Fixed long lines

This commit is contained in:
2016-06-24 16:11:43 +02:00
parent 5c3c56ecc3
commit 589884c4be
5 changed files with 118 additions and 62 deletions

View File

@@ -19,15 +19,18 @@ along with TipPy. If not, see <http://www.gnu.org/licenses/>.
"""
from django.http import HttpResponse
from django.shortcuts import render_to_response, redirect, render, get_object_or_404
from django.shortcuts import render_to_response, redirect, render, \
get_object_or_404
from django.contrib.auth import authenticate, login
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from django.contrib.auth.views import password_reset, password_reset_confirm
from django.contrib.auth.views import password_reset, \
password_reset_confirm
from django.core.context_processors import csrf
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.core.paginator import Paginator, InvalidPage, EmptyPage, PageNotAnInteger
from django.core.paginator import Paginator, InvalidPage, EmptyPage, \
PageNotAnInteger
from django.utils import timezone
from django.utils.text import slugify
from django.db.models import Sum, Max
@@ -75,7 +78,9 @@ def profile(request, pk):
# If it's a HTTP POST, we're interested in processing form data.
if request.method == 'POST':
user_form = UserForm(data=request.POST, instance=user)
profile_form = UserProfileForm(data=request.POST, instance=profile)
profile_form = UserProfileForm(
data=request.POST, instance=profile
)
if user_form.is_valid() and profile_form.is_valid():
@@ -98,13 +103,18 @@ def profile(request, pk):
if 'avatar-clear' in request.POST:
if 'on' in request.POST['avatar-clear']:
image = pjoin(settings.MEDIA_ROOT, img)
debug.append('Is the image ' + str(image) + ' a regular file? ' + str(os.path.isfile(image)))
debug.append('Is the image ' + str(image)
+ ' a regular file? '
+ str(os.path.isfile(image))
)
if os.path.isfile(image):
os.remove(image)
profile.save()
for item in request.POST:
debug.append(str(item) + " -> " + str(request.POST[item]))
debug.append(str(item) + " -> "
+ str(request.POST[item])
)
# Invalid form or forms - mistakes or something else?
# Print problems to the terminal.
@@ -114,8 +124,8 @@ def profile(request, pk):
return redirect( '/accounts/profile/' + str(user.id) )
# Not a HTTP POST, so we render our form using two ModelForm instances.
# These forms will be blank, ready for user input.
# Not a HTTP POST, so we render our form using two ModelForm
# instances. These forms will be blank, ready for user input.
else:
user_form = UserForm(
initial={ 'last_name': user.last_name,
@@ -151,7 +161,8 @@ def getSeason(request, ls, season):
for match in season[0]:
m = Match(matchID=unicode(match['matchID']),
matchDateTime=datetime.strptime(unicode(match['matchDateTime']), '%Y-%m-%d %H:%M:%S'),
matchDateTime=datetime.strptime(
unicode(match['matchDateTime']), '%Y-%m-%d %H:%M:%S'),
group=int(match['groupID']),
matchday=int(match['groupOrderID']),
matchday_name=unicode(match['groupName']),
@@ -225,7 +236,8 @@ def update(request, ls, season, cur_md):
goals_total = match.pointsTeam1 + match.pointsTeam2
# Tipp is acurate
if (tipp.pointsTeam1 == match.pointsTeam1 and tipp.pointsTeam2 == match.pointsTeam2):
if (tipp.pointsTeam1 == match.pointsTeam1
and tipp.pointsTeam2 == match.pointsTeam2):
if goals_total >= 5:
score = scores.exact_high
else:
@@ -289,7 +301,8 @@ def matchday(request, ls, season, matchday, template_name='md.html'):
user = User.objects.get(username=request.user.username)
""" get mandants current user is related """
mandants = RelUserMandant.objects.filter(user=request.user).values_list('mandant', flat=True)
mandants = RelUserMandant.objects.filter(user=request.user). \
values_list('mandant', flat=True)
""" get mates """
tipp_mates = []
@@ -320,7 +333,8 @@ def matchday(request, ls, season, matchday, template_name='md.html'):
check if Tipp already exists
"""
try:
tipp = Tipp.objects.get(tipperID=user.id,matchID=match.matchID)
tipp = Tipp.objects.get(tipperID=user.id,
matchID=match.matchID)
except ObjectDoesNotExist:
tipp = None
@@ -352,13 +366,15 @@ def matchday(request, ls, season, matchday, template_name='md.html'):
if tipp is not None:
f = TippForm(prefix=str(match.matchID),
initial={'tippTeam1': tipp.pointsTeam1, 'tippTeam2': tipp.pointsTeam2}
initial={'tippTeam1': tipp.pointsTeam1,
'tippTeam2': tipp.pointsTeam2}
)
else:
f = TippForm(prefix=str(match.matchID))
item = {}
item['matchDateTime'] = (match.matchDateTime.astimezone(timezoneLocal).strftime('%a %d.%m, %H:%M'))
item['matchDateTime'] = (match.matchDateTime. \
astimezone(timezoneLocal).strftime('%a %d.%m, %H:%M'))
item['iconTeam1']= str(match.idTeam1.icon)
item['iconURLTeam1'] = str(match.idTeam1.iconURL)
@@ -375,7 +391,8 @@ def matchday(request, ls, season, matchday, template_name='md.html'):
if (match.pointsTeam1 == -1 or match.pointsTeam2 == -1):
item['matchResult'] = "-:-"
else:
item['matchResult'] = str(match.pointsTeam1) + ":" + str(match.pointsTeam2)
item['matchResult'] = str(match.pointsTeam1) + ":" \
+ str(match.pointsTeam2)
item['tippFormTeam1'] = f['tippTeam1']
item['tippFormTeam2'] = f['tippTeam2']
@@ -386,15 +403,17 @@ def matchday(request, ls, season, matchday, template_name='md.html'):
for mate in tipp_mates:
try:
matetipp = Tipp.objects.get(tipperID=mate['mate'],matchID=match.matchID)
matetipp = Tipp.objects.get(tipperID=mate['mate'],
matchID=match.matchID)
if match_started is True:
if matetipp.score is None:
score = u'\u231B'
else:
score = matetipp.score
mate['tipps'].append(str(matetipp.pointsTeam1) + ":" + str(matetipp.pointsTeam2) + \
"(" + str(score) + ")")
mate['tipps'].append(str(matetipp.pointsTeam1)
+ ":" + str(matetipp.pointsTeam2)
+ "(" + str(score) + ")")
if match.finished is True:
mate['sum_score'] += matetipp.score
else:
@@ -405,11 +424,13 @@ def matchday(request, ls, season, matchday, template_name='md.html'):
matches.append(item)
# get the newest blogposts
pm = RelPostMandant.objects.filter(mandant__in=mandants).values_list('post', flat=True)
pm = RelPostMandant.objects.filter(mandant__in=mandants). \
values_list('post', flat=True)
posts = []
for post in Post.objects.filter(id__in=pm, published=True)[:1]:
try:
avatar = UserProfile.objects.get(user_id=post.author_id).avatar.name
avatar = UserProfile.objects.get(user_id=post.author_id). \
avatar.name
except:
avatar = None
posts.append( (post, avatar) )
@@ -428,31 +449,39 @@ def matchday(request, ls, season, matchday, template_name='md.html'):
'ls': ls,
'season': season,
'username': user,
'tipp_mates': sorted(tipp_mates, key=lambda k: k['sum_score'], reverse=True),
'tipp_mates': sorted(tipp_mates, key=lambda k: k['sum_score'],
reverse=True),
'posts': posts,
'has_refresh': has_refresh
})
@login_required
def charts(request, ls, season, pos='default', template_name='charts.html'):
def charts(request, ls, season, pos='default',
template_name='charts.html'):
debug = ''
if pos == 'default':
if get_current_md(ls) < 18:
pos = 'hin'
matches = Match.objects.filter(leagueShortcut=ls, season=season, matchday__lte=17)
matches = Match.objects.filter(leagueShortcut=ls,
season=season, matchday__lte=17)
else:
pos = 'rueck'
matches = Match.objects.filter(leagueShortcut=ls, season=season, matchday__gte=18)
matches = Match.objects.filter(leagueShortcut=ls,
season=season, matchday__gte=18)
elif pos == 'hin':
matches = Match.objects.filter(leagueShortcut=ls, season=season, matchday__lte=17)
matches = Match.objects.filter(leagueShortcut=ls,
season=season, matchday__lte=17)
elif pos == 'rueck':
matches = Match.objects.filter(leagueShortcut=ls, season=season, matchday__gte=18)
matches = Match.objects.filter(leagueShortcut=ls,
season=season, matchday__gte=18)
else:
matches = Match.objects.filter(leagueShortcut=ls, season=season)
# get mandants of current user
mandants = RelUserMandant.objects.filter(user=request.user).values_list('mandant', flat=True)
mandants = RelUserMandant.objects.filter(user=request.user). \
values_list('mandant', flat=True)
# main loop
mandant_dict = {}
@@ -460,20 +489,23 @@ def charts(request, ls, season, pos='default', template_name='charts.html'):
mandant = Mandant.objects.get(id=m)
# get users
users = RelUserMandant.objects.filter(mandant=m).values_list('user', flat=True)
users = RelUserMandant.objects.filter(mandant=m). \
values_list('user', flat=True)
user_dict = {}
for userid in users:
# get user object, then fetch matches for user
user = User.objects.get(id=userid)
score = Tipp.objects.filter(matchID__in=matches, tipperID=user).aggregate(Sum('score'))
score = Tipp.objects.filter(matchID__in=matches, \
tipperID=user).aggregate(Sum('score'))
if score['score__sum'] is None:
user_dict[user.first_name] = 0
else:
user_dict[user.first_name] = score['score__sum']
mandant_dict[mandant.name] = sorted(user_dict.items(), key=lambda x: x[1], reverse=True)
mandant_dict[mandant.name] = sorted(user_dict.items(),
key=lambda x: x[1], reverse=True)
return render(request, template_name, {
#'debug': debug,
@@ -487,13 +519,16 @@ def charts(request, ls, season, pos='default', template_name='charts.html'):
def blogindex(request, page):
# get the blog posts that are published
# and related to mandant
mandants = RelUserMandant.objects.filter(user=request.user).values_list('mandant', flat=True)
posts = RelPostMandant.objects.filter(mandant__in=mandants).values_list('post', flat=True)
mandants = RelUserMandant.objects.filter(user=request.user). \
values_list('mandant', flat=True)
posts = RelPostMandant.objects.filter(mandant__in=mandants). \
values_list('post', flat=True)
post_list = []
for post in Post.objects.filter(published=True, id__in=posts):
try:
avatar = UserProfile.objects.get(user_id=post.author_id).avatar.name
avatar = UserProfile.objects.get(user_id=post.author_id). \
avatar.name
except:
avatar = None
post_list.append( (post, avatar) )
@@ -519,7 +554,8 @@ def newBlogpost(request):
debug = ''
has_mandant = False
mandants = RelUserMandant.objects.filter(user=request.user).values_list('mandant', flat=True)
mandants = RelUserMandant.objects.filter(user=request.user). \
values_list('mandant', flat=True)
choices = []
if mandants.count > 1:
has_mandant = True
@@ -541,10 +577,12 @@ def newBlogpost(request):
data = form_mandant.cleaned_data
for m in data['mandants']:
debug += str(m) + " "
m = RelPostMandant(post=p, mandant=Mandant.objects.get(name=m))
m = RelPostMandant(post=p,
mandant=Mandant.objects.get(name=m))
m.save()
else:
m = RelPostMandant(post=p, mandant=Mandant.objects.get(id=mandants[0]))
m = RelPostMandant(post=p,
mandant=Mandant.objects.get(id=mandants[0]))
m.save()
return redirect( '/blog/1')