Commit ac349d94 authored by Okhin's avatar Okhin
Browse files

Displaying the captchas field

parent f68dce81
...@@ -9,63 +9,63 @@ from operator import itemgetter ...@@ -9,63 +9,63 @@ from operator import itemgetter
from captcha.fields import CaptchaField from captcha.fields import CaptchaField
class AdvancedEditor(forms.Textarea): class AdvancedEditor(forms.Textarea):
class Media: class Media:
js = (settings.MEDIA_URL+'/js/tinymce/tiny_mce.js',) js = (settings.MEDIA_URL+'/js/tinymce/tiny_mce.js',)
def __init__(self, language=None, attrs=None): def __init__(self, language=None, attrs=None):
self.language = language or settings.LANGUAGE_CODE[:2] self.language = language or settings.LANGUAGE_CODE[:2]
self.attrs = {'class': 'advancededitor'} self.attrs = {'class': 'advancededitor'}
if attrs: self.attrs.update(attrs) if attrs: self.attrs.update(attrs)
super(AdvancedEditor, self).__init__(attrs) super(AdvancedEditor, self).__init__(attrs)
class AddViolation(forms.Form): class AddViolation(forms.Form):
resource_name = forms.CharField(required=True, max_length=4096, label=_('Please specify the affected resource'), help_text=_("What service or site, or person is unavailable or seems artificially slowed down. e.g. VoIP, p2p, filesharing, specific websites, etc.")) resource_name = forms.CharField(required=True, max_length=4096, label=_('Please specify the affected resource'), help_text=_("What service or site, or person is unavailable or seems artificially slowed down. e.g. VoIP, p2p, filesharing, specific websites, etc."))
country = forms.ChoiceField(required=True, choices=(('',''),)+tuple(sorted(COUNTRIES,key=itemgetter(1))), label=_("Country"), help_text=_('EU member state where the restriction is reported.')) country = forms.ChoiceField(required=True, choices=(('',''),)+tuple(sorted(COUNTRIES,key=itemgetter(1))), label=_("Country"), help_text=_('EU member state where the restriction is reported.'))
operator = forms.CharField(required=True, max_length=256, label=_("Operator"), help_text=_('The ISP or operator providing the Internet service.')) operator = forms.CharField(required=True, max_length=256, label=_("Operator"), help_text=_('The ISP or operator providing the Internet service.'))
contract = forms.CharField(required=True, max_length=256, label=_("Contract"), help_text=_('The specific contract at the ISP provider. (please be as specific as possible)')) contract = forms.CharField(required=True, max_length=256, label=_("Contract"), help_text=_('The specific contract at the ISP provider. (please be as specific as possible)'))
media = forms.ChoiceField(required=True, choices=(('',''),)+tuple(sorted(MEDIA,key=itemgetter(1))), label=_('Is the Internet connection over mobile or fixed line?')) media = forms.ChoiceField(required=True, choices=(('',''),)+tuple(sorted(MEDIA,key=itemgetter(1))), label=_('Is the Internet connection over mobile or fixed line?'))
comment = forms.CharField(required=True, widget=AdvancedEditor(), label=_('Please describe the symptoms you are experiencing.')) comment = forms.CharField(required=True, widget=AdvancedEditor(), label=_('Please describe the symptoms you are experiencing.'))
email = forms.EmailField(required=True, label=_('Email (set this to enable saving)'), help_text=_("We need your email to validate your report. Your email address is obligatory, but we will never use your personal data for anything else than checking the submission. (see next for an optional exception)")) email = forms.EmailField(required=True, label=_('Email (set this to enable saving)'), help_text=_("We need your email to validate your report. Your email address is obligatory, but we will never use your personal data for anything else than checking the submission. (see next for an optional exception)"))
consent = forms.BooleanField(required=False, label=_("I want to help further"), help_text=_("We need your consent to contact you for clarifications regarding your report. This is optional, but helps us improve the quality of the reports. Thanks!")) consent = forms.BooleanField(required=False, label=_("I want to help further"), help_text=_("We need your consent to contact you for clarifications regarding your report. This is optional, but helps us improve the quality of the reports. Thanks!"))
nick = forms.CharField(required=False, label=_("Name or nickname"), help_text=_("We need some name to display that instead of an email address.")) nick = forms.CharField(required=False, label=_("Name or nickname"), help_text=_("We need some name to display that instead of an email address."))
attachments = MultiFileField(required=False, label=_("Attach screenshot, document or any other relevant information.")) attachments = MultiFileField(required=False, label=_("Attach screenshot, document or any other relevant information."))
resource = forms.ChoiceField(required=False, choices=(('',''),)+tuple(sorted(RESOURCES,key=itemgetter(1))), label=_('What is the affected resource type. (optional)')) resource = forms.ChoiceField(required=False, choices=(('',''),)+tuple(sorted(RESOURCES,key=itemgetter(1))), label=_('What is the affected resource type. (optional)'))
type = forms.ChoiceField(required=False, choices=(('',''),)+tuple(sorted(TYPES,key=itemgetter(1))), label=_('Is the Resource Blocked or otherwise discrimated? (optional)')) type = forms.ChoiceField(required=False, choices=(('',''),)+tuple(sorted(TYPES,key=itemgetter(1))), label=_('Is the Resource Blocked or otherwise discrimated? (optional)'))
temporary = forms.BooleanField(required=False, label=_('Is the restriction only temporary, e.g. due to network overload? (optional)')) temporary = forms.BooleanField(required=False, label=_('Is the restriction only temporary, e.g. due to network overload? (optional)'))
loophole = forms.BooleanField(required=False, label=_('Is there another offer provided by this Operator which removes this restriction? (optional)')) loophole = forms.BooleanField(required=False, label=_('Is there another offer provided by this Operator which removes this restriction? (optional)'))
contractual = forms.BooleanField(required=False, label=_('Is the restriction described in the subscribers contract? (optional)')) contractual = forms.BooleanField(required=False, label=_('Is the restriction described in the subscribers contract? (optional)'))
contract_excerpt = forms.CharField(required=False, widget=AdvancedEditor(), label=_('Please copy the relevant section describing the restriction from the user contract. (optional)')) contract_excerpt = forms.CharField(required=False, widget=AdvancedEditor(), label=_('Please copy the relevant section describing the restriction from the user contract. (optional)'))
captcha = CaptchaField(label=_("In order to protect against spam, please fill in the result of the following calculation. (note the + and the * are somewhat confusing)")) captcha = CaptchaField(label=_("In order to protect against spam, please fill in the result of the following calculation. (note the + and the * are somewhat confusing)"))
class SearchViolation(SearchForm): class SearchViolation(SearchForm):
country = forms.ChoiceField(required=False, choices=(('',''),)+tuple(sorted(COUNTRIES,key=itemgetter(1))), label=_("Country"), help_text=_('EU member state where the restriction is reported.')) country = forms.ChoiceField(required=False, choices=(('',''),)+tuple(sorted(COUNTRIES,key=itemgetter(1))), label=_("Country"), help_text=_('EU member state where the restriction is reported.'))
operator = forms.CharField(required=False, max_length=256, label=_("Operator"), help_text=_('The ISP or operator providing the Internet service.')) operator = forms.CharField(required=False, max_length=256, label=_("Operator"), help_text=_('The ISP or operator providing the Internet service.'))
contract = forms.CharField(required=False, max_length=256, label=_("Contract"), help_text=_('The specific contract at the ISP provider. (please be as specific as possible)')) contract = forms.CharField(required=False, max_length=256, label=_("Contract"), help_text=_('The specific contract at the ISP provider. (please be as specific as possible)'))
media = forms.ChoiceField(required=False, choices=(('',''),)+tuple(sorted(MEDIA,key=itemgetter(1))), label=_('Is the Internet connection over mobile or fixed line?')) media = forms.ChoiceField(required=False, choices=(('',''),)+tuple(sorted(MEDIA,key=itemgetter(1))), label=_('Is the Internet connection over mobile or fixed line?'))
def search(self): def search(self):
# By default, the search field is q. So let's check if it's empty # By default, the search field is q. So let's check if it's empty
if not self.cleaned_data['q']: if not self.cleaned_data['q']:
sqs = SearchQuerySet().all() sqs = SearchQuerySet().all()
else: else:
sqs = super(SearchViolation, self).search() sqs = super(SearchViolation, self).search()
if not self.is_valid(): if not self.is_valid():
return self.no_query_found() return self.no_query_found()
if self.cleaned_data['operator']: if self.cleaned_data['operator']:
sqs = sqs.filter(operator__icontains=self.cleaned_data['operator']) sqs = sqs.filter(operator__icontains=self.cleaned_data['operator'])
if self.cleaned_data['contract']: if self.cleaned_data['contract']:
sqs = sqs.filter(contract__icontains=self.cleaned_data['contract']) sqs = sqs.filter(contract__icontains=self.cleaned_data['contract'])
if self.cleaned_data['media']: if self.cleaned_data['media']:
sqs = sqs.filter(media=self.cleaned_data['media']) sqs = sqs.filter(media=self.cleaned_data['media'])
if self.cleaned_data['country']: if self.cleaned_data['country']:
sqs = sqs.filter(country=self.cleaned_data['country']) sqs = sqs.filter(country=self.cleaned_data['country'])
return sqs return sqs
class QuickSearchViolation(forms.Form): class QuickSearchViolation(forms.Form):
query = forms.CharField(required='True', max_length=256, label=_("Search"), help_text=_('Search for an existing violation')) query = forms.CharField(required='True', max_length=256, label=_("Search"), help_text=_('Search for an existing violation'))
...@@ -145,11 +145,9 @@ def sendverifymail(service,to,body): ...@@ -145,11 +145,9 @@ def sendverifymail(service,to,body):
return actid return actid
class AddForm(FormView): class AddForm(FormView):
model = Violation
template_name = 'index.html' template_name = 'index.html'
form_class = AddViolation form_class = AddViolation
success_url = '/' success_url = '/'
context_object_name = 'violations'
def form_valid(self, form): def form_valid(self, form):
msg=_("Thank you for submitting a new report. To finalize your submission please confirm using your validation key.\nYour verification key is %s/%s%s\nPlease note that reports are moderated, it might take some time before your report appears online. Thank you for your patience.") msg=_("Thank you for submitting a new report. To finalize your submission please confirm using your validation key.\nYour verification key is %s/%s%s\nPlease note that reports are moderated, it might take some time before your report appears online. Thank you for your patience.")
...@@ -167,7 +165,8 @@ class AddForm(FormView): ...@@ -167,7 +165,8 @@ class AddForm(FormView):
contractual = form.cleaned_data['contractual'], contractual = form.cleaned_data['contractual'],
contract_excerpt = sanitizeHtml(form.cleaned_data['contract_excerpt']), contract_excerpt = sanitizeHtml(form.cleaned_data['contract_excerpt']),
loophole = form.cleaned_data['loophole'], loophole = form.cleaned_data['loophole'],
activationid = actid activationid = actid,
old = False
) )
v.save() v.save()
#c=Confirmation(key='', email=form.cleaned_data['email'], violation=v) #c=Confirmation(key='', email=form.cleaned_data['email'], violation=v)
...@@ -181,7 +180,7 @@ class AddForm(FormView): ...@@ -181,7 +180,7 @@ class AddForm(FormView):
violation=v, violation=v,
) )
c.save() c.save()
for f in request.FILES.getlist('attachments[]'): for f in self.request.FILES.getlist('attachments[]'):
a=Attachment(comment=c, name=f.name, type=f.content_type) a=Attachment(comment=c, name=f.name, type=f.content_type)
m = hashlib.sha256() m = hashlib.sha256()
for chunk in f.chunks(): for chunk in f.chunks():
...@@ -189,7 +188,7 @@ class AddForm(FormView): ...@@ -189,7 +188,7 @@ class AddForm(FormView):
sname=m.hexdigest() sname=m.hexdigest()
a.storage.save(sname,f) a.storage.save(sname,f)
a.save() a.save()
messages.add_message(request, messages.INFO, _('Thank you for submitting this report, you will receive a verification email immediately, if not check your spam folder.')) messages.add_message(self.request, messages.INFO, _('Thank you for submitting this report, you will receive a verification email immediately, if not check your spam folder.'))
return super(AddForm, self).form_valid(form) return super(AddForm, self).form_valid(form)
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
......
...@@ -145,8 +145,17 @@ ...@@ -145,8 +145,17 @@
<h2>{% trans "Add New Case" %}</h2> <h2>{% trans "Add New Case" %}</h2>
</div> </div>
<div class="panel-body"> <div class="panel-body">
{% if forms.error %}
{% for field in form %}
{% for error in field.error %}
<div class="alert alert-error">
{{ error|escape }}
</div>
{% endfor %}
{% endfor %}
{% endif %}
<p>{% trans "Please report cases of zero-rating (services which are excluded from your download limit), specialised services or the blocking, throttling or prioritisation of online services. For a more detailed description of what to report, check our <a href='/about/#guidelines'>guidelines</a>." %} <p>{% trans "Please report cases of zero-rating (services which are excluded from your download limit), specialised services or the blocking, throttling or prioritisation of online services. For a more detailed description of what to report, check our <a href='/about/#guidelines'>guidelines</a>." %}
<form name="addForm" enctype="multipart/form-data" action="{% root_url %}/add/" method="post" class="form"> <form name="addForm" enctype="multipart/form-data" action="/" method="post" class="form">
{% csrf_token %} {% csrf_token %}
{% bootstrap_field form.resource_name %} {% bootstrap_field form.resource_name %}
{% bootstrap_field form.country %} {% bootstrap_field form.country %}
...@@ -165,7 +174,7 @@ ...@@ -165,7 +174,7 @@
{% bootstrap_field form.consent %} {% bootstrap_field form.consent %}
{% bootstrap_field form.email %} {% bootstrap_field form.email %}
{% bootstrap_field form.nick %} {% bootstrap_field form.nick %}
{% bootstrap_field form.email %} {% bootstrap_field form.captcha %}
{% buttons %} {% buttons %}
<button type="submit" class="btn btn-primary">{% trans "save" %}</button> <button type="submit" class="btn btn-primary">{% trans "save" %}</button>
{% endbuttons %} {% endbuttons %}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment