Add flake8 configuration, fix flake8 complaints

This commit is contained in:
Peter Bittner 2015-09-02 23:30:04 +02:00
parent c408224e02
commit 767eb75e7d
6 changed files with 21 additions and 23 deletions

4
setup.cfg Normal file
View file

@ -0,0 +1,4 @@
[flake8]
max-line-length = 120
max-complexity = 10
exclude = build,dist,docs/conf.py,todo/migrations,*.egg-info

View file

@ -1,5 +1,5 @@
from django.contrib import admin
from todo.models import Item, User, List, Comment
from todo.models import Item, List, Comment
class ItemAdmin(admin.ModelAdmin):
@ -15,4 +15,4 @@ class CommentAdmin(admin.ModelAdmin):
admin.site.register(List)
admin.site.register(Comment, CommentAdmin)
admin.site.register(Item, ItemAdmin)
admin.site.register(Item, ItemAdmin)

View file

@ -25,9 +25,8 @@ class AddItemForm(ModelForm):
# print dir(self.fields['list'])
# print self.fields['list'].initial
self.fields['assigned_to'].queryset = User.objects.filter(groups__in=[task_list.group])
self.fields['assigned_to'].label_from_instance = lambda obj: "%s (%s)" % (
obj.get_full_name(), obj.username)
self.fields['assigned_to'].label_from_instance = \
lambda obj: "%s (%s)" % (obj.get_full_name(), obj.username)
due_date = forms.DateField(
required=False,

View file

@ -61,8 +61,7 @@ class Item(models.Model):
return self.title
def get_absolute_url(self):
return reverse('todo-task_detail',
kwargs={'task_id': self.id,})
return reverse('todo-task_detail', kwargs={'task_id': self.id, })
# Auto-set the item creation / completed date
def save(self):
@ -71,7 +70,6 @@ class Item(models.Model):
self.completed_date = datetime.datetime.now()
super(Item, self).save()
class Meta:
ordering = ["priority"]
@ -93,5 +91,3 @@ class Comment(models.Model):
def __str__(self):
return self.snippet

View file

@ -1,6 +1,5 @@
from django.conf import settings
from django.contrib.auth.models import User
from todo.models import List
class MissingSuperuserException(Exception):

View file

@ -166,15 +166,15 @@ def view_list(request, list_id=0, list_slug=None, view_completed=0):
elif list_slug == "recent-add":
# We'll assume this only includes uncompleted items to avoid confusion.
# Only show items in lists that are in groups that the current user is also in.
task_list = Item.objects.filter(list__group__in=(request.user.groups.all()), completed=0).order_by(
'-created_date')[:50]
# completed_list = Item.objects.filter(assigned_to=request.user, completed=1)
task_list = Item.objects.filter(list__group__in=(request.user.groups.all()),
completed=0).order_by('-created_date')[:50]
# completed_list = Item.objects.filter(assigned_to=request.user, completed=1)
elif list_slug == "recent-complete":
# Only show items in lists that are in groups that the current user is also in.
task_list = Item.objects.filter(list__group__in=request.user.groups.all(), completed=1).order_by(
'-completed_date')[:50]
# completed_list = Item.objects.filter(assigned_to=request.user, completed=1)
task_list = Item.objects.filter(list__group__in=request.user.groups.all(),
completed=1).order_by('-completed_date')[:50]
# completed_list = Item.objects.filter(assigned_to=request.user, completed=1)
else:
task_list = Item.objects.filter(list=list.id, completed=0)
@ -209,7 +209,8 @@ def view_list(request, list_id=0, list_slug=None, view_completed=0):
return HttpResponseRedirect(request.path)
else:
if list_slug != "mine" and list_slug != "recent-add" and list_slug != "recent-complete": # We don't allow adding a task on the "mine" view
# We don't allow adding a task on the "mine" view
if list_slug != "mine" and list_slug != "recent-add" and list_slug != "recent-complete":
form = AddItemForm(list, initial={
'assigned_to': request.user.id,
'priority': 999,
@ -308,8 +309,8 @@ def reorder_tasks(request):
newitem.save()
i = i + 1
# All views must return an httpresponse of some kind ... without this we get
# error 500s in the log even though things look peachy in the browser.
# All views must return an httpresponse of some kind ... without this we get
# error 500s in the log even though things look peachy in the browser.
return HttpResponse(status=201)
@ -368,14 +369,13 @@ def add_list(request):
"Most likely a list with the same name in the same group already exists.")
else:
if request.user.groups.all().count() == 1:
form = AddListForm(request.user, initial = {"group": request.user.groups.all()[0]})
form = AddListForm(request.user, initial={"group": request.user.groups.all()[0]})
else:
form = AddListForm(request.user)
return render_to_response('todo/add_list.html', locals(), context_instance=RequestContext(request))
@user_passes_test(check_user_allowed)
def search_post(request):
"""
@ -409,7 +409,7 @@ def search(request):
# In that case we still need found_items in a queryset so it can be "excluded" below.
found_items = Item.objects.all()
if 'inc_complete' in request.GET:
if 'inc_complete' in request.GET:
found_items = found_items.exclude(completed=True)
else: