def details(request, home_team, away_team, match_id, show_full=None): try: match = Matches.objects.get(pk=match_id) league = Leagues.objects.get(pk=match.league.id) squads = MatchSquad.objects.filter(match=match) except: raise Http404 if match.status == "o": return render_to_response('matches/details_before.html', { 'match': match, 'league_table': league_table.render(league.id, match.home_team_id, match.away_team_id), 'squads': squads, 'last5_home': last_matches.render_team(match.home_team.id, 5, True), 'last5_away': last_matches.render_team(match.away_team.id, 5, True), 'menu': menu.render(request, 'matches', 'details', {'match_id': match_id}, True), }, context_instance=RequestContext(request)) else: template = 'matches/details.html' if show_full == "images": template = 'matches/show_images.html' elif show_full == "videos": template = 'matches/show_videos.html' elif show_full == "comments": template = 'matches/show_comments.html' elif show_full == "analysis": template = 'matches/show_analysis.html' return render_to_response(template, { 'match': match, 'squads': squads, 'menu': menu.render(request, 'matches', 'details', {'match_id': match_id}, True), }, context_instance=RequestContext(request))
def add_videos(request, match_id): class UploadVideoLinkForm(forms.Form): name = forms.CharField(required=False, max_length=255, widget=forms.widgets.TextInput({'size': 40, 'style': 'font-size: 20pt;'})) description = forms.CharField(required=False, widget=forms.widgets.Textarea( attrs={'rows': 3, 'cols': 5, 'style': 'font-size: 13pt;'})) link = forms.RegexField(regex=".*", max_length=1000, required=True, widget=forms.widgets.Textarea(attrs={'rows': 4, 'cols': 20})) # to regex field if request.POST: form = UploadVideoLinkForm(request.POST) post = request.POST.copy() if form.is_valid(): vid = Videos(content=post["link"], name=post["name"], description=post["description"], dst="match", dst_id=match_id, user=request.user, ip=request.META['REMOTE_ADDR'], browser=request.META['HTTP_USER_AGENT']) vid.save() try: match = Matches.objects.get(pk=match_id) except: raise Http404 return render_to_response('matches/added_video.html', { 'match': match, 'menu': menu.render(request, 'matches', 'add_videos', {'match_id': match_id}, True) }, context_instance=RequestContext(request)) else: try: match = Matches.objects.get(pk=match_id) except: raise Http404 return render_to_response('matches/add_videos.html', { 'form': form, 'match': match, 'menu': menu.render(request, 'matches', 'add_videos', {'match_id': match_id}, True), }, context_instance=RequestContext(request)) form = UploadVideoLinkForm() try: match = Matches.objects.get(pk=match_id) except: raise Http404 return render_to_response('matches/add_videos.html', { 'form': form, 'match': match, 'menu': menu.render(request, 'matches', 'add_videos', {'match_id': match_id}, True), }, context_instance=RequestContext(request))
def details_picks(request, username, range): weekdays = (_('Sa'), _('Su'), _('Mo'), _('Tu'), _('We'), _('Th'), _('Fr')) months = ( _('January'), _('February'), _('March'), _('April'), _('May'), _('June'), _('July'), _('August'), _('September'), _('October'), _('November'), _('December')) # caching if username == request.user or (not request.user.is_anonymous() and request.user.is_staff): key = "username_%s_picks_%s_all_lang_%s" % (username, range, settings.LANGUAGE_CODE) else: key = "username_%s_picks_%s_lang_%s" % (username, range, settings.LANGUAGE_CODE) # c = cache.get(key) # if c is not None: # return HttpResponse(c) try: user = User.objects.get(username=username) except: raise Http404 condition = "" if range == "all" and (user == request.user or (not request.user.is_anonymous() and request.user.is_staff)): condition = "AND m.status IN ('f', 'd', 'o')" elif range == "all": condition = "AND p.is_calculated = 1 AND m.status IN ('f')" elif range == "archive": condition = "AND p.is_calculated = 1 AND m.status IN ('f')" elif range == "pending" and (user == request.user or (not request.user.is_anonymous() and request.user.is_staff)): condition = "AND p.is_calculated = 0 AND m.status IN ('f', 'd', 'o')" if request.GET.has_key('date'): selected_date = request.GET['date'].split('-') picks = Picks().get_user_picks(user.id, condition=condition, date=datetime.date(*strptime(request.GET['date'], "%Y-%m-%d")[0:3])) else: selected_date = ('a', 'b', 'c') picks = Picks().get_user_picks(user.id, condition=condition) # rozne menu w zaleznosci gdzie jestesmy if str(request.user) == str(username): who = 'user' else: who = 'users' ret = render_to_string("accounts/details_picks.html", { 'selected_date': selected_date, 'range': range, 'show_user': user, 'picks': picks, 'menu': menu.render(request, who, 'details_picks', {'username': username}, False), 'weekdays': weekdays, 'months': months, }, context_instance=RequestContext(request)), cache.set(key, ret) return HttpResponse(ret)
def details(request, team_name, season="2007-2008"): team = get_object_or_404(Teams, name_en_url=team_name) # season = get_object_or_404(Seasons, url=season) return render_to_response("teams/details.html", { 'team': team, 'teams_news': related_news.render_team(team.id), 'team_news_most_popular': related_news.most_popular_team(team.id), 'league_table': league_table.render(team.current_league_id, team.id), 'results': last_matches.render_team(team.id), 'live_fixtures': render_live_fixtures(team_id=team.id), 'menu': menu.render(request, 'index', 'index', {}, True)}, RequestContext(request, {}))
def teams_list(request, country_name, league_name, season="2007-2008"): league_id = helpers.reveal_league_name(league_name) league = Leagues.objects.get(pk=league_id) teams = Teams.objects.filter(current_league_id=league_id).order_by('name_en') return render_to_response("teams/teams_list.html", { 'league': league, 'teams': teams, 'league_table': league_table.render(league_id), 'league_news': related_news.render_league(league_id), 'league_news_most_popular': related_news.most_popular_league(league_id), 'results': render_results(league_id=league_id), 'live_fixtures': render_live_fixtures(league_id=league_id), 'menu': menu.render(request, 'index', 'index', {}, True)}, RequestContext(request, {}))
def add_photos(request, match_id, step=None): if not step: step = "step_1" try: match = Matches.objects.get(pk=match_id) except: raise Http404 if request.POST: post = request.POST.copy() template = "matches/add_images.html" if post.has_key('how'): step = "step_2" template = "matches/add_images_%s.html" % post["how"] if post.has_key('photo_url_1'): # process images for i in range(1, 21): img = post["photo_url_" + str(i)] url_upload(img, match_id, request.user) template = "matches/added_images.html" return render_to_response(template, { 'match': match, 'photos_count': range(1, 21), 'step': step, 'menu': menu.render(request, 'matches', 'add_photos', {'match_id': match_id}, True), }, context_instance=RequestContext(request)) return render_to_response('matches/add_images.html', { 'match': match, 'photos_count': range(1, 21), 'step': step, 'menu': menu.render(request, 'matches', 'add_photos', {'match_id': match_id}, True), }, context_instance=RequestContext(request))
def show_users(request, letter=None): """display all users available to see by current user""" if not letter: letter = "a" users = Accounts.objects.filter(user__username__istartswith=letter, user__is_active=1).select_related().order_by( '-points') alphabet = ( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z') return render_to_response("accounts/show_users.html", { 'users': users, 'alphabet': alphabet, 'letter': letter, 'menu': menu.render(request, 'users', 'index', {}, True), }, context_instance=RequestContext(request))
def details_compare(request, username, other_username): # caching key = "username_%s_stats_lang_%s" % (username, settings.LANGUAGE_CODE) c = cache.get(key) if c is not None: return HttpResponse(c) stats = UsersTable.objects.filter(username=username, table_type='o', league_id=0) ret = render_to_string("accounts/details_stats.html", { 'stats': stats, 'menu': menu.render(request, 'user', 'details_stats', {}, True), }, context_instance=RequestContext(request)), cache.set(key, ret) return HttpResponse(ret)
def details(request, news_id, show_full=None): """Gets specified news""" news = get_object_or_404(News, pk=news_id) if not news.is_accepted and not request.user.is_authenticated(): return HttpResponseRedirect("/news/") elif not news.is_accepted and request.user.is_authenticated() and not request.user.is_staff: return HttpResponseRedirect("/news/") else: # increment counter for non-staff if request.user.is_authenticated() and request.user.is_staff == 0: news.view_count += 1 news.save() template = 'news/details.html' return render_to_response(template, { 'news': news, 'menu': menu.render(request, 'news', 'index', {'today': news.published_at.date()}, False), }, context_instance=RequestContext(request))
def index(request, country_name=False, league_name=False, news_date=None, page_no=1, search_query=None): """Main NEWS page""" try: page_no = int(page_no) except: page_no = 1 if request.POST.has_key('search_query'): if len(request.POST['search_query']) > 3: return HttpResponseRedirect("/news/%s/%s/" % (_('szukaj'), request.POST['search_query'])) else: return HttpResponseRedirect('/news/') # get news if search_query is not None: search_query = search_query news = News.objects.filter(Q(caption__search=search_query) | Q(short_content__search=search_query)).filter( is_accepted=1, is_deleted=0, is_temp=0, lang=settings.LANGUAGE_CODE).order_by('-published_at') else: search_query = '' news = News().get_news(country_name=country_name, league_name=league_name, news_date=news_date, page_no=page_no, slice_for_me=False) news_count = news.count() news = news[(page_no * settings.PER_PAGE) - settings.PER_PAGE:settings.PER_PAGE * page_no] return render_to_response('news/index.html', { 'news': news, 'page_no': page_no, 'pages': int(math.ceil(news_count / settings.PER_PAGE)) + 1, 'league_name': league_name, 'news_date': news_date, 'news_count': news_count, 'menu': menu.render(request, 'news', 'index', {'today': news_date, 'league_name': league_name}, False), 'search_query': search_query, }, context_instance=RequestContext(request))
def details_stats(request, username): # caching key = "username_%s_stats_lang_%s" % (username, settings.LANGUAGE_CODE) c = cache.get(key) if c is not None: return HttpResponse(c) user = Accounts().get_profile(username) stats = UsersTable.objects.filter(username=username, table_type='o', league_id=0) # rozne menu w zaleznosci gdzie jestesmy if str(request.user) == str(username): who = 'user' else: who = 'users' ret = render_to_string("accounts/details_stats.html", { 'user': user, 'stats': stats, 'menu': menu.render(request, who, 'details_stats', {'username': username}, False), }, context_instance=RequestContext(request)), cache.set(key, ret) return HttpResponse(ret)
def index(request, country_name=None, league_name=None, status_name=None, match_date=None): only_todays = True only_future = False matches = Matches.objects picks = Picks.objects.filter(user=request.user).select_related() if match_date: matches = matches.filter(match_date=match_date) if league_name: league_id = helpers.reveal_league_name(league_name) matches = matches.filter(league__id=league_id, status__in=['o', 'f', 'd']) else: if league_name: league_id = helpers.reveal_league_name(league_name) matches = matches.filter(league__id=league_id, status__in=['o', 'f', 'd']) today_matches = matches.filter(match_date=datetime.date.today()) count = today_matches.count() if count <= 5: matches = matches.filter(match_date__gte=datetime.date.today()) only_todays = False if count == 0: only_future = True else: only_todays = True matches = today_matches if status_name: status = helpers.reveal_status_name(status_name) if status: matches = matches.filter(status=status) if league_name: league_id = helpers.reveal_league_name(league_name) league_name2 = league_name.replace("-", " ") if not match_date: matches = matches.order_by("match_date", "match_time")[:12] return render_to_response('matches/index_with_table.html', { 'matches': matches, 'picks': picks, 'status_name': status_name, 'league_name': league_name, 'league_name2': league_name2, 'match_date': match_date, 'league_table': league_table.render(league_id), 'menu': menu.render(request, 'matches', 'index', {'status_name': status_name, 'league_name': league_name}, False), }, context_instance=RequestContext(request)) matches = matches.filter(status__in=['o', 'f', 'd']) if match_date: matches = matches.order_by("league", "match_date", "match_time") else: if not only_todays: matches = matches.order_by("match_date", "league", "match_time")[:20] else: matches = matches.order_by("match_date", "league", "match_time") return render_to_response('matches/index.html', { 'matches': matches, 'picks': picks, 'status_name': status_name, 'league_name': league_name, 'match_date': match_date, 'only_todays': only_todays, 'only_future': only_future, 'menu': menu.render(request, 'matches', 'index', {'status_name': status_name, 'league_name': league_name, 'today': match_date}, False), }, context_instance=RequestContext(request))
def details_activity(request, username): # caching key = "username_%s_activity_lang_%s" % (username, settings.LANGUAGE_CODE) c = cache.get(key) if c is not None: return HttpResponse(c) user = Accounts().get_profile(username) # --- TROFEA --- sql = """ SELECT t.points, t.name_en, t.name_pl, at.date FROM accounts_trophies as at LEFT JOIN trophies as t ON t.id = at.trophy_id WHERE at.username = '******' """ % str(username) logging.debug(sql) cursor = connection.cursor() cursor.execute(sql) trophies = [] trophies_points = 0 for row in cursor.fetchall(): trophies_points += int(row[0]) t = Trophies(points=row[0], name_en=row[1], name_pl=row[2]) t.date = row[3] trophies.append(t) # --- NEWSY --- sql = """ SELECT aa.points, n.id, n.caption, n.url, n.published_at FROM accounts_activity as aa LEFT JOIN news as n ON n.id = aa.dst_id WHERE aa.is_calculated = 1 AND aa.action_type = 'news' AND aa.username = '******' ORDER BY n.published_at DESC """ % str(username) logging.debug(sql) cursor = connection.cursor() cursor.execute(sql) news = [] news_points = 0 for row in cursor.fetchall(): news_points += int(row[0]) n = News(id=row[1], caption=row[2], url=row[3], published_at=row[4]) n.points = row[0] news.append(n) # --- ZDJECIA --- sql = """ SELECT aa.points, i.id, i.name, i.link, i.created_at FROM accounts_activity as aa LEFT JOIN images as i ON i.id = aa.dst_id WHERE aa.is_calculated = 1 AND (aa.action_type = 'news_image' OR aa.action_type = 'match_image') AND aa.username = '******' ORDER BY i.created_at DESC """ % str(username) logging.debug(sql) cursor = connection.cursor() cursor.execute(sql) images = [] images_points = 0 for row in cursor.fetchall(): images_points += int(row[0]) i = Images(id=row[1], name=row[2], link=row[3], created_at=row[4]) i.points = row[0] images.append(i) # --- FILMY --- sql = """ SELECT aa.points, v.id, v.name, v.content, v.created_at FROM accounts_activity as aa LEFT JOIN videos as v ON v.id = aa.dst_id WHERE aa.is_calculated = 1 AND (aa.action_type = 'news_video' OR aa.action_type = 'match_video') AND aa.username = '******' ORDER BY v.created_at DESC """ % str(username) logging.debug(sql) cursor = connection.cursor() cursor.execute(sql) videos = [] videos_points = 0 for row in cursor.fetchall(): videos_points += int(row[0]) v = Videos(id=row[1], name=row[2], content=row[3], created_at=row[4]) v.points = row[0] videos.append(v) # --- PICKS --- sql = """ SELECT SUM(aa.points), COUNT(*) FROM accounts_activity as aa WHERE aa.is_calculated = 1 AND aa.action_type = 'match_points' AND aa.username = '******' ORDER BY aa.dst_id """ % str(username) logging.debug(sql) cursor = connection.cursor() cursor.execute(sql) row = cursor.fetchone() if row is not None and row[0] is not None: picks_points = row[0] picks_count = row[1] else: picks_points = 0 picks_count = 0 # rozne menu w zaleznosci gdzie jestesmy if str(request.user) == str(username): who = 'user' else: who = 'users' ret = render_to_string("accounts/details_activity.html", { 'user': user, 'stats': { 'trophies': trophies, 'trophies_points': trophies_points, 'news': news, 'news_points': news_points, 'images': images, 'images_points': images_points, 'videos': videos, 'videos_points': videos_points, 'picks_count': picks_count, 'picks_points': picks_points, 'total_points': trophies_points + news_points + images_points + videos_points + picks_points }, 'menu': menu.render(request, who, 'details_activity', {'username': username}, False), }, context_instance=RequestContext(request)), cache.set(key, ret, 15 * 60) # cache for 15 min return HttpResponse(ret)
def my_profile(request): """show current user's profile""" if request.user.is_anonymous(): return HttpResponseRedirect("/") # TODO: naprawić to def check_passwords(old_pass, new_pass1, new_pass2, user): if old_pass and user.check_password(old_pass): if new_pass1 == new_pass2: user.set_password(new_pass1) return True else: return False else: return False def thumbnail_string(buf, size=(80, 80)): from StringIO import StringIO from PIL import Image f = StringIO(buf) image = Image.open(f) if image.mode not in ('L', 'RGB'): image = image.convert('RGB') image = image.resize(size, Image.ANTIALIAS) o = StringIO() image.save(o, "JPEG") return o.getvalue() def check_avatar(value): from StringIO import StringIO from PIL import Image if 'content-type' in value: main, sub = value['content-type'].split('/') if not (main == 'image' and sub in ['jpeg', 'gif', 'png']): request.session['flash_msg'] = {'bledy': _('JPEG, PNG, GIF only.')} try: img = Image.open(StringIO(value['content'])) x, y = img.size except: request.session['flash_msg'] = { 'bledy': _('Upload a valid image. The file you uploaded was either not an image or a corrupted image.')} return {} if x > 800 or y > 600: request.session['flash_msg'] = {'bledy': _('Upload a valid image. This one is too big in size.')} if x > 80 and y > 80: img = Image.open(StringIO(thumbnail_string(value['content']))) return img try: acc = Accounts.objects.get(pk=request.user.id) except: raise Http404 # CHANGE PASSWORD post = request.POST.copy() if request.method == 'POST' and "change_pass" in post: if check_passwords(post['old_pass'], post['pass1'], post['pass2'], request.user): request.session['flash_msg'] = {'sukces': 'Hasło zostało zmienione'} else: request.session['flash_msg'] = {'bledy': 'Podane hasła są niepoprawne'} return HttpResponseRedirect(request.META['PATH_INFO']) # CHANGE AVATAR if request.method == 'POST' and "avatar" in request.FILES: from StringIO import StringIO from PIL import Image image = check_avatar(request.FILES['avatar']) if type(image) != type({}): # needed to save GIF format to jpeg image = image.convert("RGB") # Save the avatar as a jpeg avatar_path = '%simages/avatars/avatar_%s.jpg' % (settings.MEDIA_ROOT, request.user.id) image.save(avatar_path, 'jpeg') request.session['flash_msg'] = {'sukces': 'Zaktualizowano awatar'} # Save avatar path in profile return HttpResponseRedirect(request.META['PATH_INFO']) # EDIT PROFILE DATA if request.method == 'POST' and "change_profile" in post: post = request.POST.copy() acc.msn = post['im_msn'] acc.skype = post['im_skype'] acc.jabber = post['im_jabber'] acc.gg = post['im_gg'] acc.yahoo = post['im_yahoo'] acc.icq = post['im_icq'] acc.about_me = post['about_me'] acc.www = post['www'] acc.save() request.session['flash_msg'] = {'sukces': _('Zaktualizowano profil')} return HttpResponseRedirect(request.META['PATH_INFO']) return render_to_response("accounts/my_profile.html", { 'account': acc, 'teams': Teams.objects.filter(not_country=1).order_by('name_pl'), 'countries': Countries.objects.all().order_by('name_en'), 'menu': menu.render(request, 'users', 'index', {}, True), }, context_instance=RequestContext(request))
def details_classification(request, username, range, limit): # caching if username == request.user or (not request.user.is_anonymous() and request.user.is_staff): key = "username_%s_classification_%s_all_lang_%s" % (username, range, settings.LANGUAGE_CODE) else: key = "username_%s_classification_%s_lang_%s" % (username, range, settings.LANGUAGE_CODE) # c = cache.get(key) # if c is not None: # return HttpResponse(c) try: user = User.objects.get(username=username) except: raise Http404 if range == 'all': table_type = 'o' elif range == 'month': table_type = 'm' else: table_type = 'o' tables = {} leagues = [league for league in Leagues().get_leagues_list()] leagues.insert(0, 0) # --- queries --- for league in leagues: if league == 0: league_id = 0 league_name_en = '' league_name_pl = '' else: league_id = league.id league_name_en = league.name_en league_name_pl = league.name_pl tables[str(league_id)] = [] sql = """ SELECT position, points, date FROM accounts_table WHERE table_type = '%s' AND league_id = %s AND season_id = %s AND username = '******' ORDER BY date DESC """ % (table_type, league_id, settings.CURRENT_SEASON_ID, str(username)) logging.debug(sql) cursor = connection.cursor() cursor.execute(sql) row = cursor.fetchone() if row is not None and row[0] is not None: position = row[0] last_date = row[2] if position <= limit: q_limit = "5" else: q_limit = "4" else: position = 0 q_limit = "4" sql = "SELECT MAX(date) FROM accounts_table WHERE table_type = '%s' AND league_id = %s AND season_id = %s" % ( table_type, league_id, settings.CURRENT_SEASON_ID) logging.debug(sql) cursor = connection.cursor() cursor.execute(sql) row = cursor.fetchone() last_date = row[0] sql = """ SELECT username, position, points, picked, six, four, three, one, zero, minus_one, avg, prev_week, prev_month FROM accounts_table WHERE table_type = '%s' AND league_id = %s AND season_id = %s AND date = '%s' ORDER BY position ASC LIMIT %s """ % (table_type, league_id, settings.CURRENT_SEASON_ID, str(last_date), q_limit) logging.debug(sql) cursor = connection.cursor() cursor.execute(sql) for row in cursor.fetchall(): acc = Accounts(username=row[0], points=row[2]) acc.position = row[1] acc.picked = row[3] acc.six = row[4] acc.four = row[5] acc.three = row[6] acc.one = row[7] acc.zero = row[8] acc.minus_one = row[9] acc.avg = row[10] acc.prev_week = row[11] acc.prev_month = row[12] acc.league_name_en = league_name_en acc.league_name_pl = league_name_pl tables[str(league_id)].append(acc) if q_limit == "4": sql = """ SELECT username, position, points, picked, six, four, three, one, zero, minus_one, avg, prev_week, prev_month FROM accounts_table WHERE table_type = '%s' AND league_id = %s AND season_id = %s AND username = '******' AND date = '%s' LIMIT 1 """ % (table_type, league_id, settings.CURRENT_SEASON_ID, str(username), str(last_date)) logging.debug(sql) cursor = connection.cursor() cursor.execute(sql) row = cursor.fetchone() if row is not None: acc = Accounts(username=str(username), points=row[2]) acc.position = row[1] acc.picked = row[3] acc.six = row[4] acc.four = row[5] acc.three = row[6] acc.one = row[7] acc.zero = row[8] acc.minus_one = row[9] acc.avg = row[10] acc.prev_week = row[11] acc.prev_month = row[12] acc.league_name_en = league_name_en acc.league_name_pl = league_name_pl tables[str(league_id)].append(acc) else: acc = Accounts(username=str(username), points=0) acc.position = False acc.picked = 0 acc.six = 0 acc.four = 0 acc.three = 0 acc.one = 0 acc.zero = 0 acc.minus_one = 0 acc.avg = 0 acc.prev_week = 0 acc.prev_month = 0 acc.league_name_en = league_name_en acc.league_name_pl = league_name_pl tables[str(league_id)].append(acc) # rozne menu w zaleznosci gdzie jestesmy if str(request.user) == str(username): who = 'user' else: who = 'users' ret = render_to_string("accounts/details_classification.html", { 'range': range, 'show_user': user, 'tables': tables, 'menu': menu.render(request, who, 'details_classification', {'username': username}, False), }, context_instance=RequestContext(request)), cache.set(key, ret) return HttpResponse(ret)
def index(request, league_name="", when_type="", when=""): def parse_input(): # tutaj pelna walidacja weeks = helpers.get_weeks() try: if int(when) <= len(weeks) - 1: return weeks[int(when)][0].strftime("%Y-%m-%d") else: return -1 except: return -1 # CACHING HERE FRO 2-4 HOURS # key = "typer_table_league_%s_type_%s_when_%s_limit_0_lang_%s" % (league_id, when_type, when, settings.LANGUAGE_CODE) # c = cache.get(key) # if c: # return c if league_name != "": league_id = helpers.reveal_league_name(league_name) else: league_id = 0 url = request.META["PATH_INFO"] try: if request.POST["select_month"] != "": if url.find(request.POST["select_month"]) < 0: if league_id != 0: return HttpResponseRedirect( "/" + _("Typer URL") + "/" + league_name + "/" + _("miesiac") + "/" + request.POST["select_month"] + "/" ) else: return HttpResponseRedirect( "/" + _("Typer URL") + "/" + _("miesiac") + "/" + request.POST["select_month"] + "/" ) except: pass try: if int(request.POST["select_week"]) >= 0: if url.find(request.POST["select_week"]) < 0: if league_id != 0: return HttpResponseRedirect( "/" + _("Typer URL") + "/" + league_name + "/ + _('tydzien') + /" + str(request.POST["select_week"]) + "/" ) else: return HttpResponseRedirect( "/" + _("Typer URL") + "/" + _("tydzien") + "/" + str(request.POST["select_week"]) + "/" ) except: pass if when_type == "miesiac" or when_type == "month": year, month = helpers.reveal_month_name(when) month_name = when else: month = 0 month_name = None if when_type == "tydzien" or when_type == "week": week = parse_input() print week try: int_when = int(when) + 1 except: int_when = None else: int_when = None week = -1 if month != 0: users = ( UsersTable.objects.select_related() .filter(table_type="m", league_id=league_id, date=datetime.date(year, month, 1)) .order_by("position") ) elif week != -1: users = ( UsersTable.objects.select_related() .filter(table_type="w", league_id=league_id, date=week) .order_by("position") ) else: users = ( UsersTable.objects.select_related() .filter(table_type="o", league_id=league_id, date=datetime.date.today() - datetime.timedelta(1)) .order_by("position") ) i = 1 lines = [] weeks = helpers.get_weeks() for days in weeks: if days[0] > datetime.datetime.now(): break lines.append( str(i) + " " + _("tydz.") + " | " + days[0].strftime("%d-%m-%y") + " - " + days[1].strftime("%d-%m-%y") ) i += 1 return render_to_response( "picks/index.html", { "users": users, "league_name": league_name, "month_name": month_name, "weeks": lines, "selected_week": int_when, "menu": menu.render(request, "prediction", "index", {"league_name": league_name}, False), }, context_instance=RequestContext(request), )
def help(request, subject): return render_to_response("about/help/%s.html" % subject, {'menu': menu.render(request, 'main', 'index', {}, True)}, context_instance=RequestContext(request))