Commit f1caef74 authored by stef's avatar stef

[enh] framework, i18n, and a dynamic form

parent 32c331b9
[django: templates/**.html, bt/*/templates/**.html]
[python: bt/**.py]
from django import forms
from django.conf import settings
from bt.models import Violation, COUNTRIES
from django.utils.translation import ugettext as _
from bt.models import Violation, COUNTRIES, RESOURCES, TYPES, MEDIA
from operator import itemgetter
class AdvancedEditor(forms.Textarea):
......@@ -14,14 +15,15 @@ class AdvancedEditor(forms.Textarea):
super(AdvancedEditor, self).__init__(attrs)
class AddViolation(forms.Form):
country = forms.ChoiceField(choices=(('',''),)+tuple(sorted(COUNTRIES,key=itemgetter(1))))
operator = forms.CharField(max_length=256)
contract = forms.CharField(max_length=256)
comment = forms.CharField(required=True, widget=AdvancedEditor())
resource = forms.CharField(required=False, max_length=1)
type = forms.CharField(max_length=1)
media = forms.CharField(required=False, max_length=1)
temporary = forms.BooleanField(required=False )
contractual = forms.BooleanField(required=False)
contract_excerpt = forms.CharField(required=False, widget=AdvancedEditor())
loophole = forms.BooleanField(required=False)
country = forms.ChoiceField(required=True, choices=(('',''),)+tuple(sorted(COUNTRIES,key=itemgetter(1))), help_text=_('EU member state where the restriction is reported.'))
operator = forms.CharField(required=True, max_length=256, help_text=_('The ISP or operator providing the Internet service.'))
contract = forms.CharField(required=True, max_length=256, help_text=_('The specific contract at the ISP provider. (please be as specific as possible)'))
comment = forms.CharField(required=True, widget=AdvancedEditor(), help_text=_('Please describe the symptoms you are experiencing. What service or site, or person is unavailable or seems artificially slowed down.'))
resource = forms.ChoiceField(required=False, choices=(('',''),)+tuple(sorted(RESOURCES,key=itemgetter(1))), help_text=_('The what is the affected resource.'))
resource_name = forms.CharField(required=False, max_length=4096, help_text=_('Please specify the name of the affected resource.'))
type = forms.ChoiceField(required=False, choices=(('',''),)+tuple(sorted(TYPES,key=itemgetter(1))), help_text=_('Is the Resource Blocked or otherwise discrimated?'))
media = forms.ChoiceField(required=False, choices=(('',''),)+tuple(sorted(MEDIA,key=itemgetter(1))), help_text=_('Is the Internet connection over mobile or fixed line?'))
temporary = forms.BooleanField(required=False, help_text=_('Is the restriction only temporary, e.g. due to network overload?'))
contractual = forms.BooleanField(required=False, help_text=_('Is the restriction described in the users contract?'))
contract_excerpt = forms.CharField(required=False, widget=AdvancedEditor(), help_text=_('Please copy the relevant section describing the restriction from the user contract.'))
loophole = forms.BooleanField(required=False, help_text=_('Is there another offer provided by this Operator which removes this restriction?'))
from django.db import models
from django.utils.translation import ugettext as _
COUNTRIES = (
('BE', 'Belgium'),
('BG', 'Bulgaria'),
('CZ', 'Czech Republic'),
('DK', 'Denmark'),
('DE', 'Germany'),
('EE', 'Estonia'),
('IE', 'Ireland'),
('EL', 'Greece'),
('ES', 'Spain'),
('FR', 'France'),
('IT', 'Italy'),
('CY', 'Cyprus'),
('LV', 'Latvia'),
('LT', 'Lithuania'),
('LU', 'Luxembourg'),
('HU', 'Hungary'),
('MT', 'Malta'),
('NL', 'Netherlands'),
('AT', 'Austria'),
('PL', 'Poland'),
('PT', 'Portugal'),
('RO', 'Romania'),
('SI', 'Slovenia'),
('SK', 'Slovakia'),
('FI', 'Finland'),
('SE', 'Sweden'),
('UK', 'United Kingdom '),
('BE', _('Belgium')),
('BG', _('Bulgaria')),
('CZ', _('Czech Republic')),
('DK', _('Denmark')),
('DE', _('Germany')),
('EE', _('Estonia')),
('IE', _('Ireland')),
('EL', _('Greece')),
('ES', _('Spain')),
('FR', _('France')),
('IT', _('Italy')),
('CY', _('Cyprus')),
('LV', _('Latvia')),
('LT', _('Lithuania')),
('LU', _('Luxembourg')),
('HU', _('Hungary')),
('MT', _('Malta')),
('NL', _('Netherlands')),
('AT', _('Austria')),
('PL', _('Poland')),
('PT', _('Portugal')),
('RO', _('Romania')),
('SI', _('Slovenia')),
('SK', _('Slovakia')),
('FI', _('Finland')),
('SE', _('Sweden')),
('UK', _('United Kingdom ')),
)
RESOURCES = (
('1', _('port')),
('2', _('protocol')),
('3', _('service')),
('4', _('site')),
('5', _('user')),
('6', _('ip')),
)
TYPES = (
('1', _('Blocking')),
('2', _('Throttling')),
)
MEDIA = (
('1', _('Fixed')),
('2', _('Mobile')),
)
class Attachment(models.Model):
......@@ -40,22 +58,6 @@ class Comment(models.Model):
attachments = models.ForeignKey(Attachment)
class Violation(models.Model):
RESOURCES = (
('1', 'port'),
('2', 'protocol'),
('3', 'service'),
('4', 'site'),
('5', 'user'),
('6', 'ip'),
)
TYPES = (
('1', 'Blocking'),
('2', 'Throttling'),
)
MEDIA = (
('1', 'Fixed'),
('2', 'Mobile'),
)
country = models.CharField(max_length=2, choices=COUNTRIES)
operator = models.CharField(max_length=256)
contract = models.CharField(max_length=256)
......
......@@ -8,24 +8,17 @@ import json
def add(request):
if request.method == 'POST': # If the form has been submitted...
form = AddViolation(request.POST) # A form bound to the POST data
print form.errors
v=Violation(**form.cleaned_data)
print 'v',v
if form.is_valid(): # All validation rules pass
# Process the data in form.cleaned_data
# ...
v=Violation(**form.values)
print 'v',v
print 'asdf',form.cleaned_data
return HttpResponseRedirect('/') # Redirect after POST
else:
form = AddViolation() # An unbound form
return render_to_response('add.html', {
'form': form,
}, context_instance=RequestContext(request))
def edit(request):
return add(request)
return render_to_response('add.html',
{ 'form': form, },
context_instance=RequestContext(request))
def ajax(request, country=None, operator=None):
if not operator:
......
# German translations for nnmon.
# Copyright (C) 2011 ORGANIZATION
# This file is distributed under the same license as the nnmon project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2011.
#
msgid ""
msgstr ""
"Project-Id-Version: nnmon 0.00000000000001\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2011-04-29 17:45+0200\n"
"PO-Revision-Date: 2011-04-29 17:53+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: de <LL@li.org>\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 0.9.6\n"
#: bt/models.py:4
msgid "Belgium"
msgstr ""
#: bt/models.py:5
msgid "Bulgaria"
msgstr ""
#: bt/models.py:6
msgid "Czech Republic"
msgstr ""
#: bt/models.py:7
msgid "Denmark"
msgstr ""
#: bt/models.py:8
msgid "Germany"
msgstr ""
#: bt/models.py:9
msgid "Estonia"
msgstr ""
#: bt/models.py:10
msgid "Ireland"
msgstr ""
#: bt/models.py:11
msgid "Greece"
msgstr ""
#: bt/models.py:12
msgid "Spain"
msgstr ""
#: bt/models.py:13
msgid "France"
msgstr ""
#: bt/models.py:14
msgid "Italy"
msgstr ""
#: bt/models.py:15
msgid "Cyprus"
msgstr ""
#: bt/models.py:16
msgid "Latvia"
msgstr ""
#: bt/models.py:17
msgid "Lithuania"
msgstr ""
#: bt/models.py:18
msgid "Luxembourg"
msgstr ""
#: bt/models.py:19
msgid "Hungary"
msgstr ""
#: bt/models.py:20
msgid "Malta"
msgstr ""
#: bt/models.py:21
msgid "Netherlands"
msgstr ""
#: bt/models.py:22
msgid "Austria"
msgstr ""
#: bt/models.py:23
msgid "Poland"
msgstr ""
#: bt/models.py:24
msgid "Portugal"
msgstr ""
#: bt/models.py:25
msgid "Romania"
msgstr ""
#: bt/models.py:26
msgid "Slovenia"
msgstr ""
#: bt/models.py:27
msgid "Slovakia"
msgstr ""
#: bt/models.py:28
msgid "Finland"
msgstr ""
#: bt/models.py:29
msgid "Sweden"
msgstr ""
#: bt/models.py:30
msgid "United Kingdom "
msgstr ""
#: bt/models.py:44
msgid "port"
msgstr ""
#: bt/models.py:45
msgid "protocol"
msgstr ""
#: bt/models.py:46
msgid "service"
msgstr ""
#: bt/models.py:47
msgid "site"
msgstr ""
#: bt/models.py:48
msgid "user"
msgstr ""
#: bt/models.py:49
msgid "ip"
msgstr ""
#: bt/models.py:52
msgid "Blocking"
msgstr ""
#: bt/models.py:53
msgid "Throttling"
msgstr ""
#: bt/models.py:56
msgid "Fixed"
msgstr ""
#: bt/models.py:57
msgid "Mobile"
msgstr ""
# French translations for nnmon.
# Copyright (C) 2011 ORGANIZATION
# This file is distributed under the same license as the nnmon project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2011.
#
msgid ""
msgstr ""
"Project-Id-Version: nnmon 0.00000000000001\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2011-04-29 17:45+0200\n"
"PO-Revision-Date: 2011-04-29 17:49+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: fr <LL@li.org>\n"
"Plural-Forms: nplurals=2; plural=(n > 1)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 0.9.6\n"
#: bt/models.py:4
msgid "Belgium"
msgstr ""
#: bt/models.py:5
msgid "Bulgaria"
msgstr ""
#: bt/models.py:6
msgid "Czech Republic"
msgstr ""
#: bt/models.py:7
msgid "Denmark"
msgstr ""
#: bt/models.py:8
msgid "Germany"
msgstr ""
#: bt/models.py:9
msgid "Estonia"
msgstr ""
#: bt/models.py:10
msgid "Ireland"
msgstr ""
#: bt/models.py:11
msgid "Greece"
msgstr ""
#: bt/models.py:12
msgid "Spain"
msgstr ""
#: bt/models.py:13
msgid "France"
msgstr ""
#: bt/models.py:14
msgid "Italy"
msgstr ""
#: bt/models.py:15
msgid "Cyprus"
msgstr ""
#: bt/models.py:16
msgid "Latvia"
msgstr ""
#: bt/models.py:17
msgid "Lithuania"
msgstr ""
#: bt/models.py:18
msgid "Luxembourg"
msgstr ""
#: bt/models.py:19
msgid "Hungary"
msgstr ""
#: bt/models.py:20
msgid "Malta"
msgstr ""
#: bt/models.py:21
msgid "Netherlands"
msgstr ""
#: bt/models.py:22
msgid "Austria"
msgstr ""
#: bt/models.py:23
msgid "Poland"
msgstr ""
#: bt/models.py:24
msgid "Portugal"
msgstr ""
#: bt/models.py:25
msgid "Romania"
msgstr ""
#: bt/models.py:26
msgid "Slovenia"
msgstr ""
#: bt/models.py:27
msgid "Slovakia"
msgstr ""
#: bt/models.py:28
msgid "Finland"
msgstr ""
#: bt/models.py:29
msgid "Sweden"
msgstr ""
#: bt/models.py:30
msgid "United Kingdom "
msgstr ""
#: bt/models.py:44
msgid "port"
msgstr ""
#: bt/models.py:45
msgid "protocol"
msgstr ""
#: bt/models.py:46
msgid "service"
msgstr ""
#: bt/models.py:47
msgid "site"
msgstr ""
#: bt/models.py:48
msgid "user"
msgstr ""
#: bt/models.py:49
msgid "ip"
msgstr ""
#: bt/models.py:52
msgid "Blocking"
msgstr ""
#: bt/models.py:53
msgid "Throttling"
msgstr ""
#: bt/models.py:56
msgid "Fixed"
msgstr ""
#: bt/models.py:57
msgid "Mobile"
msgstr ""
# Hungarian translations for nnmon.
# Copyright (C) 2011 ORGANIZATION
# This file is distributed under the same license as the nnmon project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2011.
#
msgid ""
msgstr ""
"Project-Id-Version: nnmon 0.00000000000001\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2011-04-29 17:45+0200\n"
"PO-Revision-Date: 2011-04-29 17:53+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: hu <LL@li.org>\n"
"Plural-Forms: nplurals=1; plural=0\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 0.9.6\n"
#: bt/models.py:4
msgid "Belgium"
msgstr ""
#: bt/models.py:5
msgid "Bulgaria"
msgstr ""
#: bt/models.py:6
msgid "Czech Republic"
msgstr ""
#: bt/models.py:7
msgid "Denmark"
msgstr ""
#: bt/models.py:8
msgid "Germany"
msgstr ""
#: bt/models.py:9
msgid "Estonia"
msgstr ""
#: bt/models.py:10
msgid "Ireland"
msgstr ""
#: bt/models.py:11
msgid "Greece"
msgstr ""
#: bt/models.py:12
msgid "Spain"
msgstr ""
#: bt/models.py:13
msgid "France"
msgstr ""
#: bt/models.py:14
msgid "Italy"
msgstr ""
#: bt/models.py:15
msgid "Cyprus"
msgstr ""
#: bt/models.py:16
msgid "Latvia"
msgstr ""
#: bt/models.py:17
msgid "Lithuania"
msgstr ""
#: bt/models.py:18
msgid "Luxembourg"
msgstr ""
#: bt/models.py:19
msgid "Hungary"
msgstr ""
#: bt/models.py:20
msgid "Malta"
msgstr ""
#: bt/models.py:21
msgid "Netherlands"
msgstr ""
#: bt/models.py:22
msgid "Austria"
msgstr ""
#: bt/models.py:23
msgid "Poland"
msgstr ""
#: bt/models.py:24
msgid "Portugal"
msgstr ""
#: bt/models.py:25
msgid "Romania"
msgstr ""
#: bt/models.py:26
msgid "Slovenia"
msgstr ""
#: bt/models.py:27
msgid "Slovakia"
msgstr ""
#: bt/models.py:28
msgid "Finland"
msgstr ""
#: bt/models.py:29
msgid "Sweden"
msgstr ""
#: bt/models.py:30
msgid "United Kingdom "
msgstr ""
#: bt/models.py:44
msgid "port"
msgstr ""
#: bt/models.py:45
msgid "protocol"
msgstr ""
#: bt/models.py:46
msgid "service"
msgstr ""
#: bt/models.py:47
msgid "site"
msgstr ""
#: bt/models.py:48
msgid "user"
msgstr ""
#: bt/models.py:49
msgid "ip"
msgstr ""
#: bt/models.py:52
msgid "Blocking"
msgstr ""
#: bt/models.py:53
msgid "Throttling"
msgstr ""
#: bt/models.py:56
msgid "Fixed"
msgstr ""
#: bt/models.py:57
msgid "Mobile"