Skip to content

Commit

Permalink
Adding pep8 and pyflakes to dev external dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
zuzelvp committed Jun 27, 2011
1 parent de3ed19 commit bc3a084
Show file tree
Hide file tree
Showing 94 changed files with 1,372 additions and 1,133 deletions.
1 change: 0 additions & 1 deletion apps/activity/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from activity.models import Activity, RemoteObject


def send(actor, verb, object, target=None):
Expand Down
1 change: 0 additions & 1 deletion apps/activity/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from django.shortcuts import get_object_or_404
from django.utils.translation import ugettext as _
from django.utils.feedgenerator import rfc3339_date
from django.http import Http404

from l10n.urlresolvers import reverse
from django_push.publisher.feeds import Feed, HubAtom1Feed
Expand Down
46 changes: 27 additions & 19 deletions apps/activity/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.db import models, connection
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext
from django.template.loader import render_to_string
Expand Down Expand Up @@ -28,11 +28,15 @@ def public(self):
"""Get list of activities to show on splash page."""

return Activity.objects.filter(deleted=False,
parent__isnull=True, remote_object__isnull=True,
parent__isnull=True, remote_object__isnull=True,
status__isnull=True).filter(
models.Q(target_project__isnull=True) | models.Q(target_project__not_listed=False),
models.Q(project__isnull=True) | models.Q(project__not_listed=False)
).exclude(verb='http://activitystrea.ms/schema/1.0/follow').order_by('-created_on')[:10]
models.Q(target_project__isnull=True)
| models.Q(target_project__not_listed=False),
models.Q(project__isnull=True)
| models.Q(project__not_listed=False)
).exclude(
verb='http://activitystrea.ms/schema/1.0/follow'
).order_by('-created_on')[:10]

