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
=== modified file 'summit/common/admin/menuadmin.py'
--- summit/common/admin/menuadmin.py 2012-03-08 01:45:05 +0000
+++ summit/common/admin/menuadmin.py 2013-07-08 13:28:38 +0000
@@ -1,10 +1,12 @@
1from django.contrib import admin1from django.contrib import admin
2from common.models import Menu, MenuItem2from common.models import Menu, MenuItem
33
4
4class MenuItemInline(admin.TabularInline):5class MenuItemInline(admin.TabularInline):
5 model = MenuItem6 model = MenuItem
67
8
7class MenuAdmin(admin.ModelAdmin):9class MenuAdmin(admin.ModelAdmin):
8 inlines = [MenuItemInline,]10 inlines = [MenuItemInline, ]
911
10admin.site.register(Menu, MenuAdmin)12admin.site.register(Menu, MenuAdmin)
1113
=== modified file 'summit/common/context_processors.py'
--- summit/common/context_processors.py 2013-03-07 01:48:40 +0000
+++ summit/common/context_processors.py 2013-07-08 13:28:38 +0000
@@ -14,9 +14,6 @@
14# You should have received a copy of the GNU Affero General Public License14# You should have received a copy of the GNU Affero General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.15# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
17# context processors for The Summit Scheduler
18# see http://docs.djangoproject.com/en/dev/ref/settings/#setting-TEMPLATE_CONTEXT_PROCESSORS
19
20from schedule.models.summitmodel import Summit17from schedule.models.summitmodel import Summit
2118
22from django.conf import settings19from django.conf import settings
2320
=== modified file 'summit/common/forms.py'
--- summit/common/forms.py 2012-01-25 19:47:36 +0000
+++ summit/common/forms.py 2013-07-08 13:28:38 +0000
@@ -1,13 +1,13 @@
1from django.template import Context, loader1from django.template import Context, loader
2from django import forms2from django import forms
3from django.utils.translation import ugettext as _3
44
5# Taken from http://djangosnippets.org/snippets/1732/5# Taken from http://djangosnippets.org/snippets/1732/
6class RenderableMixin(object):6class RenderableMixin(object):
7 """7 """
8 Mixin to render forms from a predefined template8 Mixin to render forms from a predefined template
9 """9 """
10 10
11 @property11 @property
12 def form_class_name(self):12 def form_class_name(self):
13 return '.'.join([self.__module__, self.__class__.__name__.lower()])13 return '.'.join([self.__module__, self.__class__.__name__.lower()])
@@ -23,7 +23,12 @@
2323
24 context_dict = dict(24 context_dict = dict(
25 non_field_errors=self.non_field_errors(),25 non_field_errors=self.non_field_errors(),
26 fields=[ forms.forms.BoundField(self, field, name) for name, field in self.fields.iteritems()],26 fields=[
27 forms.forms.BoundField(
28 self,
29 field,
30 name,
31 ) for name, field in self.fields.iteritems()],
27 errors=self.errors,32 errors=self.errors,
28 data=self.data,33 data=self.data,
29 form=self,34 form=self,
3035
=== modified file 'summit/common/launchpad.py'
--- summit/common/launchpad.py 2013-02-04 23:22:10 +0000
+++ summit/common/launchpad.py 2013-07-08 13:28:38 +0000
@@ -38,7 +38,10 @@
38 html = f.read()38 html = f.read()
39 services = OpenIDServiceEndpoint().fromHTML(url, html)39 services = OpenIDServiceEndpoint().fromHTML(url, html)
40 if services is not None and len(services) > 0:40 if services is not None and len(services) > 0:
41 services[0].local_id = services[0].local_id.replace('launchpad.net', 'ubuntu.com')41 services[0].local_id = services[0].local_id.replace(
42 'launchpad.net',
43 'ubuntu.com',
44 )
42 return services[0]45 return services[0]
43 else:46 else:
44 return None47 return None
4548
=== modified file 'summit/common/management/commands/release.py'
--- summit/common/management/commands/release.py 2013-05-06 21:00:28 +0000
+++ summit/common/management/commands/release.py 2013-07-08 13:28:38 +0000
@@ -7,6 +7,7 @@
7import sys7import sys
8import os8import os
99
10
10def write_version_strings(version):11def write_version_strings(version):
11 try:12 try:
12 from bzrlib.branch import Branch13 from bzrlib.branch import Branch
@@ -25,6 +26,7 @@
25 f.close()26 f.close()
26 return (version, bzr_revno)27 return (version, bzr_revno)
2728
29
28class Command(LabelCommand):30class Command(LabelCommand):
29 help = "Prepare release of The Summit Scheduler. Please pass <version> as an argument."31 help = "Prepare release of The Summit Scheduler. Please pass <version> as an argument."
3032
3133
=== modified file 'summit/common/models.py'
--- summit/common/models.py 2012-10-02 18:07:24 +0000
+++ summit/common/models.py 2013-07-08 13:28:38 +0000
@@ -3,6 +3,7 @@
3from django.contrib.sites.models import Site3from django.contrib.sites.models import Site
4from django.contrib.sites.managers import CurrentSiteManager4from django.contrib.sites.managers import CurrentSiteManager
55
6
6class Menu(models.Model):7class Menu(models.Model):
7 name = models.CharField(max_length=100)8 name = models.CharField(max_length=100)
8 slug = models.SlugField()9 slug = models.SlugField()
@@ -19,12 +20,12 @@
19 def save(self, force_insert=False, force_update=False):20 def save(self, force_insert=False, force_update=False):
20 """21 """
21 Re-order all items from 10 upwards, at intervals of 10.22 Re-order all items from 10 upwards, at intervals of 10.
22 This makes it easy to insert new items in the middle of 23 This makes it easy to insert new items in the middle of
23 existing items without having to manually shuffle 24 existing items without having to manually shuffle
24 them all around.25 them all around.
25 """26 """
26 super(Menu, self).save(force_insert, force_update)27 super(Menu, self).save(force_insert, force_update)
27 28
28 current = 1029 current = 10
29 for item in MenuItem.objects.filter(menu=self).order_by('order'):30 for item in MenuItem.objects.filter(menu=self).order_by('order'):
30 item.order = current31 item.order = current
@@ -35,10 +36,19 @@
35class MenuItem(models.Model):36class MenuItem(models.Model):
36 menu = models.ForeignKey(Menu)37 menu = models.ForeignKey(Menu)
37 order = models.IntegerField()38 order = models.IntegerField()
38 link_url = models.CharField(max_length=100, help_text='URL or URI to the content, eg /about/ or http://foo.com/')39 link_url = models.CharField(
40 max_length=100,
41 help_text='URL or URI to the content, eg /about/ or http://foo.com/',
42 )
39 title = models.CharField(max_length=100)43 title = models.CharField(max_length=100)
40 login_required = models.BooleanField(blank=True, help_text='Should this item only be shown to authenticated users?')44 login_required = models.BooleanField(
41 anonymous_only = models.BooleanField(blank=True, help_text='Should this item only be shown to non-logged-in users?')45 blank=True,
42 46 help_text='Should this item only be shown to authenticated users?',
47 )
48 anonymous_only = models.BooleanField(
49 blank=True,
50 help_text='Should this item only be shown to non-logged-in users?',
51 )
52
43 def __unicode__(self):53 def __unicode__(self):
44 return "%s %s. %s" % (self.menu.slug, self.order, self.title)54 return "%s %s. %s" % (self.menu.slug, self.order, self.title)
4555
=== modified file 'summit/common/templatetags/menubuilder.py'
--- summit/common/templatetags/menubuilder.py 2012-10-06 01:42:35 +0000
+++ summit/common/templatetags/menubuilder.py 2013-07-08 13:28:38 +0000
@@ -4,6 +4,7 @@
44
5register = template.Library()5register = template.Library()
66
7
7def build_menu(parser, token):8def build_menu(parser, token):
8 """9 """
9 {% menu menu_name %}10 {% menu menu_name %}
@@ -11,9 +12,12 @@
11 try:12 try:
12 tag_name, menu_name = token.split_contents()13 tag_name, menu_name = token.split_contents()
13 except:14 except:
14 raise template.TemplateSyntaxError, "%r tag requires exactly one argument" % token.contents.split()[0]15 raise template.TemplateSyntaxError, (
16 "%r tag requires exactly one argument" % token.contents.split()[0]
17 )
15 return MenuObject(menu_name)18 return MenuObject(menu_name)
1619
20
17class MenuObject(template.Node):21class MenuObject(template.Node):
18 def __init__(self, menu_name):22 def __init__(self, menu_name):
19 self.menu_name = menu_name23 self.menu_name = menu_name
@@ -27,12 +31,14 @@
27 context['menuitems'] = get_items(real_menu_name, current_path, user)31 context['menuitems'] = get_items(real_menu_name, current_path, user)
28 return ''32 return ''
2933
34
30def build_sub_menu(parser, token):35def build_sub_menu(parser, token):
31 """36 """
32 {% submenu %}37 {% submenu %}
33 """38 """
34 return SubMenuObject()39 return SubMenuObject()
3540
41
36class SubMenuObject(template.Node):42class SubMenuObject(template.Node):
37 def __init__(self):43 def __init__(self):
38 pass44 pass
@@ -52,11 +58,13 @@
52 context['submenu_items'] = context['submenu'] = None58 context['submenu_items'] = context['submenu'] = None
53 return ''59 return ''
5460
61
55def get_items(menu_name, current_path, user):62def get_items(menu_name, current_path, user):
56 """63 """
57 If possible, use a cached list of items to avoid continually re-querying 64 If possible, use a cached list of items to avoid continually re-querying
58 the database.65 the database.
59 The key contains the menu name, whether the user is authenticated, and the current path.66 The key contains the menu name, whether the user is authenticated, and the
67 current path.
60 Disable caching by setting MENU_CACHE_TIME to -1.68 Disable caching by setting MENU_CACHE_TIME to -1.
61 """69 """
62 from django.conf import settings70 from django.conf import settings
@@ -64,26 +72,46 @@
64 debug = getattr(settings, 'DEBUG', False)72 debug = getattr(settings, 'DEBUG', False)
6573
66 if cache_time >= 0 and not debug:74 if cache_time >= 0 and not debug:
67 cache_key = 'django-menu-items/%s/%s/%s' % (menu_name, current_path, user.is_authenticated())75 cache_key = 'django-menu-items/%s/%s/%s' % (
76 menu_name,
77 current_path,
78 user.is_authenticated(),
79 )
68 menuitems = cache.get(cache_key, [])80 menuitems = cache.get(cache_key, [])
69 if menuitems:81 if menuitems:
70 return menuitems82 return menuitems
71 else:83 else:
72 menuitems = []84 menuitems = []
73 85
74 try:86 try:
75 menu = Menu.objects.get(slug=menu_name)87 menu = Menu.objects.get(slug=menu_name)
76 except Menu.DoesNotExist:88 except Menu.DoesNotExist:
77 return []89 return []
7890
79 for i in MenuItem.objects.filter(menu=menu).order_by('order'):91 for i in MenuItem.objects.filter(menu=menu).order_by('order'):
80 current = ( i.link_url != '/' and current_path.startswith(i.link_url)) or ( i.link_url == '/' and current_path == '/' )92 current = (
81 if menu.base_url and i.link_url == menu.base_url and current_path != i.link_url:93 i.link_url != '/' and current_path.startswith(i.link_url)
94 ) or (
95 i.link_url == '/' and current_path == '/'
96 )
97 if (
98 menu.base_url and i.link_url == menu.base_url
99 ) and (
100 current_path != i.link_url
101 ):
82 current = False102 current = False
83 show_anonymous = i.anonymous_only and user.is_anonymous()103 show_anonymous = i.anonymous_only and user.is_anonymous()
84 show_auth = i.login_required and user.is_authenticated()104 show_auth = i.login_required and user.is_authenticated()
85 if (not (i.login_required or i.anonymous_only)) or (i.login_required and show_auth) or (i.anonymous_only and show_anonymous):105 if (
86 menuitems.append({'url': i.link_url, 'title': i.title, 'current': current,})106 not (i.login_required or i.anonymous_only)
107 ) or (
108 i.login_required and show_auth
109 ) or (
110 i.anonymous_only and show_anonymous
111 ):
112 menuitems.append(
113 {'url': i.link_url, 'title': i.title, 'current': current}
114 )
87115
88 if cache_time >= 0 and not debug:116 if cache_time >= 0 and not debug:
89 cache.set(cache_key, menuitems, cache_time)117 cache.set(cache_key, menuitems, cache_time)
90118
=== modified file 'summit/common/templatetags/qrcode.py'
--- summit/common/templatetags/qrcode.py 2012-10-27 15:27:30 +0000
+++ summit/common/templatetags/qrcode.py 2013-07-08 13:28:38 +0000
@@ -1,14 +1,14 @@
1# Snippet from http://djangosnippets.org/snippets/1494/1# Snippet from http://djangosnippets.org/snippets/1494/
2# Generate QR Code image from a string with the Google charts API2# Generate QR Code image from a string with the Google charts API
3# 3#
4# http://code.google.com/intl/fr-FR/apis/chart/types.html#qrcodes4# http://code.google.com/intl/fr-FR/apis/chart/types.html#qrcodes
5# 5#
6# Exemple usage in a template6# Example usage in a template
7# 7#
8# {{ my_string|qrcode:"my alt" }}8# {{ my_string|qrcode:"my alt" }}
9# will return the image tag with9# will return the image tag with
10# 10#
11# src: http://chart.apis.google.com/chart?chs=150x150&amp;cht=qr&amp;chl=my_string&amp;choe=UTF-811# src: http://goo.gl/KyAVB
12# Author:johnnoone12# Author:johnnoone
13# Posted:May 6, 200913# Posted:May 6, 2009
14# Language:Python14# Language:Python
@@ -23,34 +23,41 @@
2323
24register = template.Library()24register = template.Library()
2525
26
26@register.filter27@register.filter
27@stringfilter28@stringfilter
28def qrcode(value, alt=None):29def qrcode(value, alt=None):
29 """30 """
30 Generate QR Code image from a string with the Google charts API31 Generate QR Code image from a string with the Google charts API
31 32
32 http://code.google.com/intl/fr-FR/apis/chart/types.html#qrcodes33 http://code.google.com/intl/fr-FR/apis/chart/types.html#qrcodes
33 34
34 Exemple usage --35 Example usage --
35 {{ my_string|qrcode:"my alt" }}36 {{ my_string|qrcode:"my alt" }}
36 37
37 <img src="http://chart.apis.google.com/chart?chs=150x150&amp;cht=qr&amp;chl=my_string&amp;choe=UTF-8" alt="my alt" />
38 """38 """
39 39
40 url = conditional_escape("http://chart.apis.google.com/chart?%s" % \40 url = conditional_escape(
41 urllib.urlencode({'chs':'150x150', 'cht':'qr', 'chl':value, 'choe':'UTF-8'}))41 "http://chart.apis.google.com/chart?%s" % urllib.urlencode(
42 {'chs': '150x150', 'cht': 'qr', 'chl': value, 'choe': 'UTF-8'}
43 )
44 )
42 alt = conditional_escape(alt or value)45 alt = conditional_escape(alt or value)
43 46
44 return mark_safe(u"""<img class="qrcode" src="%s" width="150" height="150" alt="%s" />""" % (url, alt))47 return mark_safe(
48 u"""<img class="qrcode" src="%s" width="150" height="150" alt="%s" />""" % (url, alt)
49 )
50
4551
46def build_qrhere(parser, token):52def build_qrhere(parser, token):
47 """53 """
48 {% qrhere %}54 {% qrhere %}
49 55
50 Returns an <img> with a QR Code pointing to the current URL56 Returns an <img> with a QR Code pointing to the current URL
51 """57 """
52 return QRHere()58 return QRHere()
5359
60
54class QRHere(template.Node):61class QRHere(template.Node):
55 def __init__(self):62 def __init__(self):
56 pass63 pass
@@ -59,8 +66,18 @@
59 if 'request' not in context:66 if 'request' not in context:
60 return ''67 return ''
61 current_url = '%s/%s' % (settings.SITE_ROOT, context['request'].path)68 current_url = '%s/%s' % (settings.SITE_ROOT, context['request'].path)
62 url = conditional_escape("http://chart.apis.google.com/chart?%s" % \69 url = conditional_escape(
63 urllib.urlencode({'chs':'150x150', 'cht':'qr', 'chl':current_url, 'choe':'UTF-8'}))70 "http://chart.apis.google.com/chart?%s" % urllib.urlencode(
64 return mark_safe(u"""<img class="qrcode" src="%s" width="150" height="150" />""" % url)71 {
72 'chs': '150x150',
73 'cht': 'qr',
74 'chl': current_url,
75 'choe': 'UTF-8',
76 }
77 )
78 )
79 return mark_safe(
80 u"""<img class="qrcode" src="%s" width="150" height="150" />""" % url
81 )
6582
66register.tag('qrhere', build_qrhere)83register.tag('qrhere', build_qrhere)
6784
=== modified file 'summit/common/utils.py'
--- summit/common/utils.py 2013-01-19 22:29:21 +0000
+++ summit/common/utils.py 2013-07-08 13:28:38 +0000
@@ -7,7 +7,9 @@
7 """7 """
8 value = value.lstrip('#')8 value = value.lstrip('#')
9 lv = len(value)9 lv = len(value)
10 return tuple(int(value[i:i + lv / 3], 16) for i in range(0, lv, lv / 3)) + (0.5,)10 return tuple(
11 int(value[i:i + lv / 3], 16) for i in range(0, lv, lv / 3)
12 ) + (0.5,)
1113
1214
13def redirect(to, *args, **kwargs):15def redirect(to, *args, **kwargs):
1416
=== modified file 'summit/common/views.py'
--- summit/common/views.py 2013-05-10 16:36:27 +0000
+++ summit/common/views.py 2013-07-08 13:28:38 +0000
@@ -47,9 +47,13 @@
47 return render_to_response("common/no_summit.html")47 return render_to_response("common/no_summit.html")
4848
4949
50def login_failure(request, message, status=403,50def login_failure(
51 template_name='login_failure.html',51 request,
52 exception=None):52 message,
53 status=403,
54 template_name='login_failure.html',
55 exception=None,
56):
53 """Render an error page to the user."""57 """Render an error page to the user."""
54 context = {58 context = {
55 'message': message,59 'message': message,
@@ -60,6 +64,9 @@
60 elif isinstance(exception, MissingUsernameViolation):64 elif isinstance(exception, MissingUsernameViolation):
61 context['solution'] = 'You will need to create a <a href="https://launchpad.net/people/+me">Launchpad profile</a> to use The Summit Scheduler'65 context['solution'] = 'You will need to create a <a href="https://launchpad.net/people/+me">Launchpad profile</a> to use The Summit Scheduler'
6266
63 data = render_to_string(template_name, context,67 data = render_to_string(
64 context_instance=RequestContext(request))68 template_name,
69 context,
70 context_instance=RequestContext(request),
71 )
65 return HttpResponse(data, status=status)72 return HttpResponse(data, status=status)
6673
=== modified file 'summit/common/widgets.py'
--- summit/common/widgets.py 2013-04-08 20:50:49 +0000
+++ summit/common/widgets.py 2013-07-08 13:28:38 +0000
@@ -99,9 +99,7 @@
99 """99 """
100 A more-friendly date/time widget.100 A more-friendly date/time widget.
101101
102 Inspired by:102 Inspired by: http://goo.gl/bul3W
103
104 http://copiesofcopies.org/webl/2010/04/26/a-better-datetime-widget-for-django/
105 """103 """
106 def __init__(self, attrs=None, date_format=None, time_format=None):104 def __init__(self, attrs=None, date_format=None, time_format=None):
107 super(DateTimeWidget, self).__init__(attrs, date_format, time_format)105 super(DateTimeWidget, self).__init__(attrs, date_format, time_format)

Subscribers

People subscribed via source and target branches