From cc39a5d3bc818233f24fda541ec5765d4e2c0beb Mon Sep 17 00:00:00 2001 From: carol15022 Date: Wed, 28 Jan 2015 11:52:51 -0200 Subject: [PATCH] Applying flake8 --- colab/badger/admin.py | 1 - colab/badger/forms.py | 2 -- colab/badger/management/commands/rebuild_badges.py | 4 ++-- colab/badger/management/commands/update_badges.py | 5 +++-- colab/badger/models.py | 2 +- colab/badger/tests.py | 3 ++- colab/badger/utils.py | 28 ++++++++++++++-------------- colab/badger/views.py | 3 ++- colab/home/admin.py | 3 ++- colab/home/context_processors.py | 1 + colab/home/models.py | 3 ++- colab/home/tests.py | 3 ++- colab/home/views.py | 4 +--- colab/planet/admin.py | 3 ++- colab/planet/management/commands/update_planet.py | 2 +- colab/planet/models.py | 3 ++- colab/planet/tests.py | 3 ++- colab/planet/views.py | 3 ++- colab/search/admin.py | 3 ++- colab/search/forms.py | 13 +++++++------ colab/search/models.py | 3 ++- colab/search/tests.py | 3 ++- colab/search/views.py | 24 +++++++++++++----------- colab/settings.py | 3 ++- colab/super_archives/admin.py | 10 +++++----- colab/super_archives/apps.py | 3 ++- colab/super_archives/context_processors.py | 4 +++- colab/super_archives/management/commands/message.py | 6 +++--- colab/super_archives/management/commands/update_keywords.py | 2 +- colab/super_archives/managers.py | 1 - colab/super_archives/migrations/0001_initial.py | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------ colab/super_archives/models.py | 34 +++++++++++++++++++--------------- colab/super_archives/search_indexes.py | 4 ++-- colab/super_archives/signals.py | 2 +- colab/super_archives/templatetags/superarchives.py | 4 +--- colab/super_archives/urls.py | 13 +++++++------ colab/super_archives/utils/blocks.py | 15 ++++++++------- colab/super_archives/utils/email.py | 3 ++- colab/super_archives/utils/url.py | 2 +- colab/super_archives/views.py | 19 +++++++++---------- colab/urls.py | 15 ++++++++------- setup.py | 2 +- 42 files changed, 209 insertions(+), 146 deletions(-) diff --git a/colab/badger/admin.py b/colab/badger/admin.py index c0d0b0d..25cf1f4 100644 --- a/colab/badger/admin.py +++ b/colab/badger/admin.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- from django.contrib import admin -from django.utils.translation import ugettext_lazy as _ from .forms import BadgeForm from .models import Badge, BadgeI18N diff --git a/colab/badger/forms.py b/colab/badger/forms.py index f5c6125..ca9c507 100644 --- a/colab/badger/forms.py +++ b/colab/badger/forms.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- -import base64 - from django import forms from django.utils.translation import ugettext_lazy as _ diff --git a/colab/badger/management/commands/rebuild_badges.py b/colab/badger/management/commands/rebuild_badges.py index 11d6af7..94d547d 100644 --- a/colab/badger/management/commands/rebuild_badges.py +++ b/colab/badger/management/commands/rebuild_badges.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from django.core.management.base import BaseCommand, CommandError +from django.core.management.base import BaseCommand from haystack.query import SearchQuerySet from colab.accounts.models import User @@ -23,7 +23,7 @@ class Command(BaseCommand): continue comparison = u'__{}'.format(badge.comparison) if badge.comparison \ - is not 'equal' else u'' + is not 'equal' else u'' key = u'{}{}'.format( Badge.USER_ATTR_OPTS[badge.user_attr], diff --git a/colab/badger/management/commands/update_badges.py b/colab/badger/management/commands/update_badges.py index e75bb8b..c6b0325 100644 --- a/colab/badger/management/commands/update_badges.py +++ b/colab/badger/management/commands/update_badges.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from django.core.management.base import BaseCommand, CommandError +from django.core.management.base import BaseCommand from haystack.query import SearchQuerySet from colab.accounts.models import User @@ -8,6 +8,7 @@ from colab.badger.models import Badge import logging + class Command(BaseCommand): help = "Update the user's badges" @@ -23,7 +24,7 @@ class Command(BaseCommand): continue comparison = u'__{}'.format(badge.comparison) if badge.comparison \ - is not 'equal' else u'' + is not 'equal' else u'' key = u'{}{}'.format( Badge.USER_ATTR_OPTS[badge.user_attr], diff --git a/colab/badger/models.py b/colab/badger/models.py index b5b72bf..9820a9d 100644 --- a/colab/badger/models.py +++ b/colab/badger/models.py @@ -39,7 +39,7 @@ class Badge(models.Model): image_base64 = models.TextField(_(u'Image')) type = models.CharField(_(u'Type'), max_length=200, choices=TYPE_CHOICES) user_attr = models.CharField( - _(u'User attribute'),max_length=100, + _(u'User attribute'), max_length=100, choices=USER_ATTR_CHOICES, blank=True, null=True, diff --git a/colab/badger/tests.py b/colab/badger/tests.py index 7ce503c..e88a4a2 100644 --- a/colab/badger/tests.py +++ b/colab/badger/tests.py @@ -1,3 +1,4 @@ -from django.test import TestCase +# uncomment the import if you really use. +#from django.test import TestCase # Create your tests here. diff --git a/colab/badger/utils.py b/colab/badger/utils.py index bdb9e8a..4270b9e 100644 --- a/colab/badger/utils.py +++ b/colab/badger/utils.py @@ -2,27 +2,27 @@ from django.db.models import Count -#from proxy.trac.models import (Revision, Ticket, Wiki, -# WikiCollabCount, TicketCollabCount) +#from proxy.trac.models import (Ticket, Wiki) +#from proxy.trac.models import (Revision, WikiCollabCount, TicketCollabCount) from colab.accounts.models import User -def get_wiki_counters(): - return {author: count for author, count in - WikiCollabCount.objects.values_list()} +#def get_wiki_counters(): +# return {author: count for author, count in +# WikiCollabCount.objects.values_list()} -def get_revision_counters(): - return { - author: count for author, count in Revision.objects.values_list( - 'author' - ).annotate(count=Count('author')) - } +#def get_revision_counters(): +# return { +# author: count for author, count in Revision.objects.values_list( +# 'author' +# ).annotate(count=Count('author')) +# } -def get_ticket_counters(): - return {author: count for author, count in - TicketCollabCount.objects.values_list()} +#def get_ticket_counters(): +# return {author: count for author, count in +# TicketCollabCount.objects.values_list()} def get_users_counters(): diff --git a/colab/badger/views.py b/colab/badger/views.py index 91ea44a..70ce736 100644 --- a/colab/badger/views.py +++ b/colab/badger/views.py @@ -1,3 +1,4 @@ -from django.shortcuts import render +# uncomment the import if you really use. +# from django.shortcuts import render # Create your views here. diff --git a/colab/home/admin.py b/colab/home/admin.py index 8c38f3f..2e9147e 100644 --- a/colab/home/admin.py +++ b/colab/home/admin.py @@ -1,3 +1,4 @@ -from django.contrib import admin +# uncomment the import if you really use. +# from django.contrib import admin # Register your models here. diff --git a/colab/home/context_processors.py b/colab/home/context_processors.py index eb79083..5d38487 100644 --- a/colab/home/context_processors.py +++ b/colab/home/context_processors.py @@ -26,5 +26,6 @@ def ribbon(request): } } + def browserid_enabled(request): return {'BROWSERID_ENABLED': getattr(settings, 'BROWSERID_ENABLED', False)} diff --git a/colab/home/models.py b/colab/home/models.py index 71a8362..eb2ad62 100644 --- a/colab/home/models.py +++ b/colab/home/models.py @@ -1,3 +1,4 @@ -from django.db import models +# uncomment the import if you really use. +#from django.db import models # Create your models here. diff --git a/colab/home/tests.py b/colab/home/tests.py index 7ce503c..e88a4a2 100644 --- a/colab/home/tests.py +++ b/colab/home/tests.py @@ -1,3 +1,4 @@ -from django.test import TestCase +# uncomment the import if you really use. +#from django.test import TestCase # Create your tests here. diff --git a/colab/home/views.py b/colab/home/views.py index ad65f55..1399392 100644 --- a/colab/home/views.py +++ b/colab/home/views.py @@ -15,8 +15,6 @@ from colab.super_archives.models import Thread def dashboard(request): """Dashboard page""" - - latest_threads = Thread.objects.all()[:6] hottest_threads = Thread.highest_score.from_haystack()[:6] @@ -40,7 +38,7 @@ def dashboard(request): # count_types['wiki'] = sum([ # wiki.count for wiki in WikiCollabCount.objects.all() # ]) - + cache.set('home_chart', count_types) for key in count_types.keys(): diff --git a/colab/planet/admin.py b/colab/planet/admin.py index 8c38f3f..6e63521 100644 --- a/colab/planet/admin.py +++ b/colab/planet/admin.py @@ -1,3 +1,4 @@ -from django.contrib import admin +# uncomment the import if you really use. +#from django.contrib import admin # Register your models here. diff --git a/colab/planet/management/commands/update_planet.py b/colab/planet/management/commands/update_planet.py index 8d7fc03..91fea42 100644 --- a/colab/planet/management/commands/update_planet.py +++ b/colab/planet/management/commands/update_planet.py @@ -1,5 +1,5 @@ -from django.conf import settings +from django.conf import settings from feedzilla.management.commands import feedzilla_update diff --git a/colab/planet/models.py b/colab/planet/models.py index 71a8362..eb2ad62 100644 --- a/colab/planet/models.py +++ b/colab/planet/models.py @@ -1,3 +1,4 @@ -from django.db import models +# uncomment the import if you really use. +#from django.db import models # Create your models here. diff --git a/colab/planet/tests.py b/colab/planet/tests.py index 7ce503c..e88a4a2 100644 --- a/colab/planet/tests.py +++ b/colab/planet/tests.py @@ -1,3 +1,4 @@ -from django.test import TestCase +# uncomment the import if you really use. +#from django.test import TestCase # Create your tests here. diff --git a/colab/planet/views.py b/colab/planet/views.py index 91ea44a..de8a5a0 100644 --- a/colab/planet/views.py +++ b/colab/planet/views.py @@ -1,3 +1,4 @@ -from django.shortcuts import render +# uncomment the import if you really use. +#from django.shortcuts import render # Create your views here. diff --git a/colab/search/admin.py b/colab/search/admin.py index 8c38f3f..6e63521 100644 --- a/colab/search/admin.py +++ b/colab/search/admin.py @@ -1,3 +1,4 @@ -from django.contrib import admin +# uncomment the import if you really use. +#from django.contrib import admin # Register your models here. diff --git a/colab/search/forms.py b/colab/search/forms.py index 1b3150f..04ef66e 100644 --- a/colab/search/forms.py +++ b/colab/search/forms.py @@ -8,8 +8,7 @@ from django.utils.translation import ugettext_lazy as _ from haystack.forms import SearchForm from haystack.inputs import AltParser -from colab.accounts.models import User -from colab.super_archives.models import Message, MailingList +from colab.super_archives.models import MailingList class ColabSearchForm(SearchForm): @@ -90,8 +89,8 @@ class ColabSearchForm(SearchForm): sqs = sqs.filter_or(**filter_sizes_exp) if self.cleaned_data['used_by']: - sqs = sqs.filter_or(used_by__in=self.cleaned_data['used_by'].split()) - + sqs = sqs.filter_or(used_by__in=self.cleaned_data['used_by'] + .split()) if self.cleaned_data['q']: q = unicodedata.normalize( @@ -103,7 +102,8 @@ class ColabSearchForm(SearchForm): 'pf': 'title^2.1 author^1.9 description^1.7', 'mm': '2<70%', - # Date boosting: http://wiki.apache.org/solr/FunctionQuery#Date_Boosting + # Date boosting: + # http://wiki.apache.org/solr/FunctionQuery#Date_Boosting 'bf': 'recip(ms(NOW/HOUR,modified),3.16e-11,1,1)^10', } @@ -124,8 +124,9 @@ class ColabSearchForm(SearchForm): ) if self.cleaned_data['modified_by']: + modified_by_data = self.cleaned_date['modified_by'] sqs = sqs.filter( - fullname_and_username__contains=self.cleaned_data['modified_by'] + fullname_and_username__contains=modified_by_data ) if self.cleaned_data['milestone']: diff --git a/colab/search/models.py b/colab/search/models.py index 71a8362..eb2ad62 100644 --- a/colab/search/models.py +++ b/colab/search/models.py @@ -1,3 +1,4 @@ -from django.db import models +# uncomment the import if you really use. +#from django.db import models # Create your models here. diff --git a/colab/search/tests.py b/colab/search/tests.py index 7ce503c..e88a4a2 100644 --- a/colab/search/tests.py +++ b/colab/search/tests.py @@ -1,3 +1,4 @@ -from django.test import TestCase +# uncomment the import if you really use. +#from django.test import TestCase # Create your tests here. diff --git a/colab/search/views.py b/colab/search/views.py index 751f18e..813bd6a 100644 --- a/colab/search/views.py +++ b/colab/search/views.py @@ -145,17 +145,19 @@ class ColabSearchView(SearchView): size_choices = () used_by_choices = () - if type_chosen == 'attachment': - mimetype_choices = [(type_, display) for type_, display, mimelist_ in settings.FILE_TYPE_GROUPINGS] - size_choices = [ - ('<500KB', u'< 500 KB'), - ('500KB__10MB', u'>= 500 KB <= 10 MB'), - ('>10MB', u'> 10 MB'), - ] - used_by_choices = set([ - (v, v) for v in Attachment.objects.values_list( - 'used_by', flat=True) - ]) + #if type_chosen == 'attachment': + # mimetype_choices = [ + # (type_, display) + # for type_, display, mimelist_ in settings.FILE_TYPE_GROUPINGS] + # size_choices = [ + # ('<500KB', u'< 500 KB'), + # ('500KB__10MB', u'>= 500 KB <= 10 MB'), + # ('>10MB', u'> 10 MB'), + # ] + # used_by_choices = set([ + # (v, v) for v in Attachment.objects.values_list('used_by', + # flat=True) + # ]) mimetype_chosen = self.request.GET.get('mimetype') size_chosen = self.request.GET.get('size') diff --git a/colab/settings.py b/colab/settings.py index 801254f..fda5560 100644 --- a/colab/settings.py +++ b/colab/settings.py @@ -90,7 +90,8 @@ MEDIA_ROOT = '/usr/share/nginx/colab/media/' STATIC_URL = '/static/' MEDIA_URL = '/media/' -STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage' +STATICFILES_STORAGE = \ + 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage' # Normally you should not import ANYTHING from Django directly diff --git a/colab/super_archives/admin.py b/colab/super_archives/admin.py index 16dfec7..0eec972 100644 --- a/colab/super_archives/admin.py +++ b/colab/super_archives/admin.py @@ -11,13 +11,14 @@ class EmailAddressAdmin(admin.ModelAdmin): 'user__last_name', ) + class MessageAdmin(admin.ModelAdmin): list_filter = ('spam', 'thread__mailinglist', 'received_time', ) search_fields = ( 'id', 'subject', 'subject_clean', - 'body', + 'body', 'from_address__real_name', 'from_address__address', 'from_address__user__first_name', @@ -40,14 +41,14 @@ class ThreadAdmin(admin.ModelAdmin): 'message__from_address__user__last_name', 'message__from_address__user__username', ) - + readonly_fields = ( 'mailinglist', 'subject_token', 'latest_message', 'score', ) - + fields = ( 'mailinglist', 'subject_token', @@ -55,10 +56,9 @@ class ThreadAdmin(admin.ModelAdmin): 'score', 'spam', ) - + admin.site.register(MailingList) admin.site.register(Thread, ThreadAdmin) admin.site.register(Message, MessageAdmin) admin.site.register(EmailAddress, EmailAddressAdmin) - diff --git a/colab/super_archives/apps.py b/colab/super_archives/apps.py index eca1b7a..f1b940f 100644 --- a/colab/super_archives/apps.py +++ b/colab/super_archives/apps.py @@ -7,4 +7,5 @@ class SuperArchivesConfig(AppConfig): verbose_name = 'Super Archives' def ready(self): - from . import signals + pass + #from . import signals diff --git a/colab/super_archives/context_processors.py b/colab/super_archives/context_processors.py index a60b59c..6939543 100644 --- a/colab/super_archives/context_processors.py +++ b/colab/super_archives/context_processors.py @@ -1,11 +1,13 @@ from .models import Message + def mailarchive(request): context = {} try: - context['last_imported_message'] = Message.objects.latest('received_time') + context['last_imported_message'] = \ + Message.objects.latest('received_time') except Message.DoesNotExist: pass diff --git a/colab/super_archives/management/commands/message.py b/colab/super_archives/management/commands/message.py index 690ab5e..8c5be92 100644 --- a/colab/super_archives/management/commands/message.py +++ b/colab/super_archives/management/commands/message.py @@ -71,15 +71,15 @@ class Message(mailbox.mboxMessage): return u"\n".join(body).strip() - else: # if it is not multipart, the payload will be a string - # representing the message body + else: # if it is not multipart, the payload will be a string + # representing the message body body = unicode(self.get_payload(decode=True), get_charset(self), "replace") return body.strip() def get_received_datetime(self): - if not self.has_key('Received'): + if not self in ('Received'): return None # The time received should always be the last element # in the `Received` attribute from the message headers diff --git a/colab/super_archives/management/commands/update_keywords.py b/colab/super_archives/management/commands/update_keywords.py index be59910..4dd49e2 100644 --- a/colab/super_archives/management/commands/update_keywords.py +++ b/colab/super_archives/management/commands/update_keywords.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -from django.core.management.base import BaseCommand, CommandError +from django.core.management.base import BaseCommand from colab.super_archives.models import Thread diff --git a/colab/super_archives/managers.py b/colab/super_archives/managers.py index d79d25a..6165207 100644 --- a/colab/super_archives/managers.py +++ b/colab/super_archives/managers.py @@ -1,7 +1,6 @@ from django.db import models from haystack.query import SearchQuerySet -import django class NotSpamManager(models.Manager): diff --git a/colab/super_archives/migrations/0001_initial.py b/colab/super_archives/migrations/0001_initial.py index c4f1ac3..32d8a0c 100644 --- a/colab/super_archives/migrations/0001_initial.py +++ b/colab/super_archives/migrations/0001_initial.py @@ -20,11 +20,15 @@ class Migration(migrations.Migration): migrations.CreateModel( name='EmailAddress', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('id', models.AutoField(verbose_name='ID', serialize=False, + auto_created=True, primary_key=True)), ('address', models.EmailField(unique=True, max_length=75)), - ('real_name', models.CharField(db_index=True, max_length=64, blank=True)), + ('real_name', models.CharField(db_index=True, max_length=64, + blank=True)), ('md5', models.CharField(max_length=32, null=True)), - ('user', models.ForeignKey(related_name=b'emails', on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, null=True)), + ('user', models.ForeignKey(related_name=b'emails', + on_delete=django.db.models.deletion.SET_NULL, + to=settings.AUTH_USER_MODEL, null=True)), ], options={ 'ordering': ('id',), @@ -34,11 +38,17 @@ class Migration(migrations.Migration): migrations.CreateModel( name='EmailAddressValidation', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('id', models.AutoField(verbose_name='ID', serialize=False, + auto_created=True, primary_key=True)), ('address', models.EmailField(unique=True, max_length=75)), - ('validation_key', models.CharField(default=colab.super_archives.models.get_validation_key, max_length=32, null=True)), + ('validation_key', + models.CharField( + default=colab.super_archives.models.get_validation_key, + max_length=32, null=True)), ('created', models.DateTimeField(auto_now_add=True)), - ('user', models.ForeignKey(related_name=b'emails_not_validated', to=settings.AUTH_USER_MODEL, null=True)), + ('user', + models.ForeignKey(related_name=b'emails_not_validated', + to=settings.AUTH_USER_MODEL, null=True)), ], options={ }, @@ -47,7 +57,8 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Keyword', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('id', models.AutoField(verbose_name='ID', serialize=False, + auto_created=True, primary_key=True)), ('keyword', models.CharField(max_length=b'128')), ('weight', models.IntegerField(default=0)), ], @@ -59,7 +70,8 @@ class Migration(migrations.Migration): migrations.CreateModel( name='MailingList', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('id', models.AutoField(verbose_name='ID', serialize=False, + auto_created=True, primary_key=True)), ('name', models.CharField(max_length=80)), ('email', models.EmailField(max_length=75)), ('description', models.TextField()), @@ -73,8 +85,10 @@ class Migration(migrations.Migration): migrations.CreateModel( name='MailingListMembership', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('mailinglist', models.ForeignKey(to='super_archives.MailingList')), + ('id', models.AutoField(verbose_name='ID', serialize=False, + auto_created=True, primary_key=True)), + ('mailinglist', + models.ForeignKey(to='super_archives.MailingList')), ('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)), ], options={ @@ -84,14 +98,23 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Message', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('subject', models.CharField(help_text='Please enter a message subject', max_length=512, verbose_name='Subject', db_index=True)), - ('subject_clean', models.CharField(max_length=512, db_index=True)), - ('body', models.TextField(default=b'', help_text='Please enter a message body', verbose_name='Message body')), + ('id', models.AutoField(verbose_name='ID', serialize=False, + auto_created=True, primary_key=True)), + ('subject', + models.CharField(help_text='Please enter a message subject', + max_length=512, verbose_name='Subject', + db_index=True)), + ('subject_clean', models.CharField(max_length=512, + db_index=True)), + ('body', + models.TextField(default=b'', + help_text='Please enter a message body', + verbose_name='Message body')), ('received_time', models.DateTimeField(db_index=True)), ('message_id', models.CharField(max_length=512)), ('spam', models.BooleanField(default=False)), - ('from_address', models.ForeignKey(to='super_archives.EmailAddress')), + ('from_address', + models.ForeignKey(to='super_archives.EmailAddress')), ], options={ 'ordering': ('received_time',), @@ -103,11 +126,13 @@ class Migration(migrations.Migration): migrations.CreateModel( name='MessageBlock', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('id', models.AutoField(verbose_name='ID', serialize=False, + auto_created=True, primary_key=True)), ('text', models.TextField()), ('is_reply', models.BooleanField(default=False)), ('order', models.IntegerField()), - ('message', models.ForeignKey(related_name=b'blocks', to='super_archives.Message')), + ('message', models.ForeignKey(related_name=b'blocks', + to='super_archives.Message')), ], options={ 'ordering': ('order',), @@ -117,7 +142,8 @@ class Migration(migrations.Migration): migrations.CreateModel( name='MessageMetadata', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('id', models.AutoField(verbose_name='ID', serialize=False, + auto_created=True, primary_key=True)), ('name', models.CharField(max_length=512)), ('value', models.TextField()), ('Message', models.ForeignKey(to='super_archives.Message')), @@ -129,13 +155,29 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Thread', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('id', models.AutoField(verbose_name='ID', serialize=False, + auto_created=True, primary_key=True)), ('subject_token', models.CharField(max_length=512)), - ('score', models.IntegerField(default=0, help_text='Thread score', verbose_name='Score')), + ('score', models.IntegerField(default=0, + help_text='Thread score', + verbose_name='Score')), ('spam', models.BooleanField(default=False)), - ('latest_message', models.OneToOneField(related_name=b'+', null=True, to='super_archives.Message', help_text='Latest message posted', verbose_name='Latest message')), - ('mailinglist', models.ForeignKey(verbose_name='Mailing List', to='super_archives.MailingList', help_text='The Mailing List where is the thread')), - ('tags', taggit.managers.TaggableManager(to='taggit.Tag', through='taggit.TaggedItem', help_text='A comma-separated list of tags.', verbose_name='Tags')), + ('latest_message', + models.OneToOneField(related_name=b'+', + null=True, to='super_archives.Message', + help_text='Latest message posted', + verbose_name='Latest message')), + ('mailinglist', + models.ForeignKey( + verbose_name='Mailing List', + to='super_archives.MailingList', + help_text='The Mailing List where is the thread')), + ('tags', + taggit.managers.TaggableManager( + to='taggit.Tag', + through='taggit.TaggedItem', + help_text='A comma-separated list of tags.', + verbose_name='Tags')), ], options={ 'ordering': ('-latest_message__received_time',), @@ -147,7 +189,8 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Vote', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('id', models.AutoField(verbose_name='ID', serialize=False, + auto_created=True, primary_key=True)), ('created', models.DateTimeField(auto_now_add=True)), ('message', models.ForeignKey(to='super_archives.Message')), ('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)), diff --git a/colab/super_archives/models.py b/colab/super_archives/models.py index 5857513..7fa4d7b 100644 --- a/colab/super_archives/models.py +++ b/colab/super_archives/models.py @@ -38,12 +38,14 @@ class EmailAddressValidation(models.Model): @classmethod def create(cls, address, user): - email_address_validation = cls.objects.create(address=address, user=user) - email.send_verification_email(email_address_validation.address, - email_address_validation.user, - email_address_validation.validation_key) + email_address_validation = cls.objects.create(address=address, + user=user) + email.send_verification_email(email_address_validation.address, + email_address_validation.user, + email_address_validation.validation_key) return email_address_validation + class EmailAddress(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, related_name='emails', on_delete=models.SET_NULL) @@ -114,14 +116,17 @@ class Keyword(models.Model): class Thread(models.Model, HitCounterModelMixin): subject_token = models.CharField(max_length=512) - mailinglist = models.ForeignKey(MailingList, - verbose_name=_(u"Mailing List"), - help_text=_(u"The Mailing List where is the thread")) - latest_message = models.OneToOneField('Message', null=True, - related_name='+', - verbose_name=_(u"Latest message"), - help_text=_(u"Latest message posted")) - score = models.IntegerField(default=0, verbose_name=_(u"Score"), help_text=_(u"Thread score")) + mailinglist = \ + models.ForeignKey( + MailingList, + verbose_name=_(u"Mailing List"), + help_text=_(u"The Mailing List where is the thread")) + latest_message = \ + models.OneToOneField('Message', null=True, related_name='+', + verbose_name=_(u"Latest message"), + help_text=_(u"Latest message posted")) + score = models.IntegerField(default=0, verbose_name=_(u"Score"), + help_text=_(u"Thread score")) spam = models.BooleanField(default=False) highest_score = HighestScore() @@ -204,8 +209,8 @@ class Thread(models.Model, HitCounterModelMixin): # function N times in the loops below now = timezone.now() days_ago = lambda date: (now - date).days - get_score = lambda weight, created: \ - max(weight - (days_ago(created) // 3), 5) + get_score = lambda weight, created: max(weight - (days_ago(created) + // 3), 5) vote_score = 0 replies_score = 0 @@ -384,7 +389,6 @@ class MessageBlock(models.Model): return obj - class MessageMetadata(models.Model): Message = models.ForeignKey(Message) # Same problem here than on subjects. Read comment above diff --git a/colab/super_archives/search_indexes.py b/colab/super_archives/search_indexes.py index face2e6..30b4029 100644 --- a/colab/super_archives/search_indexes.py +++ b/colab/super_archives/search_indexes.py @@ -36,8 +36,8 @@ class ThreadIndex(BaseIndex, indexes.Indexable): def get_updated_field(self): return 'latest_message__received_time' - def prepare_fullname(self, obj): - return obj.message_set.first().from_address.get_full_name() + #def prepare_fullname(self, obj): + # return obj.message_set.first().from_address.get_full_name() def prepare_fullname_and_username(self, obj): from_address = obj.message_set.first().from_address diff --git a/colab/super_archives/signals.py b/colab/super_archives/signals.py index a888758..ba3a4f7 100644 --- a/colab/super_archives/signals.py +++ b/colab/super_archives/signals.py @@ -13,7 +13,7 @@ def create_email_address(sender, instance, created, **kwargs): email, email_created = EmailAddress.objects.get_or_create( address=instance.email, - defaults= { + defaults={ 'real_name': instance.get_full_name(), 'user': instance, } diff --git a/colab/super_archives/templatetags/superarchives.py b/colab/super_archives/templatetags/superarchives.py index e1cbfb2..560771d 100644 --- a/colab/super_archives/templatetags/superarchives.py +++ b/colab/super_archives/templatetags/superarchives.py @@ -1,7 +1,5 @@ from django import template -from django.conf import settings - from colab.super_archives.utils import url @@ -14,7 +12,7 @@ def display_message(email): if not email.blocks.count(): email.update_blocks() - return { 'blocks': email.blocks.all } + return {'blocks': email.blocks.all} @register.simple_tag(takes_context=True) diff --git a/colab/super_archives/urls.py b/colab/super_archives/urls.py index 1ab90e2..dae37e3 100644 --- a/colab/super_archives/urls.py +++ b/colab/super_archives/urls.py @@ -1,15 +1,16 @@ -from django.conf.urls import patterns, include, url +from django.conf.urls import patterns, url -from .views import EmailView, EmailValidationView, ThreadView, \ - ThreadDashboardView +from .views import EmailView, EmailValidationView, ThreadView +from .views import ThreadDashboardView -urlpatterns = patterns('super_archives.views', +urlpatterns = patterns( + 'super_archives.views', url(r'thread/(?P[-\w]+)/(?P[-\w]+)$', ThreadView.as_view(), name="thread_view"), url(r'thread/$', ThreadDashboardView.as_view(), name='thread_list'), url(r'manage/email/validate/?$', EmailValidationView.as_view(), - name="archive_email_validation_view"), + name="archive_email_validation_view"), url(r'manage/email/(?P[0-9a-z]{32})?', EmailView.as_view(), - name="archive_email_view"), + name="archive_email_view"), ) diff --git a/colab/super_archives/utils/blocks.py b/colab/super_archives/utils/blocks.py index f6e57d7..a3e868d 100644 --- a/colab/super_archives/utils/blocks.py +++ b/colab/super_archives/utils/blocks.py @@ -8,7 +8,7 @@ from html2text import html2text EXTENDED_PUNCTUATION = '!"#$%&\'()*+,-./:;=?@[\\]^_`{|}~ \t\n\r\x0b\x0c' RE_WRAPPED_BY_HTML = re.compile(r'^<[a-z]+[^>]*>.*]*>$', - re.MULTILINE|re.IGNORECASE|re.DOTALL) + re.MULTILINE | re.IGNORECASE | re.DOTALL) RE_LINKS = re.compile(r'(?Phttps?://[^ \t\r\n\<]+)') LINK_MARKUP = u'\g' @@ -26,8 +26,8 @@ class EmailBlock(list): def _html2text(self, text): if RE_WRAPPED_BY_HTML.match(text.strip()): return html2text(text) - - text, n = RE_BR_TO_LINEBREAK.subn('\n', text) + + text, n = RE_BR_TO_LINEBREAK.subn('\n', text) text = strip_tags(text) return text @@ -90,10 +90,11 @@ class EmailBlockParser(list): return True clean_line = RE_REPLY_LINE.subn('', stripped_line)[0] - queryset = self.thread_emails.filter( - received_time__lt=self.email.received_time, - body__contains=clean_line).order_by('-received_time') - + queryset = \ + self.thread_emails.filter( + received_time__lt=self.email.received_time, + body__contains=clean_line).order_by('-received_time') + if queryset[:1]: return True diff --git a/colab/super_archives/utils/email.py b/colab/super_archives/utils/email.py index 9095406..d77f235 100644 --- a/colab/super_archives/utils/email.py +++ b/colab/super_archives/utils/email.py @@ -12,7 +12,8 @@ def colab_send_email(subject, message, to): def send_verification_email(to, user, validation_key): subject = _('Please verify your email ') + u'{}'.format(to) - msg_tmpl = loader.get_template('superarchives/emails/email_verification.txt') + msg_tmpl = \ + loader.get_template('superarchives/emails/email_verification.txt') message = msg_tmpl.render(Context({'to': to, 'user': user, 'key': validation_key, 'SITE_URL': settings.SITE_URL})) diff --git a/colab/super_archives/utils/url.py b/colab/super_archives/utils/url.py index 38f5402..e8a7cf6 100644 --- a/colab/super_archives/utils/url.py +++ b/colab/super_archives/utils/url.py @@ -14,7 +14,7 @@ def append_to_get(path, query=None, **kwargs): def pop_from_get(path, query=None, **kwargs): query_dict = dict(urlparse.parse_qsl(query)) for key, value in kwargs.items(): - if not query_dict.has_key(key): + if not query_dict in (key): continue if query_dict[key] == value: del query_dict[key] diff --git a/colab/super_archives/views.py b/colab/super_archives/views.py index 02925f7..04c07ab 100644 --- a/colab/super_archives/views.py +++ b/colab/super_archives/views.py @@ -11,7 +11,6 @@ from django.conf import settings from django.contrib import messages from django.db import IntegrityError from django.views.generic import View -from django.core.paginator import Paginator, EmptyPage from django.utils.translation import ugettext as _ from django.core.exceptions import ObjectDoesNotExist from django.utils.decorators import method_decorator @@ -23,8 +22,8 @@ from haystack.query import SearchQuerySet from colab.accounts.utils import mailman from colab.accounts.models import User from .utils.email import send_verification_email -from .models import MailingList, Thread, EmailAddress, \ - EmailAddressValidation, Message +from .models import MailingList, Thread, EmailAddress +from .models import EmailAddressValidation, Message class ThreadView(View): @@ -83,7 +82,8 @@ class ThreadView(View): 'body': request.POST.get('emailbody', '').strip(), } - url = urlparse.urljoin(settings.MAILMAN_API_URL, mailinglist + '/sendmail') + url = urlparse.urljoin(settings.MAILMAN_API_URL, + mailinglist + '/sendmail') error_msg = None try: @@ -110,7 +110,8 @@ class ThreadView(View): elif resp.status_code == 404: error_msg = _('Mailing list does not exist') else: - error_msg = _('Unknown error trying to connect to Mailman API') + error_msg = _('Unknown error\ + trying to connect to Mailman API') messages.error(request, error_msg) return self.get(request, mailinglist, thread_token) @@ -125,7 +126,7 @@ class ThreadDashboardView(View): all_lists = mailman.all_lists(description=True) context['lists'] = [] - lists = MailingList.objects.filter() + #lists = MailingList.objects.filter() for list_ in MailingList.objects.order_by('name'): context['lists'].append(( list_.name, @@ -134,7 +135,7 @@ class ThreadDashboardView(View): '-latest_message__received_time' )[:MAX], SearchQuerySet().filter(type='thread', tag=list_.name)[:MAX], - len(mailman.list_users(list_.name)), + len(mailman.list_users(list_.name)), )) return render(request, 'superarchives/thread-dashboard.html', context) @@ -151,7 +152,7 @@ class EmailView(View): email_val = EmailAddressValidation.objects.get(validation_key=key) except EmailAddressValidation.DoesNotExist: messages.error(request, _('The email address you are trying to ' - 'verify either has already been verified ' + 'verify either has already been verified' 'or does not exist.')) return redirect('/') @@ -170,7 +171,6 @@ class EmailView(View): email.user = email_val.user email.save() email_val.delete() - user = User.objects.get(username=email.user.username) user.is_active = True user.save() @@ -178,7 +178,6 @@ class EmailView(View): messages.success(request, _('Email address verified!')) return redirect('user_profile', username=email_val.user.username) - @method_decorator(login_required) def post(self, request, key): """Create new email address that will wait for validation""" diff --git a/colab/urls.py b/colab/urls.py index 79e0ca3..51b0bfc 100644 --- a/colab/urls.py +++ b/colab/urls.py @@ -4,14 +4,11 @@ from django.views.generic import TemplateView from django.contrib import admin from django.views.generic import RedirectView -from colab.accounts.models import User -from .search.forms import ColabSearchForm -from .super_archives.models import Message - admin.autodiscover() -urlpatterns = patterns('', +urlpatterns = patterns( + '', url(r'^robots.txt$', 'colab.home.views.robots', name='robots'), url(r'^dashboard$', 'colab.home.views.dashboard', name='dashboard'), url(r'^$', RedirectView.as_view(url=settings.COLAB_HOME_URL), name='home'), @@ -24,8 +21,12 @@ urlpatterns = patterns('', url(r'^api/', include('colab.api.urls')), url(r'^rss/', include('colab.rss.urls')), - url(r'^user/', include('colab.accounts.urls')), # Kept for backwards compatibility - url(r'^signup/', include('colab.accounts.urls')), # (same here) TODO: move to nginx + # Kept for backwards compatibility + url(r'^user/', include('colab.accounts.urls')), + # Kept for backwards compatibility + url(r'^user/', include('colab.accounts.urls')), + # (same here) TODO: move to nginx + url(r'^signup/', include('colab.accounts.urls')), url(r'^account/', include('colab.accounts.urls')), url(r'', include('django_browserid.urls')), diff --git a/setup.py b/setup.py index 2f63408..b67aebc 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages - + REQUIREMENTS = [ 'Django>=1.7', -- libgit2 0.21.2