Commit 44bbca8a authored by jc's avatar jc

fixes with autopep8

parent 0161a2d3
from django.contrib import admin
from bt import models
class CommentInline(admin.TabularInline):
model = models.Comment
max_num = 1
model = models.Comment
max_num = 1
class ViolationAdmin(admin.ModelAdmin):
list_display = ('state', 'country', 'operator', 'contract', 'resource_name', 'media', 'activationid', 'old', 'creation_date')
list_filter = ('state', 'operator_ref', 'contract', 'resource_name', 'media', 'country', 'old')
inlines = [CommentInline, ]
list_display = ('state', 'country', 'operator', 'contract', 'resource_name', 'media', 'activationid', 'old', 'creation_date')
list_filter = ('state', 'operator_ref', 'contract', 'resource_name', 'media', 'country', 'old')
inlines = [CommentInline, ]
admin.site.register(models.Violation, ViolationAdmin)
class CommentAdmin(admin.ModelAdmin):
list_display = ('violation', 'submitter_name', 'comment')
list_filter = ('violation', 'submitter_name')
list_display = ('violation', 'submitter_name', 'comment')
list_filter = ('violation', 'submitter_name')
admin.site.register(models.Comment, CommentAdmin)
class AttachmentAdmin(admin.ModelAdmin):
list_display = ('name', 'comment')
list_display = ('name', 'comment')
admin.site.register(models.Attachment, AttachmentAdmin)
class ConfirmationAdmin(admin.ModelAdmin):
list_display = ('violation', 'key')
list_filter = ('violation__operator_ref', 'violation__contract', 'violation__resource_name', 'violation__media', 'violation__country')
list_display = ('violation', 'key')
list_filter = ('violation__operator_ref', 'violation__contract', 'violation__resource_name', 'violation__media', 'violation__country')
admin.site.register(models.Confirmation, ConfirmationAdmin)
class FeaturedCaseAdmin(admin.ModelAdmin):
pass
admin.site.register(models.FeaturedCase, FeaturedCaseAdmin)
class OperatorAdmin(admin.ModelAdmin):
list_display = ("__unicode__", "reported_violations")
search_fields = ('name', )
pass
admin.site.register(models.Operator, OperatorAdmin)
\ No newline at end of file
list_display = ("__unicode__", "reported_violations")
search_fields = ('name', )
pass
admin.site.register(models.Operator, OperatorAdmin)
......@@ -5,7 +5,7 @@ from tastypie.resources import ModelResource, ALL, ALL_WITH_RELATIONS
from bt.models import Violation, Operator
#class UserResource(ModelResource):
# class UserResource(ModelResource):
# class Meta:
# queryset = User.objects.all()
# resource_name = 'auth/user'
......
......@@ -2,6 +2,7 @@ from django.contrib.syndication.views import Feed
from django.utils.feedgenerator import Atom1Feed
from bt.models import Violation
class RssSiteNewsFeed(Feed):
title = "NNMON - Latest NN Infringements"
link = "/"
......@@ -17,7 +18,7 @@ class RssSiteNewsFeed(Feed):
def item_title(self, item):
return "%s (%s) %s" % (item.operator, item.country, item.contract)
class AtomSiteNewsFeed(RssSiteNewsFeed):
feed_type = Atom1Feed
subtitle = RssSiteNewsFeed.description
......@@ -8,16 +8,19 @@ from bt.multifile import MultiFileField
from operator import itemgetter
from captcha.fields import CaptchaField
class AdvancedEditor(forms.Textarea):
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):
self.language = language or settings.LANGUAGE_CODE[:2]
self.attrs = {'class': 'advancededitor'}
if attrs: self.attrs.update(attrs)
if attrs:
self.attrs.update(attrs)
super(AdvancedEditor, self).__init__(attrs)
class AddViolation(forms.Form):
resource_name = forms.CharField(required=True, max_length=4096, label=_('Please describe the discrimination'), 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 discrimination is reported.'))
......@@ -67,5 +70,6 @@ class SearchViolation(SearchForm):
return sqs
class QuickSearchViolation(forms.Form):
query = forms.CharField(required='True', max_length=256, label=_("Search"), help_text=_('Search for an existing violation'))
......@@ -36,7 +36,7 @@ COUNTRIES = (
('FI', _('Finland')),
('SE', _('Sweden')),
('UK', _('United Kingdom')),
)
)
RESOURCES = (
('other', _('other')),
('port', _('port')),
......@@ -48,7 +48,7 @@ RESOURCES = (
('video', _('video streaming')),
('audio', _('audio streaming')),
('class', _('class of application or contraint')),
)
)
TYPES = (
('zerorating', _('Zero Rating')),
('specialised', _('Specialised Service')),
......@@ -56,11 +56,11 @@ TYPES = (
('throttling', _('Throttling')),
('prioritisation', _('Prioritisation')),
('other', _('Other'))
)
)
MEDIA = (
('fixed', _('Fixed')),
('mobile', _('Mobile')),
)
)
STATUS = (
('moreinfo', _('Need more info')),
('new', _('New')),
......@@ -69,7 +69,8 @@ STATUS = (
('ooscope', _('Out of scope')),
('resolved', _('Resolved')),
('closed', _('Closed')),
)
)
class Operator(models.Model):
"""
......@@ -85,6 +86,7 @@ class Operator(models.Model):
def __unicode__(self):
return self.name
class Violation(models.Model):
country = models.CharField(max_length=2, choices=COUNTRIES)
operator_ref = models.ForeignKey(Operator, related_name="violations")
......@@ -92,12 +94,12 @@ class Violation(models.Model):
resource = models.CharField(max_length=20, choices=RESOURCES, blank=True)
resource_name = models.CharField(max_length=4096, blank=True)
type = models.CharField(max_length=20, choices=TYPES, blank=True)
media = models.CharField( max_length=20, choices=MEDIA, blank=True)
temporary = models.BooleanField( )
media = models.CharField(max_length=20, choices=MEDIA, blank=True)
temporary = models.BooleanField()
contractual = models.BooleanField()
contract_excerpt = models.TextField(null=True, blank=True)
loophole = models.BooleanField()
activationid= models.CharField(max_length=128, null=True, blank=True)
activationid = models.CharField(max_length=128, null=True, blank=True)
state = models.CharField(max_length=20, choices=STATUS, default='new', blank=True)
editorial = models.TextField(null=True, blank=True)
old = models.BooleanField(default="False")
......@@ -131,7 +133,7 @@ class Violation(models.Model):
class Comment(models.Model):
submitter_email = models.EmailField()
submitter_name = models.CharField(max_length=20)
consent = models.BooleanField( )
consent = models.BooleanField()
comment = models.TextField()
timestamp = models.DateTimeField()
violation = models.ForeignKey(Violation)
......@@ -142,10 +144,11 @@ class Comment(models.Model):
def __unicode__(self):
return _("Comment #%s") % (self.pk)
class Attachment(models.Model):
storage = models.FileField(upload_to='static')
name= models.CharField(max_length=512)
type= models.CharField(max_length=512)
name = models.CharField(max_length=512)
type = models.CharField(max_length=512)
comment = models.ForeignKey(Comment)
class Admin:
......@@ -154,23 +157,28 @@ class Attachment(models.Model):
def __unicode__(self):
return self.name
class Confirmation(models.Model):
key=models.CharField(max_length=64, blank=True)
email=models.EmailField()
key = models.CharField(max_length=64, blank=True)
email = models.EmailField()
violation = models.ForeignKey(Violation)
class Admin:
pass
class ViolationModerator(CommentModerator):
email_notification = True
moderate_after = 0
moderate_after = 0
def moderate(self, comment, content_object, request):
return True
if Violation not in moderator._registry:
moderator.register(Violation, ViolationModerator)
class FeaturedCase(models.Model):
case = models.OneToOneField(Violation)
......
......@@ -16,6 +16,7 @@ from django.utils.safestring import mark_safe
FILE_INPUT_EMPTY_VALUE = object()
class MultiFileInput(Input):
"""
A widget to be used by the MultiFileField to allow the user to upload
......@@ -57,6 +58,7 @@ class MultiFileInput(Input):
return id_
id_for_label = classmethod(id_for_label)
class MultiFileField(Field):
"""
A field allowing users to upload multiple files at once.
......
from haystack import indexes
from models import Operator, Violation
class ViolationIndexes(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
operator = indexes.CharField(model_attr="operator_ref")
......
......@@ -8,7 +8,8 @@ from bt.models import Violation
from django.db.models import Count
import odslib
from django.utils.html import strip_tags
import re, htmlentitydefs
import re
import htmlentitydefs
##
# Removes HTML or XML character references and entities from a text string.
#
......@@ -16,8 +17,10 @@ import re, htmlentitydefs
# @return The plain text, as a Unicode string, if necessary.
# source: http://effbot.org/zone/re-sub.htm
def unescape(text):
text=strip_tags(text)
text = strip_tags(text)
def fixup(m):
text = m.group(0)
if text[:2] == "&#":
......@@ -35,47 +38,49 @@ def unescape(text):
text = unichr(htmlentitydefs.name2codepoint[text[1:-1]])
except KeyError:
pass
return text # leave as is
return text # leave as is
return re.sub("&#?\w+;", fixup, text)
def save_ods():
# Create your document
doc = ooolib.Calc()
col=1
row=2
col = 1
row = 2
doc.set_cell_property('bold', True)
doc.set_row_property(row, 'height', '16.5pt')
for heading, width in [('Country', '73pt'),
('Operator', '77pt'),
('Type of measure*','355pt'),
('','355pt'),
('Type of measure*', '355pt'),
('', '355pt'),
('Description of the measure', '148pt'),
('Objective',''),
('Method of implementation (if applicable)',''),
('Number of subscribers having a subscription where this measure is implemented',''),
('How is the user informed?','148pt'),
('Objective', ''),
('Method of implementation (if applicable)', ''),
('Number of subscribers having a subscription where this measure is implemented', ''),
('How is the user informed?', '148pt'),
('Can the user activate/deactivate the measure? How?', '148pt'),
('Protection of business secret','239pt')]:
if width: doc.set_column_property(col, 'width', width)
('Protection of business secret', '239pt')]:
if width:
doc.set_column_property(col, 'width', width)
doc.set_cell_value(col, row, "string", heading)
col+=1
col += 1
doc.set_cell_property('bold', False)
row=3
row = 3
for v in Violation.objects.filter(activationid='').exclude(state__in=['closed', 'ooscope', 'duplicate']).annotate(total=Count('confirmation')):
if v.total>0 or v.state=='verified':
if v.total > 0 or v.state == 'verified':
doc.set_row_property(row, 'height', '16.5pt')
doc.set_cell_property('wrap-option', 'wrap')
doc.set_cell_value(1, row, "string", v.country)
doc.set_cell_value(2, row, "string", v.operator)
doc.set_cell_value(3, row, "string", "%s %s" % (v.type, v.resource_name))
doc.set_cell_value(5, row, "string", "%s\n\n%s" % ( v.editorial, unescape(v.comment_set.get().comment)))
doc.set_cell_value(5, row, "string", "%s\n\n%s" % (v.editorial, unescape(v.comment_set.get().comment)))
doc.set_cell_value(9, row, "string", "%s %s" % ("Contractual" if v.contractual else "", unescape(v.contract_excerpt)))
doc.set_cell_value(10, row, "string", "can update to a different dataplan" if v.loophole else "")
doc.set_cell_value(12, row, "string", v.media)
row+=1
row += 1
#(v.state, v.country, v.operator, v.contract, v.resource, v.resource_name, v.type, v.media, v.temporary, v.contractual, v.contract_excerpt, v.loophole, v.editorial,v.comment_set.get().comment)
# Save the document to the file you want to create
......
......@@ -6,20 +6,28 @@ from ..models import COUNTRIES, STATUS, TYPES, MEDIA
register = Library()
@register.simple_tag
def root_url():
return settings.ROOT_URL
@register.simple_tag
def media_url():
return settings.MEDIA_URL
country_map=dict(COUNTRIES)
country_map = dict(COUNTRIES)
@register.filter(name='country')
def country(code):
return country_map[code]
status_map=dict(STATUS)
status_map = dict(STATUS)
@register.filter(name='status')
def status(code):
try:
......@@ -27,7 +35,10 @@ def status(code):
except:
return code
type_map=dict(TYPES)
type_map = dict(TYPES)
@register.filter(name='type')
def type(code):
try:
......@@ -35,7 +46,10 @@ def type(code):
except:
return code
media_map=dict(MEDIA)
media_map = dict(MEDIA)
@register.filter(name='media')
def media(code):
try:
......
......@@ -6,6 +6,7 @@ import json
register = Library()
@register.filter(name='jsonify')
def jsonify(object):
if isinstance(object, QuerySet):
......
This diff is collapsed.
......@@ -13,82 +13,82 @@ operator_api_resource = OperatorResource()
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$',
view=bt.AddForm.as_view(),
name="homepage"),
url(r'^list/$',
view=bt.ViolationsList.as_view(),
name="list_violations"),
url(r'^list/(?P<country>\w+)/$',
view=bt.ViolationsList.as_view(),
name="filter_country"),
url(r'^list/(?P<country>\w+)/(?P<operator>\w+)/$',
view=bt.ViolationsList.as_view(),
name="filter_operator"),
# violation cannonical url and redirections
url(r'^(?P<id>[0-9]*)$',
RedirectView.as_view(url='/view/%(id)s')),
url(r'^view/(?P<id>[0-9]*)$',
view=bt.ViolationView.as_view(),
name="violation_url"),
url(r'^attach/(?P<id>[0-9]*)$',
view=bt.get_attach,
name="attach"),
# different data outputs
url(r'^csv$',
view=bt.ViolationCsvList.as_view(),
name="csv_output"),
url(r'^ods$',
view=bt.asods,
name="ods_output"),
url(r'^rss/$',
view=RssSiteNewsFeed(),
name="rss_output"),
url(r'^atom/$',
view=AtomSiteNewsFeed(),
name="atom_output"),
url(r'^activate/$',
view=bt.activate,
name="activate"),
url(r'^confirm/(?P<id>[0-9a-z]*)$',
view=bt.confirm,
name="confirm"),
url(r'^confirm/(?P<id>[0-9]*)/(?P<name>.*)$',
view=bt.confirm,
name="confirm_full"),
url(r'^moderate/$',
view=bt.moderate,
name="moderate"),
url(r'^lookup/',
view=bt.LookupView.as_view(template_name='search/lookup.json'),
name="lookup"),
url(r'^accounts/logout$',
'django.contrib.auth.views.logout', {'next_page': '/'}),
url(r'^accounts/',
include('registration.backends.hmac.urls')),
url(r'^comments/',
include('django_comments.urls')),
url(r'^about/$',
TemplateView.as_view(template_name='nn.html')),
url(r'^start/$',
TemplateView.as_view(template_name='start.html')),
url(r'^captcha/',
include('captcha.urls')),
url(r'^admin/',
include(admin.site.urls)),
url(r'^api/',
include(api_resource.urls)),
url(r'^api/',
include(operator_api_resource.urls)),
url(r'^search/',
bt.ViolationSearchView.as_view(template_name='search/search.html')),
# Language switch
url(r'^i18n/', include('django.conf.urls.i18n')),
)
url(r'^$',
view=bt.AddForm.as_view(),
name="homepage"),
url(r'^list/$',
view=bt.ViolationsList.as_view(),
name="list_violations"),
url(r'^list/(?P<country>\w+)/$',
view=bt.ViolationsList.as_view(),
name="filter_country"),
url(r'^list/(?P<country>\w+)/(?P<operator>\w+)/$',
view=bt.ViolationsList.as_view(),
name="filter_operator"),
# violation cannonical url and redirections
url(r'^(?P<id>[0-9]*)$',
RedirectView.as_view(url='/view/%(id)s')),
url(r'^view/(?P<id>[0-9]*)$',
view=bt.ViolationView.as_view(),
name="violation_url"),
url(r'^attach/(?P<id>[0-9]*)$',
view=bt.get_attach,
name="attach"),
# different data outputs
url(r'^csv$',
view=bt.ViolationCsvList.as_view(),
name="csv_output"),
url(r'^ods$',
view=bt.asods,
name="ods_output"),
url(r'^rss/$',
view=RssSiteNewsFeed(),
name="rss_output"),
url(r'^atom/$',
view=AtomSiteNewsFeed(),
name="atom_output"),
url(r'^activate/$',
view=bt.activate,
name="activate"),
url(r'^confirm/(?P<id>[0-9a-z]*)$',
view=bt.confirm,
name="confirm"),
url(r'^confirm/(?P<id>[0-9]*)/(?P<name>.*)$',
view=bt.confirm,
name="confirm_full"),
url(r'^moderate/$',
view=bt.moderate,
name="moderate"),
url(r'^lookup/',
view=bt.LookupView.as_view(template_name='search/lookup.json'),
name="lookup"),
url(r'^accounts/logout$',
'django.contrib.auth.views.logout', {'next_page': '/'}),
url(r'^accounts/',
include('registration.backends.hmac.urls')),
url(r'^comments/',
include('django_comments.urls')),
url(r'^about/$',
TemplateView.as_view(template_name='nn.html')),
url(r'^start/$',
TemplateView.as_view(template_name='start.html')),
url(r'^captcha/',
include('captcha.urls')),
url(r'^admin/',
include(admin.site.urls)),
url(r'^api/',
include(api_resource.urls)),
url(r'^api/',
include(operator_api_resource.urls)),
url(r'^search/',
bt.ViolationSearchView.as_view(template_name='search/search.html')),
# Language switch
url(r'^i18n/', include('django.conf.urls.i18n')),
)
if settings.DEV_SERVER == True:
urlpatterns += patterns('',
(r'^site_media/(?P<path>.*)$',
'django.views.static.serve',
{'document_root': settings.MEDIA_PATH}),
)
\ No newline at end of file
(r'^site_media/(?P<path>.*)$',
'django.views.static.serve',
{'document_root': settings.MEDIA_PATH}),
)
from spamlesscomment.forms import CommentFormWithCaptcha
def get_form():
return CommentFormWithCaptcha
Markdown is supported
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