Merge lp:~cjohnston/summit/flake8-common into lp:summit

Proposed by Chris Johnston
Status: Needs review
Proposed branch: lp:~cjohnston/summit/flake8-common
Merge into: lp:summit
Diff against target: 426 lines (+124/-53)
11 files modified
summit/common/admin/menuadmin.py (+3/-1)
summit/common/context_processors.py (+0/-3)
summit/common/forms.py (+8/-3)
summit/common/launchpad.py (+4/-1)
summit/common/management/commands/release.py (+2/-0)
summit/common/models.py (+17/-7)
summit/common/templatetags/menubuilder.py (+37/-9)
summit/common/templatetags/qrcode.py (+37/-20)
summit/common/utils.py (+3/-1)
summit/common/views.py (+12/-5)
summit/common/widgets.py (+1/-3)
To merge this branch: bzr merge lp:~cjohnston/summit/flake8-common
Reviewer Review Type Date Requested Status
Summit Hackers Pending
Review via email: mp+173496@code.launchpad.net

Commit message

Just some flake8 fixes for summit

To post a comment you must log in.

Unmerged revisions

555. By Chris Johnston <email address hidden>

Flake8 fixes for common

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'summit/common/admin/menuadmin.py'
2--- summit/common/admin/menuadmin.py 2012-03-08 01:45:05 +0000
3+++ summit/common/admin/menuadmin.py 2013-07-08 13:28:38 +0000
4@@ -1,10 +1,12 @@
5 from django.contrib import admin
6 from common.models import Menu, MenuItem
7
8+
9 class MenuItemInline(admin.TabularInline):
10 model = MenuItem
11
12+
13 class MenuAdmin(admin.ModelAdmin):
14- inlines = [MenuItemInline,]
15+ inlines = [MenuItemInline, ]
16
17 admin.site.register(Menu, MenuAdmin)
18
19=== modified file 'summit/common/context_processors.py'
20--- summit/common/context_processors.py 2013-03-07 01:48:40 +0000
21+++ summit/common/context_processors.py 2013-07-08 13:28:38 +0000
22@@ -14,9 +14,6 @@
23 # You should have received a copy of the GNU Affero General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25
26-# context processors for The Summit Scheduler
27-# see http://docs.djangoproject.com/en/dev/ref/settings/#setting-TEMPLATE_CONTEXT_PROCESSORS
28-
29 from schedule.models.summitmodel import Summit
30
31 from django.conf import settings
32
33=== modified file 'summit/common/forms.py'
34--- summit/common/forms.py 2012-01-25 19:47:36 +0000
35+++ summit/common/forms.py 2013-07-08 13:28:38 +0000
36@@ -1,13 +1,13 @@
37 from django.template import Context, loader
38 from django import forms
39-from django.utils.translation import ugettext as _
40+
41
42 # Taken from http://djangosnippets.org/snippets/1732/
43 class RenderableMixin(object):
44 """
45 Mixin to render forms from a predefined template
46 """
47-
48+
49 @property
50 def form_class_name(self):
51 return '.'.join([self.__module__, self.__class__.__name__.lower()])
52@@ -23,7 +23,12 @@
53
54 context_dict = dict(
55 non_field_errors=self.non_field_errors(),
56- fields=[ forms.forms.BoundField(self, field, name) for name, field in self.fields.iteritems()],
57+ fields=[
58+ forms.forms.BoundField(
59+ self,
60+ field,
61+ name,
62+ ) for name, field in self.fields.iteritems()],
63 errors=self.errors,
64 data=self.data,
65 form=self,
66
67=== modified file 'summit/common/launchpad.py'
68--- summit/common/launchpad.py 2013-02-04 23:22:10 +0000
69+++ summit/common/launchpad.py 2013-07-08 13:28:38 +0000
70@@ -38,7 +38,10 @@
71 html = f.read()
72 services = OpenIDServiceEndpoint().fromHTML(url, html)
73 if services is not None and len(services) > 0:
74- services[0].local_id = services[0].local_id.replace('launchpad.net', 'ubuntu.com')
75+ services[0].local_id = services[0].local_id.replace(
76+ 'launchpad.net',
77+ 'ubuntu.com',
78+ )
79 return services[0]
80 else:
81 return None
82
83=== modified file 'summit/common/management/commands/release.py'
84--- summit/common/management/commands/release.py 2013-05-06 21:00:28 +0000
85+++ summit/common/management/commands/release.py 2013-07-08 13:28:38 +0000
86@@ -7,6 +7,7 @@
87 import sys
88 import os
89
90+
91 def write_version_strings(version):
92 try:
93 from bzrlib.branch import Branch
94@@ -25,6 +26,7 @@
95 f.close()
96 return (version, bzr_revno)
97
98+
99 class Command(LabelCommand):
100 help = "Prepare release of The Summit Scheduler. Please pass <version> as an argument."
101
102
103=== modified file 'summit/common/models.py'
104--- summit/common/models.py 2012-10-02 18:07:24 +0000
105+++ summit/common/models.py 2013-07-08 13:28:38 +0000
106@@ -3,6 +3,7 @@
107 from django.contrib.sites.models import Site
108 from django.contrib.sites.managers import CurrentSiteManager
109
110+
111 class Menu(models.Model):
112 name = models.CharField(max_length=100)
113 slug = models.SlugField()
114@@ -19,12 +20,12 @@
115 def save(self, force_insert=False, force_update=False):
116 """
117 Re-order all items from 10 upwards, at intervals of 10.
118- This makes it easy to insert new items in the middle of
119- existing items without having to manually shuffle
120+ This makes it easy to insert new items in the middle of
121+ existing items without having to manually shuffle
122 them all around.
123 """
124 super(Menu, self).save(force_insert, force_update)
125-
126+
127 current = 10
128 for item in MenuItem.objects.filter(menu=self).order_by('order'):
129 item.order = current
130@@ -35,10 +36,19 @@
131 class MenuItem(models.Model):
132 menu = models.ForeignKey(Menu)
133 order = models.IntegerField()
134- link_url = models.CharField(max_length=100, help_text='URL or URI to the content, eg /about/ or http://foo.com/')
135+ link_url = models.CharField(
136+ max_length=100,
137+ help_text='URL or URI to the content, eg /about/ or http://foo.com/',
138+ )
139 title = models.CharField(max_length=100)
140- login_required = models.BooleanField(blank=True, help_text='Should this item only be shown to authenticated users?')
141- anonymous_only = models.BooleanField(blank=True, help_text='Should this item only be shown to non-logged-in users?')
142-
143+ login_required = models.BooleanField(
144+ blank=True,
145+ help_text='Should this item only be shown to authenticated users?',
146+ )
147+ anonymous_only = models.BooleanField(
148+ blank=True,
149+ help_text='Should this item only be shown to non-logged-in users?',
150+ )
151+
152 def __unicode__(self):
153 return "%s %s. %s" % (self.menu.slug, self.order, self.title)
154
155=== modified file 'summit/common/templatetags/menubuilder.py'
156--- summit/common/templatetags/menubuilder.py 2012-10-06 01:42:35 +0000
157+++ summit/common/templatetags/menubuilder.py 2013-07-08 13:28:38 +0000
158@@ -4,6 +4,7 @@
159
160 register = template.Library()
161
162+
163 def build_menu(parser, token):
164 """
165 {% menu menu_name %}
166@@ -11,9 +12,12 @@
167 try:
168 tag_name, menu_name = token.split_contents()
169 except:
170- raise template.TemplateSyntaxError, "%r tag requires exactly one argument" % token.contents.split()[0]
171+ raise template.TemplateSyntaxError, (
172+ "%r tag requires exactly one argument" % token.contents.split()[0]
173+ )
174 return MenuObject(menu_name)
175
176+
177 class MenuObject(template.Node):
178 def __init__(self, menu_name):
179 self.menu_name = menu_name
180@@ -27,12 +31,14 @@
181 context['menuitems'] = get_items(real_menu_name, current_path, user)
182 return ''
183
184+
185 def build_sub_menu(parser, token):
186 """
187 {% submenu %}
188 """
189 return SubMenuObject()
190
191+
192 class SubMenuObject(template.Node):
193 def __init__(self):
194 pass
195@@ -52,11 +58,13 @@
196 context['submenu_items'] = context['submenu'] = None
197 return ''
198
199+
200 def get_items(menu_name, current_path, user):
201 """
202- If possible, use a cached list of items to avoid continually re-querying
203+ If possible, use a cached list of items to avoid continually re-querying
204 the database.
205- The key contains the menu name, whether the user is authenticated, and the current path.
206+ The key contains the menu name, whether the user is authenticated, and the
207+ current path.
208 Disable caching by setting MENU_CACHE_TIME to -1.
209 """
210 from django.conf import settings
211@@ -64,26 +72,46 @@
212 debug = getattr(settings, 'DEBUG', False)
213
214 if cache_time >= 0 and not debug:
215- cache_key = 'django-menu-items/%s/%s/%s' % (menu_name, current_path, user.is_authenticated())
216+ cache_key = 'django-menu-items/%s/%s/%s' % (
217+ menu_name,
218+ current_path,
219+ user.is_authenticated(),
220+ )
221 menuitems = cache.get(cache_key, [])
222 if menuitems:
223 return menuitems
224 else:
225 menuitems = []
226-
227+
228 try:
229 menu = Menu.objects.get(slug=menu_name)
230 except Menu.DoesNotExist:
231 return []
232
233 for i in MenuItem.objects.filter(menu=menu).order_by('order'):
234- current = ( i.link_url != '/' and current_path.startswith(i.link_url)) or ( i.link_url == '/' and current_path == '/' )
235- if menu.base_url and i.link_url == menu.base_url and current_path != i.link_url:
236+ current = (
237+ i.link_url != '/' and current_path.startswith(i.link_url)
238+ ) or (
239+ i.link_url == '/' and current_path == '/'
240+ )
241+ if (
242+ menu.base_url and i.link_url == menu.base_url
243+ ) and (
244+ current_path != i.link_url
245+ ):
246 current = False
247 show_anonymous = i.anonymous_only and user.is_anonymous()
248 show_auth = i.login_required and user.is_authenticated()
249- if (not (i.login_required or i.anonymous_only)) or (i.login_required and show_auth) or (i.anonymous_only and show_anonymous):
250- menuitems.append({'url': i.link_url, 'title': i.title, 'current': current,})
251+ if (
252+ not (i.login_required or i.anonymous_only)
253+ ) or (
254+ i.login_required and show_auth
255+ ) or (
256+ i.anonymous_only and show_anonymous
257+ ):
258+ menuitems.append(
259+ {'url': i.link_url, 'title': i.title, 'current': current}
260+ )
261
262 if cache_time >= 0 and not debug:
263 cache.set(cache_key, menuitems, cache_time)
264
265=== modified file 'summit/common/templatetags/qrcode.py'
266--- summit/common/templatetags/qrcode.py 2012-10-27 15:27:30 +0000
267+++ summit/common/templatetags/qrcode.py 2013-07-08 13:28:38 +0000
268@@ -1,14 +1,14 @@
269 # Snippet from http://djangosnippets.org/snippets/1494/
270 # Generate QR Code image from a string with the Google charts API
271-#
272+#
273 # http://code.google.com/intl/fr-FR/apis/chart/types.html#qrcodes
274-#
275-# Exemple usage in a template
276-#
277+#
278+# Example usage in a template
279+#
280 # {{ my_string|qrcode:"my alt" }}
281 # will return the image tag with
282-#
283-# src: http://chart.apis.google.com/chart?chs=150x150&amp;cht=qr&amp;chl=my_string&amp;choe=UTF-8
284+#
285+# src: http://goo.gl/KyAVB
286 # Author:johnnoone
287 # Posted:May 6, 2009
288 # Language:Python
289@@ -23,34 +23,41 @@
290
291 register = template.Library()
292
293+
294 @register.filter
295 @stringfilter
296 def qrcode(value, alt=None):
297 """
298 Generate QR Code image from a string with the Google charts API
299-
300+
301 http://code.google.com/intl/fr-FR/apis/chart/types.html#qrcodes
302-
303- Exemple usage --
304+
305+ Example usage --
306 {{ my_string|qrcode:"my alt" }}
307-
308- <img src="http://chart.apis.google.com/chart?chs=150x150&amp;cht=qr&amp;chl=my_string&amp;choe=UTF-8" alt="my alt" />
309+
310 """
311-
312- url = conditional_escape("http://chart.apis.google.com/chart?%s" % \
313- urllib.urlencode({'chs':'150x150', 'cht':'qr', 'chl':value, 'choe':'UTF-8'}))
314+
315+ url = conditional_escape(
316+ "http://chart.apis.google.com/chart?%s" % urllib.urlencode(
317+ {'chs': '150x150', 'cht': 'qr', 'chl': value, 'choe': 'UTF-8'}
318+ )
319+ )
320 alt = conditional_escape(alt or value)
321-
322- return mark_safe(u"""<img class="qrcode" src="%s" width="150" height="150" alt="%s" />""" % (url, alt))
323+
324+ return mark_safe(
325+ u"""<img class="qrcode" src="%s" width="150" height="150" alt="%s" />""" % (url, alt)
326+ )
327+
328
329 def build_qrhere(parser, token):
330 """
331 {% qrhere %}
332-
333+
334 Returns an <img> with a QR Code pointing to the current URL
335 """
336 return QRHere()
337
338+
339 class QRHere(template.Node):
340 def __init__(self):
341 pass
342@@ -59,8 +66,18 @@
343 if 'request' not in context:
344 return ''
345 current_url = '%s/%s' % (settings.SITE_ROOT, context['request'].path)
346- url = conditional_escape("http://chart.apis.google.com/chart?%s" % \
347- urllib.urlencode({'chs':'150x150', 'cht':'qr', 'chl':current_url, 'choe':'UTF-8'}))
348- return mark_safe(u"""<img class="qrcode" src="%s" width="150" height="150" />""" % url)
349+ url = conditional_escape(
350+ "http://chart.apis.google.com/chart?%s" % urllib.urlencode(
351+ {
352+ 'chs': '150x150',
353+ 'cht': 'qr',
354+ 'chl': current_url,
355+ 'choe': 'UTF-8',
356+ }
357+ )
358+ )
359+ return mark_safe(
360+ u"""<img class="qrcode" src="%s" width="150" height="150" />""" % url
361+ )
362
363 register.tag('qrhere', build_qrhere)
364
365=== modified file 'summit/common/utils.py'
366--- summit/common/utils.py 2013-01-19 22:29:21 +0000
367+++ summit/common/utils.py 2013-07-08 13:28:38 +0000
368@@ -7,7 +7,9 @@
369 """
370 value = value.lstrip('#')
371 lv = len(value)
372- return tuple(int(value[i:i + lv / 3], 16) for i in range(0, lv, lv / 3)) + (0.5,)
373+ return tuple(
374+ int(value[i:i + lv / 3], 16) for i in range(0, lv, lv / 3)
375+ ) + (0.5,)
376
377
378 def redirect(to, *args, **kwargs):
379
380=== modified file 'summit/common/views.py'
381--- summit/common/views.py 2013-05-10 16:36:27 +0000
382+++ summit/common/views.py 2013-07-08 13:28:38 +0000
383@@ -47,9 +47,13 @@
384 return render_to_response("common/no_summit.html")
385
386
387-def login_failure(request, message, status=403,
388- template_name='login_failure.html',
389- exception=None):
390+def login_failure(
391+ request,
392+ message,
393+ status=403,
394+ template_name='login_failure.html',
395+ exception=None,
396+):
397 """Render an error page to the user."""
398 context = {
399 'message': message,
400@@ -60,6 +64,9 @@
401 elif isinstance(exception, MissingUsernameViolation):
402 context['solution'] = 'You will need to create a <a href="https://launchpad.net/people/+me">Launchpad profile</a> to use The Summit Scheduler'
403
404- data = render_to_string(template_name, context,
405- context_instance=RequestContext(request))
406+ data = render_to_string(
407+ template_name,
408+ context,
409+ context_instance=RequestContext(request),
410+ )
411 return HttpResponse(data, status=status)
412
413=== modified file 'summit/common/widgets.py'
414--- summit/common/widgets.py 2013-04-08 20:50:49 +0000
415+++ summit/common/widgets.py 2013-07-08 13:28:38 +0000
416@@ -99,9 +99,7 @@
417 """
418 A more-friendly date/time widget.
419
420- Inspired by:
421-
422- http://copiesofcopies.org/webl/2010/04/26/a-better-datetime-widget-for-django/
423+ Inspired by: http://goo.gl/bul3W
424 """
425 def __init__(self, attrs=None, date_format=None, time_format=None):
426 super(DateTimeWidget, self).__init__(attrs, date_format, time_format)

Subscribers

People subscribed via source and target branches