Skip to content

Commit

Permalink
Make kitsune flake8 compliant.
Browse files Browse the repository at this point in the history
  • Loading branch information
mythmon committed Jan 8, 2014
1 parent b64557e commit 1cff5af
Show file tree
Hide file tree
Showing 165 changed files with 1,437 additions and 1,334 deletions.
3 changes: 2 additions & 1 deletion kitsune/announcements/forms.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class AnnouncementForm(forms.Form):
""" """
content = forms.CharField(label=_lazy(u'Content'), max_length=10000, content = forms.CharField(label=_lazy(u'Content'), max_length=10000,
widget=forms.Textarea) widget=forms.Textarea)
show_after = forms.DateField(label=_lazy(u'Show after'), initial=date.today, show_after = forms.DateField(label=_lazy(u'Show after'),
initial=date.today,
input_formats=['%Y-%m-%d']) input_formats=['%Y-%m-%d'])
show_until = forms.DateField(label=_lazy(u'Show until'), required=False, show_until = forms.DateField(label=_lazy(u'Show until'), required=False,
input_formats=['%Y-%m-%d']) input_formats=['%Y-%m-%d'])
8 changes: 4 additions & 4 deletions kitsune/announcements/models.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ class Announcement(ModelBase):
default=datetime.now, db_index=True, default=datetime.now, db_index=True,
verbose_name='Start displaying', verbose_name='Start displaying',
help_text=('When this announcement will start appearing. ' help_text=('When this announcement will start appearing. '
'(US/Pacific)')) '(US/Pacific)'))
show_until = models.DateTimeField( show_until = models.DateTimeField(
db_index=True, null=True, blank=True, db_index=True, null=True, blank=True,
verbose_name='Stop displaying', verbose_name='Stop displaying',
help_text=('When this announcement will stop appearing. ' help_text=('When this announcement will stop appearing. '
'Leave blank for indefinite. (US/Pacific)')) 'Leave blank for indefinite. (US/Pacific)'))
content = models.TextField( content = models.TextField(
max_length=10000, max_length=10000,
help_text=("Use wiki syntax or HTML. It will display similar to a " help_text=("Use wiki syntax or HTML. It will display similar to a "
"document's content.")) "document's content."))
group = models.ForeignKey(Group, null=True, blank=True) group = models.ForeignKey(Group, null=True, blank=True)
locale = models.ForeignKey(Locale, null=True, blank=True) locale = models.ForeignKey(Locale, null=True, blank=True)


def __unicode__(self): def __unicode__(self):
excerpt = self.content[:50] excerpt = self.content[:50]
if self.group: if self.group:
return u'[{group}] {excerpt}'.format(group=self.group, return u'[{group}] {excerpt}'.format(group=self.group,
excerpt=excerpt) excerpt=excerpt)
return u'{excerpt}'.format(excerpt=excerpt) return u'{excerpt}'.format(excerpt=excerpt)


def is_visible(self): def is_visible(self):
Expand Down
4 changes: 1 addition & 3 deletions kitsune/announcements/tasks.py
Original file line number Original file line Diff line number Diff line change
@@ -1,15 +1,13 @@
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.core.mail import EmailMultiAlternatives


import bleach import bleach
from celery.task import task from celery.task import task
from tower import ugettext as _ from tower import ugettext as _


from kitsune.announcements.models import Announcement from kitsune.announcements.models import Announcement
from kitsune.sumo.email_utils import ( from kitsune.sumo.email_utils import make_mail, safe_translation, send_messages
make_mail, render_email, safe_translation, send_messages)




@task @task
Expand Down
6 changes: 3 additions & 3 deletions kitsune/announcements/tests/test_views.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def setUp(self):
self.locale.leaders.add(self.u) self.locale.leaders.add(self.u)
self.locale.save() self.locale.save()


self.announcement = announcement(save=True, creator=self.u, self.announcement = announcement(
locale=self.locale, content="Look at me!", creator=self.u, locale=self.locale, content="Look at me!",
show_after=datetime(2012, 01, 01, 0, 0, 0)) show_after=datetime(2012, 01, 01, 0, 0, 0), save=True)


def _delete_test(self, id, status, count): def _delete_test(self, id, status, count):
"""Login, or other setup, then call this.""" """Login, or other setup, then call this."""
Expand Down
3 changes: 2 additions & 1 deletion kitsune/announcements/urls.py
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.conf.urls import patterns, url from django.conf.urls import patterns, url