def dashboard(self, user):
"""
Expand Down Expand Up @@ -63,8 +67,10 @@ def for_user(self, user):
return Activity.objects.filter(deleted=False).select_related(
'actor', 'status', 'project').filter(
actor=user).filter(
models.Q(target_project__isnull=True) | models.Q(target_project__not_listed=False),
models.Q(project__isnull=True) | models.Q(project__not_listed=False)
models.Q(target_project__isnull=True)
| models.Q(target_project__not_listed=False),
models.Q(project__isnull=True)
| models.Q(project__not_listed=False)
).exclude(
models.Q(verb='http://activitystrea.ms/schema/1.0/follow'),
models.Q(target_user__isnull=False),
Expand All @@ -77,10 +83,12 @@ class Activity(ModelBase):
"""Represents a single activity entry."""
actor = models.ForeignKey('users.UserProfile')
verb = models.URLField(verify_exists=False)
status = models.ForeignKey('statuses.Status', null=True, related_name='activity')
status = models.ForeignKey('statuses.Status', null=True,
related_name='activity')
target_content_type = models.ForeignKey(ContentType, null=True)
target_id = models.PositiveIntegerField(null=True)
target_object = generic.GenericForeignKey('target_content_type', 'target_id')
target_object = generic.GenericForeignKey('target_content_type',
'target_id')
project = models.ForeignKey('projects.Project', null=True)
target_user = models.ForeignKey('users.UserProfile', null=True,
related_name='target_user')
Expand All @@ -104,23 +112,23 @@ def get_absolute_url(self):

@property
def object_type(self):
obj = (self.status or self.target_user or self.remote_object
or self.target_object or None)
obj = (self.status or self.target_user or self.remote_object
or self.target_object or None)
return obj and obj.object_type or None

@property
def object_url(self):
obj = (self.status or self.target_user or self.remote_object
or self.target_object or None)
obj = (self.status or self.target_user or self.remote_object
or self.target_object or None)
return obj and obj.get_absolute_url() or None

def textual_representation(self):
target = self.target_user or self.target_project or self.project
if target and self.verb == schema.verbs['follow']:
name = target.display_name if self.target_user else target.name
return _('%(actor)s %(verb)s %(target)s') % dict(
actor=self.actor.display_name, verb=schema.past_tense['follow'],
target=name)
actor=self.actor.display_name,
verb=schema.past_tense['follow'], target=name)
if self.status:
return self.status.status[:50]
elif self.remote_object:
Expand All @@ -130,15 +138,16 @@ def textual_representation(self):
return self.target_object.title

friendly_verb = schema.verbs_by_uri[self.verb]
return ugettext('%(verb)s activity performed by %(actor)s') % dict(verb=friendly_verb,
actor=self.actor.display_name)
return ugettext('%(verb)s activity performed by %(actor)s') % dict(
verb=friendly_verb, actor=self.actor.display_name)

def friendly_verb(self):
if self.verb == schema.verbs['post']:
if self.project_id:
return mark_safe(ugettext('created'))
else:
if self.object_type == 'http://activitystrea.ms/schema/1.0/comment':
comment_type = 'http://activitystrea.ms/schema/1.0/comment'
if self.object_type == comment_type:
return mark_safe(ugettext('posted comment'))
else:
return mark_safe(ugettext('added'))
Expand All @@ -163,4 +172,3 @@ def can_edit(self, user):
return (profile == self.actor)
else:
return False

8 changes: 4 additions & 4 deletions apps/activity/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
urlpatterns = patterns('',
url(r'^activity/(?P<activity_id>[\d]+)/$', 'activity.views.index',
name='activity_index'),
url(r'^activity/(?P<activity_id>[\d]+)/delete/$', 'activity.views.delete_restore',
name='activity_delete'),
url(r'^activity/(?P<activity_id>[\d]+)/restore/$', 'activity.views.delete_restore',
name='activity_restore'),
url(r'^activity/(?P<activity_id>[\d]+)/delete/$',
'activity.views.delete_restore', name='activity_delete'),
url(r'^activity/(?P<activity_id>[\d]+)/restore/$',
'activity.views.delete_restore', name='activity_restore'),
url(r'^(?P<username>[\w\-\. ]+)/feed$', feeds.UserActivityFeed(),
name='activity_user_feed'),
url(r'^projects/(?P<project>[\w\- ]+)/feed$', feeds.ProjectActivityFeed(),
Expand Down
11 changes: 8 additions & 3 deletions apps/activity/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def index(request, activity_id):
return HttpResponseRedirect(reverse('activity_restore',
kwargs={'activity_id': activity.id}))
elif activity.target_project:
return HttpResponseRedirect(activity.target_project.get_absolute_url())
return HttpResponseRedirect(
activity.target_project.get_absolute_url())
else:
return HttpResponseRedirect(activity.actor.get_absolute_url())
return render_to_response('activity/index.html', {
Expand All @@ -36,10 +37,14 @@ def delete_restore(request, activity_id):
if request.method == 'POST':
activity.deleted = not activity.deleted
activity.save()
msg = _('Message deleted!') if activity.deleted else _('Message restored!')
if activity.deleted:
msg = _('Message deleted!')
else:
msg = _('Message restored!')
messages.success(request, msg)
if activity.target_project:
return HttpResponseRedirect(activity.target_project.get_absolute_url())
return HttpResponseRedirect(
activity.target_project.get_absolute_url())
else:
return HttpResponseRedirect(reverse('dashboard_index'))
else:
Expand Down
1 change: 1 addition & 0 deletions apps/challenges/decorators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.http import HttpResponseForbidden
from django.shortcuts import get_object_or_404
from django.utils.translation import ugettext as _

from challenges.models import Challenge, Submission

Expand Down
7 changes: 4 additions & 3 deletions apps/challenges/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class Meta:
def clean_image(self):
if self.cleaned_data['image'].size > settings.MAX_IMAGE_SIZE:
max_size = settings.MAX_IMAGE_SIZE / 1024
raise forms.ValidationError(
_("Image exceeds max image size: %(max)dk" % dict(max=max_size)))
msg = _("Image exceeds max image size: %(max)dk")
raise forms.ValidationError(msg % dict(max=max_size))
return self.cleaned_data['image']


Expand All @@ -45,7 +45,8 @@ def save(self, sender):
challenge = Challenge.objects.get(id=int(challenge))
except Challenge.DoesNotExist:
raise forms.ValidationError(_(u'Not a valid challenge'))
recipients = UserProfile.objects.filter(submissions__challenge=challenge).distinct()
recipients = UserProfile.objects.filter(
submissions__challenge=challenge).distinct()
subject = self.cleaned_data['subject']
body = self.cleaned_data['body']
message_list = []
Expand Down
2 changes: 1 addition & 1 deletion apps/challenges/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def publish(self):
'slug': challenge.slug,
'submission_id': self.pk
})
subj = _('Thanks for entering in the Knight-Mozilla Innovation Challenge!')
subj = _('Thanks for entering in this challenge!')
body = render_to_string('challenges/emails/submission_thanks.txt', {
'share_url': share_url,
'submission_url': submission_url,
Expand Down
6 changes: 4 additions & 2 deletions apps/challenges/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ def show_challenge(request, slug):
qn = connection.ops.quote_name
ctype = ContentType.objects.get_for_model(Submission)

submission_set = challenge.submission_set.filter(is_published=True).extra(select={'score': """
submission_set = challenge.submission_set.filter(
is_published=True).extra(select={'score': """
SELECT SUM(vote)
FROM %s
WHERE content_type_id = %s
Expand Down Expand Up @@ -449,7 +450,8 @@ def challenge_judges_delete(request, slug, judge):
challenge = get_object_or_404(Challenge, slug=slug)
judge = get_object_or_404(Judge, pk=judge)
if judge.challenge != challenge:
return HttpResponseForbidden(_("You are not a judge of this challenge"))
return HttpResponseForbidden(
_("You are not a judge of this challenge"))
judge.delete()
messages.success(request, _('Judge removed.'))
return HttpResponseRedirect(reverse('challenges_judges', kwargs={
Expand Down
7 changes: 4 additions & 3 deletions apps/content/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ class PageVersionAdmin(admin.ModelAdmin):
date_hierarchy = 'date'
list_display = ('id', 'page', 'author', 'date', 'deleted')
list_filter = list_display[3:]
search_fields = ('id', 'page__slug', 'page__title', 'author__username', 'author__full_name')
search_fields = ('id', 'page__slug', 'page__title',
'author__username', 'author__full_name')


class PageCommentAdmin(admin.ModelAdmin):
date_hierarchy = 'created_on'
list_display = ('id', 'page', 'author', 'created_on', 'deleted')
list_filter = list_display[3:]
search_fields = ('id', 'page__slug', 'page__title', 'author__username', 'author__full_name')

search_fields = ('id', 'page__slug', 'page__title',
'author__username', 'author__full_name')


admin.site.register(Page, PageAdmin)
Expand Down
10 changes: 4 additions & 6 deletions apps/content/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Meta:
'content': CKEditorWidget(config_name=CKEDITOR_CONFIG_NAME),
}

def clean_content(self):
def clean_content(self):
data = self.cleaned_data['content']
if data.strip() == "<br />":
raise forms.ValidationError(_("This field is required."))
Expand All @@ -48,7 +48,7 @@ class Meta:
'content': CKEditorWidget(config_name=CKEDITOR_CONFIG_NAME),
}

def clean_content(self):
def clean_content(self):
data = self.cleaned_data['content']
if data.strip() == "<br />":
raise forms.ValidationError(_("This field is required."))
Expand All @@ -64,7 +64,7 @@ class Meta:
'content': CKEditorWidget(config_name=CKEDITOR_CONFIG_NAME),
}

def clean_content(self):
def clean_content(self):
data = self.cleaned_data['content']
if data.strip() == "<br />":
raise forms.ValidationError(_("This field is required."))
Expand All @@ -80,10 +80,8 @@ class Meta:
'content': CKEditorWidget(config_name=CKEDITOR_CONFIG_NAME),
}

def clean_content(self):
def clean_content(self):
data = self.cleaned_data['content']
if data.strip() == "<br />":
raise forms.ValidationError(_("This field is required."))
return data


Loading

0 comments on commit bc3a084

Please sign in to comment.