Skip to content

Commit

Permalink
Forms and alerts updates and enhancements
Browse files Browse the repository at this point in the history
* UserCreationForm
* ClippingForms
* View home calling 8 dataset cards
* Table Dynamic Forms, datasets filter bootstrap forms enhancements
  • Loading branch information
marcmatias committed Feb 6, 2022
1 parent 8750ac5 commit 01b66bb
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 16 deletions.
43 changes: 38 additions & 5 deletions brasilio_auth/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,49 @@ def is_valid_username(username):


class UserCreationForm(RegistrationFormUniqueEmail):
username = forms.CharField(widget=forms.TextInput(),)
email = forms.EmailField()
password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
username = forms.CharField(
widget=forms.TextInput(
attrs={
'type':'text',
'class':"form-control"
}
),
label=_("Usuário"),
required=True
)

email = forms.EmailField(
widget=forms.TextInput(
attrs={
'placeholder': '[email protected]',
'type':'email',
'class':"form-control"
}
),
required=True
)
password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput(
attrs={
'class':"form-control"
}
))
password2 = forms.CharField(
label=_("Password confirmation"),
widget=forms.PasswordInput,
widget=forms.PasswordInput(
attrs={
'class':"form-control"
}),
help_text=_("Enter the same password as above, for verification."),
)
captcha = ReCaptchaField()
subscribe_newsletter = forms.BooleanField(required=False)
subscribe_newsletter = forms.BooleanField(widget=forms.CheckboxInput(
attrs={
'type':'checkbox',
'class':'form-check-input'
},
),
required=False
)

class Meta:
model = get_user_model()
Expand Down
65 changes: 61 additions & 4 deletions clipping/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,67 @@


class ClippingForm(ModelForm):
category = forms.CharField(widget=forms.Select(choices=settings.CATEGORY_CHOICES), label="Categoria")
date = forms.CharField(widget=forms.TextInput(attrs={"class": "datepicker"}), label="Data")
author = forms.CharField(label="Autor")
title = forms.CharField(label="Título")
category = forms.CharField(
widget=forms.Select(
attrs={
'aria-label': 'Seletor de categoria',
'class':'form-select'
},
choices=settings.CATEGORY_CHOICES
),
label="Categoria"
)
date = forms.CharField(
widget=forms.TextInput(
attrs={
"type":"text",
"class":"datepicker_input form-control",
"placeholder":"aaaa/mm/dd",
"autocomplete":"off",
}
),
label="Data"
)
vehicle = forms.CharField(
widget=forms.TextInput(
attrs={
'type':'text',
'class':"form-control",
"placeholder":"Veículo que exibiu o conteúdo",
}
),
label="Veículo"
)
author = forms.CharField(
widget=forms.TextInput(
attrs={
'type':'text',
'class':"form-control",
"placeholder":"Autor do conteúdo",
}
),
label="Autor"
)
title = forms.CharField(
widget=forms.TextInput(
attrs={
'type':'text',
'class':"form-control",
"placeholder":"Título do conteúdo",
}
),
label="Título"
)
url = forms.CharField(
widget=forms.TextInput(
attrs={
'type':'url',
'class':"form-control",
"placeholder":"http://site.com",
}
),
label="URL"
)

class Meta:
model = Clipping
Expand Down
7 changes: 6 additions & 1 deletion core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,19 @@ class DatasetSearchForm(forms.Form):
def get_table_dynamic_form(table, cache=True):
def config_dynamic_filter(model_field):
dynamic_field = table.get_field(model_field.name)
kwargs = {"required": False, "label": dynamic_field.title}
kwargs = {
"required": False,
"label": dynamic_field.title,
"widget": forms.TextInput(attrs={'type':'text', 'class':"form-control"}),
}
field_factory = model_field.formfield

# null values are being saved as "None"
if dynamic_field.has_choices and dynamic_field.choices:
kwargs["choices"] = [("", "Todos")] + [
(c, c if c != "None" else "(vazio)") for c in dynamic_field.choices.get("data", [])
]
kwargs["widget"] = forms.Select(attrs={'class':'form-select'})
field_factory = forms.ChoiceField

return field_factory(**kwargs)
Expand Down
10 changes: 4 additions & 6 deletions core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from core.util import cached_http_get_json
from data_activities_log.activites import recent_activities
from traffic_control.logging import log_blocked_request
from django.contrib.messages import success
from django.contrib import messages

class Echo:
def write(self, value):
Expand Down Expand Up @@ -89,7 +89,7 @@ def donate(request):

def home(request):
context = {
"datasets": Dataset.objects.filter(show=True).order_by("?")[:6],
"datasets": Dataset.objects.filter(show=True).order_by("?")[:8],
"recent_activities": recent_activities(
days_ago=settings.DAYS_RANGE_RECENT_ACTIVITES_HOMEPAGE, limit=settings.NUM_RECENT_ACTIVITES_HOMEPAGE
),
Expand Down Expand Up @@ -275,25 +275,23 @@ def dataset_clipping_suggestion(request):
if len(request.GET) > 0 and not request.user.is_authenticated:
return redirect(f"{settings.LOGIN_URL}?next={request.get_full_path()}")

message = None
if request.method == "POST":
clipping_form = ClippingForm(request.POST)
if clipping_form.is_valid():
clipping = clipping_form.save(commit=False)
clipping.added_by = request.user
clipping.save()

success(request, "Sugestão enviada com sucesso")
messages.success(request, "Sugestão enviada com sucesso", extra_tags='success')

return redirect(request.POST.get('next', '/'))
else:
message = "Erro: Verifique o formulário novamente"
messages.error(request, "Verifique o formulário novamente", extra_tags='danger')
else:
clipping_form = ClippingForm()

context = {
"form": clipping_form,
"message": message,
}
return render(request, "core/dataset-form-clipping.html", context)

Expand Down

0 comments on commit 01b66bb

Please sign in to comment.