urlpatterns = patterns('kitsune.announcements.views', urlpatterns = patterns(
'kitsune.announcements.views',
url(r'^/create/locale$', 'create_for_locale', url(r'^/create/locale$', 'create_for_locale',
name='announcements.create_for_locale'), name='announcements.create_for_locale'),
url(r'^/(?P<announcement_id>\d+)/delete$', 'delete', url(r'^/(?P<announcement_id>\d+)/delete$', 'delete',
Expand Down
4 changes: 2 additions & 2 deletions kitsune/announcements/views.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def create_for_locale(request):
a = Announcement(creator=user, locale=locale, **form.cleaned_data) a = Announcement(creator=user, locale=locale, **form.cleaned_data)
a.save() a.save()
return HttpResponse(json.dumps({'id': a.id}), return HttpResponse(json.dumps({'id': a.id}),
content_type="application/json") content_type="application/json")
else: else:
return HttpResponse(json.dumps(form.errors), status=400, return HttpResponse(json.dumps(form.errors), status=400,
content_type="application/json") content_type="application/json")




@require_POST @require_POST
Expand Down
2 changes: 1 addition & 1 deletion kitsune/customercare/admin.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TweetAdmin(admin.ModelAdmin):
class ReplyAdmin(admin.ModelAdmin): class ReplyAdmin(admin.ModelAdmin):
date_hierarchy = 'created' date_hierarchy = 'created'
list_display = ('tweet_id', 'user', 'twitter_username', '__unicode__', list_display = ('tweet_id', 'user', 'twitter_username', '__unicode__',
'created', 'locale') 'created', 'locale')
list_filter = ('locale', 'twitter_username') list_filter = ('locale', 'twitter_username')
search_fields = ('raw_json',) search_fields = ('raw_json',)
raw_id_fields = ('user',) raw_id_fields = ('user',)
Expand Down
5 changes: 3 additions & 2 deletions kitsune/customercare/cron.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def get_customercare_stats():
raw = json.loads(reply.raw_json) raw = json.loads(reply.raw_json)
user = reply.twitter_username user = reply.twitter_username
if user not in contributor_stats: if user not in contributor_stats:
if 'from_user' in raw: #For tweets collected using v1 API if 'from_user' in raw: # For tweets collected using v1 API
user_data = raw user_data = raw
else: else:
user_data = raw['user'] user_data = raw['user']
Expand All @@ -227,7 +227,8 @@ def get_customercare_stats():
limit = settings.CC_TOP_CONTRIB_LIMIT limit = settings.CC_TOP_CONTRIB_LIMIT
# Sort by whatever is in settings, break ties with 'all' # Sort by whatever is in settings, break ties with 'all'
contributor_stats = sorted(contributor_stats.values(), contributor_stats = sorted(contributor_stats.values(),
key=lambda c: (c[sort_key], c['all']), reverse=True)[:limit] key=lambda c: (c[sort_key], c['all']),
reverse=True)[:limit]


try: try:
redis = redis_client(name='default') redis = redis_client(name='default')
Expand Down
3 changes: 2 additions & 1 deletion kitsune/customercare/helpers.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ def round_percent(num):
"""Return a customercare-format percentage from a number.""" """Return a customercare-format percentage from a number."""
return round(num, 1) if num < 10 else int(round(num, 0)) return round(num, 1) if num < 10 else int(round(num, 0))



@register.filter @register.filter
def max(num, limit): def max(num, limit):
if num > limit: if num > limit:
num = limit num = limit
return num return num
3 changes: 2 additions & 1 deletion kitsune/customercare/models.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class Reply(ModelBase):
The Tweet table gets truncated regularly so we can't use it for metrics. The Tweet table gets truncated regularly so we can't use it for metrics.
This model is to keep track of contributor counts and such. This model is to keep track of contributor counts and such.
""" """
user = models.ForeignKey(User, null=True, blank=True, related_name='tweet_replies') user = models.ForeignKey(User, null=True, blank=True,
related_name='tweet_replies')
twitter_username = models.CharField(max_length=20) twitter_username = models.CharField(max_length=20)
tweet_id = models.BigIntegerField() tweet_id = models.BigIntegerField()
raw_json = models.TextField() raw_json = models.TextField()
Expand Down
2 changes: 1 addition & 1 deletion kitsune/customercare/tests/__init__.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def reply(**kwargs):
'text': kwargs.pop('text', 'Hey #Firefox'), 'text': kwargs.pop('text', 'Hey #Firefox'),
'created_at': 'Thu, 23 Sep 2010 13:58:06 +0000', 'created_at': 'Thu, 23 Sep 2010 13:58:06 +0000',
'source': '&lt;a href=&quot;http://www.tweetdeck.com&quot; ' 'source': '&lt;a href=&quot;http://www.tweetdeck.com&quot; '
'rel=&quot;nofollow&quot;&gt;TweetDeck&lt;/a&gt;', 'rel=&quot;nofollow&quot;&gt;TweetDeck&lt;/a&gt;',
'user': { 'user': {
'screen_name': '__jimcasey__', 'screen_name': '__jimcasey__',
'profile_image_url': 'http://a1.twimg.com/profile_images/' 'profile_image_url': 'http://a1.twimg.com/profile_images/'
Expand Down
1 change: 0 additions & 1 deletion kitsune/customercare/tests/test_cron.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from kitsune.sumo.tests import TestCase from kitsune.sumo.tests import TestCase





class TwitterCronTestCase(TestCase): class TwitterCronTestCase(TestCase):
tweet_template = { tweet_template = {
"profile_image_url": ( "profile_image_url": (
Expand Down
2 changes: 1 addition & 1 deletion kitsune/customercare/tests/test_templates.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_fallback_message(self):
eq_(200, r.status_code) eq_(200, r.status_code)
doc = pq(r.content) doc = pq(r.content)
assert doc('#tweets-wrap .warning-box'), ( assert doc('#tweets-wrap .warning-box'), (
'Fallback message is not showing up.') 'Fallback message is not showing up.')




class StatsTests(TestCase): class StatsTests(TestCase):
Expand Down
1 change: 0 additions & 1 deletion kitsune/customercare/tests/test_views.py
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,5 @@
from datetime import datetime, timedelta from datetime import datetime, timedelta
import json import json
import time


from django.conf import settings from django.conf import settings


Expand Down
3 changes: 2 additions & 1 deletion kitsune/customercare/urls.py
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.conf.urls import patterns, url from django.conf.urls import patterns, url




urlpatterns = patterns('kitsune.customercare.views', urlpatterns = patterns(
'kitsune.customercare.views',
url(r'^/more_tweets$', 'more_tweets', name="customercare.more_tweets"), url(r'^/more_tweets$', 'more_tweets', name="customercare.more_tweets"),
url(r'^/twitter_post$', 'twitter_post', name="customercare.twitter_post"), url(r'^/twitter_post$', 'twitter_post', name="customercare.twitter_post"),
url(r'^/hide_tweet$', 'hide_tweet', name="customercare.hide_tweet"), url(r'^/hide_tweet$', 'hide_tweet', name="customercare.hide_tweet"),
Expand Down
15 changes: 7 additions & 8 deletions kitsune/customercare/views.py
Original file line number Original file line Diff line number Diff line change
@@ -1,8 +1,7 @@
import calendar
import json import json
import logging import logging
from datetime import datetime, timedelta from datetime import datetime, timedelta
from email.utils import parsedate, formatdate from email.utils import parsedate


from django.conf import settings from django.conf import settings
from django.http import (HttpResponse, HttpResponseBadRequest, from django.http import (HttpResponse, HttpResponseBadRequest,
Expand Down Expand Up @@ -46,7 +45,7 @@ def _tweet_for_template(tweet, https=False):
else: else:
replies = None replies = None


if 'from_user' in data: #For tweets collected using v1 API if 'from_user' in data: # For tweets collected using v1 API
user_data = data user_data = data
from_user = data['from_user'] from_user = data['from_user']
else: else:
Expand Down Expand Up @@ -242,10 +241,10 @@ def twitter_post(request):
# replying to a deleted tweet. TODO: Catch integrity error and log or # replying to a deleted tweet. TODO: Catch integrity error and log or
# something. # something.
tweet = Tweet.objects.create(pk=status['id'], tweet = Tweet.objects.create(pk=status['id'],
raw_json=json.dumps(raw_tweet_data), raw_json=json.dumps(raw_tweet_data),
locale=author['lang'], locale=author['lang'],
created=created_at, created=created_at,
reply_to_id=reply_to_id) reply_to_id=reply_to_id)


# Record in our Reply table. # Record in our Reply table.
Reply.objects.create( Reply.objects.create(
Expand Down Expand Up @@ -287,7 +286,7 @@ def hide_tweet(request):
return HttpResponseNotFound(_('Invalid ID.')) return HttpResponseNotFound(_('Invalid ID.'))


if (tweet.reply_to is not None or if (tweet.reply_to is not None or
Tweet.objects.filter(reply_to=tweet).exists()): Tweet.objects.filter(reply_to=tweet).exists()):
return HttpResponseBadRequest(_('Tweets that are replies or have ' return HttpResponseBadRequest(_('Tweets that are replies or have '
'replies must not be hidden.')) 'replies must not be hidden.'))


Expand Down
16 changes: 8 additions & 8 deletions kitsune/dashboards/cron.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def update_l10n_coverage_metrics():
# % of all articles # % of all articles
all_ = rows['all'] all_ = rows['all']
try: try:
percent = 100.0 * float(all_['numerator']) / all_['denominator'] percent = 100 * float(all_['numerator']) / all_['denominator']
except ZeroDivisionError: except ZeroDivisionError:
percent = 0.0 percent = 0.0


Expand Down Expand Up @@ -253,10 +253,10 @@ def _bayes_avg(C, m, R, v):
for entry in sorted_final: for entry in sorted_final:
doc = Document.objects.get(pk=entry[0]) doc = Document.objects.get(pk=entry[0])
redis.rpush(REDIS_KEY, (u'%s::%s::%s::%s::%s::%s::%s' % redis.rpush(REDIS_KEY, (u'%s::%s::%s::%s::%s::%s::%s' %
(entry[0], # Document ID (entry[0], # Document ID
entry[1], # Total Votes entry[1], # Total Votes
entry[2], # Current Percentage entry[2], # Current Percentage
entry[3], # Difference in Percentage entry[3], # Difference in Percentage
1 - (entry[1] / max_total), # Graph Color 1 - (entry[1] / max_total), # Graph Color
doc.slug, # Document slug doc.slug, # Document slug
doc.title))) # Document title doc.title))) # Document title
Loading

0 comments on commit 1cff5af

Please sign in to comment.