First import of migration to python 3
This commit is contained in:
0
TipPy/__init__.py
Normal file
0
TipPy/__init__.py
Normal file
16
TipPy/asgi.py
Normal file
16
TipPy/asgi.py
Normal file
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
ASGI config for TipPy project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TipPy.settings')
|
||||
|
||||
application = get_asgi_application()
|
||||
153
TipPy/settings.py
Normal file
153
TipPy/settings.py
Normal file
@@ -0,0 +1,153 @@
|
||||
"""
|
||||
Django settings for TipPy project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 4.0.6.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.0/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/4.0/ref/settings/
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure-jiw8js(^@d)no7tv(oq+ugl3kj=f8@j-kz3bj530&!%!$cjqj9'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'django.contrib.humanize',
|
||||
'tipp'
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'TipPy.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [BASE_DIR / 'templates']
|
||||
,
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'TipPy.wsgi.application'
|
||||
WSGI_APPLICATION = 'TipPy.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
||||
'NAME': 'tippy',
|
||||
'USER': 'tippy',
|
||||
'PASSWORD': 'tippy',
|
||||
'HOST': 'localhost',
|
||||
'PORT': '5432',
|
||||
}
|
||||
}
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/4.0/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'de-de'
|
||||
|
||||
TIME_ZONE = 'Europe/Berlin'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
# Absolute filesystem path to the directory that will hold user-uploaded files.
|
||||
# Example: "/home/media/media.lawrence.com/media/"
|
||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
|
||||
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
|
||||
# trailing slash.
|
||||
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
|
||||
MEDIA_URL = '/media/'
|
||||
# Absolute path to the directory static files should be collected to.
|
||||
# Don't put anything in this directory yourself; store your static files
|
||||
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
|
||||
# Example: "/home/media/media.lawrence.com/static/"
|
||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/4.0/howto/static-files/
|
||||
STATIC_URL = 'static/'
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
|
||||
|
||||
if not DEBUG:
|
||||
STATIC_ROOT = ''
|
||||
|
||||
STATICFILES_DIRS = [
|
||||
#os.path.join(BASE_DIR, 'static/'),
|
||||
]
|
||||
|
||||
# STATIC_ROOT=os.path.join(BASE_DIR,"static/")
|
||||
# STATIC_URL = 'static/'
|
||||
# STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'), ]
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
13
TipPy/urls.py
Normal file
13
TipPy/urls.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from django.contrib import admin, auth
|
||||
from django.urls import include, path, re_path
|
||||
|
||||
urlpatterns = [
|
||||
path('', include('tipp.urls')),
|
||||
path('admin/', admin.site.urls),
|
||||
# re_path(r'^login$', auth.views.login, {
|
||||
# 'template_name': 'login.html'}
|
||||
# ),
|
||||
# re_path(r'^logout$', auth.views.logout, {
|
||||
# 'next_page': '/'}),
|
||||
]
|
||||
|
||||
16
TipPy/wsgi.py
Normal file
16
TipPy/wsgi.py
Normal file
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
WSGI config for TipPy project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TipPy.settings')
|
||||
|
||||
application = get_wsgi_application()
|
||||
@@ -19,11 +19,13 @@ along with TipPy. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
from django.db import models
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
class UserProfile(models.Model):
|
||||
user = models.OneToOneField(User)
|
||||
user = models.OneToOneField(
|
||||
User,
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
avatar = models.ImageField(upload_to="profiles/", blank=True)
|
||||
|
||||
def __unicode__(self):
|
||||
@@ -58,8 +60,14 @@ class Match(models.Model):
|
||||
group = models.IntegerField()
|
||||
matchday = models.IntegerField()
|
||||
matchday_name = models.CharField(max_length=128)
|
||||
idTeam1 = models.ForeignKey(Team, related_name='+')
|
||||
idTeam2 = models.ForeignKey(Team, related_name='+')
|
||||
idTeam1 = models.ForeignKey(
|
||||
Team, related_name='+',
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
idTeam2 = models.ForeignKey(
|
||||
Team, related_name='+',
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
pointsTeam1 = models.SmallIntegerField()
|
||||
pointsTeam2 = models.SmallIntegerField()
|
||||
finished = models.BooleanField()
|
||||
@@ -70,8 +78,14 @@ class Match(models.Model):
|
||||
return (str(self.matchID))
|
||||
|
||||
class Tipp(models.Model):
|
||||
matchID = models.ForeignKey(Match)
|
||||
tipperID = models.ForeignKey(User)
|
||||
matchID = models.ForeignKey(
|
||||
Match,
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
tipperID = models.ForeignKey(
|
||||
User,
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
pointsTeam1 = models.PositiveSmallIntegerField()
|
||||
pointsTeam2 = models.PositiveSmallIntegerField()
|
||||
score = models.PositiveIntegerField(
|
||||
@@ -88,7 +102,10 @@ class Mandant(models.Model):
|
||||
return self.name
|
||||
|
||||
class Score(models.Model):
|
||||
client = models.ForeignKey(Mandant)
|
||||
client = models.ForeignKey(
|
||||
Mandant,
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
exact_high = models.PositiveSmallIntegerField()
|
||||
exact = models.PositiveSmallIntegerField()
|
||||
diff = models.PositiveSmallIntegerField()
|
||||
@@ -97,8 +114,14 @@ class Score(models.Model):
|
||||
return str(self.client)
|
||||
|
||||
class chart(models.Model):
|
||||
team = models.ForeignKey(Team)
|
||||
competition = models.ForeignKey(Competition)
|
||||
team = models.ForeignKey(
|
||||
Team,
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
competition = models.ForeignKey(
|
||||
Competition,
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
points = models.PositiveSmallIntegerField()
|
||||
diff = models.SmallIntegerField()
|
||||
games = models.PositiveSmallIntegerField()
|
||||
@@ -107,8 +130,14 @@ class chart(models.Model):
|
||||
unique_together = ("team", "competition")
|
||||
|
||||
class RelUserMandant(models.Model):
|
||||
user = models.ForeignKey(User)
|
||||
mandant = models.ForeignKey(Mandant)
|
||||
user = models.ForeignKey(
|
||||
User,
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
mandant = models.ForeignKey(
|
||||
Mandant,
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
|
||||
class Meta:
|
||||
unique_together = ("user", "mandant")
|
||||
@@ -119,7 +148,10 @@ class Post(models.Model):
|
||||
content = models.TextField()
|
||||
published = models.BooleanField(default=True)
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
author = models.ForeignKey(User)
|
||||
author = models.ForeignKey(
|
||||
User,
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ['-created']
|
||||
@@ -128,8 +160,14 @@ class Post(models.Model):
|
||||
return u'%s' % self.created
|
||||
|
||||
class RelPostMandant(models.Model):
|
||||
post = models.ForeignKey(Post)
|
||||
mandant = models.ForeignKey(Mandant)
|
||||
post = models.ForeignKey(
|
||||
Post,
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
mandant = models.ForeignKey(
|
||||
Mandant,
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
|
||||
class Meta:
|
||||
unique_together = ("post", "mandant")
|
||||
|
||||
@@ -18,7 +18,13 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with TipPy. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import sys, locale, suds, urllib2, psycopg2
|
||||
import sys
|
||||
import locale
|
||||
from suds.client import Client
|
||||
import urllib.request
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
import psycopg2
|
||||
|
||||
class OpenLiga(object):
|
||||
version = "0.1"
|
||||
@@ -37,21 +43,21 @@ class OpenLiga(object):
|
||||
# get a SUDS client object
|
||||
if self.proxyurl is None:
|
||||
try:
|
||||
self.client = suds.client.Client(
|
||||
self.client = Client(
|
||||
'http://www.openligadb.de/'
|
||||
+ 'Webservices/Sportsdata.asmx?WSDL')
|
||||
except (urllib2.URLError):
|
||||
except (urllib.error.URLError):
|
||||
self.error += "Connect to webservice failed."
|
||||
else:
|
||||
try:
|
||||
t = suds.transport.http.HttpTransport()
|
||||
proxy = urllib2.ProxyHandler({'http':proxyurl})
|
||||
opener = urllib2.build_opener(proxy)
|
||||
proxy = urllib.request.ProxyHandler({'http':proxyurl})
|
||||
opener = urllib.request.build_opener(proxy)
|
||||
t.urlopener = opener
|
||||
self.client = suds.client.Client(
|
||||
'http://www.openligadb.de/Webservices/'
|
||||
+ 'Sportsdata.asmx?WSDL', transport=t)
|
||||
except urllib2.URLError as e:
|
||||
except urllib.error.URLError as e:
|
||||
self.error += "Connect to webservice failed " \
|
||||
+ "(via proxy " + proxyurl + "): " + str(e) + "\n"
|
||||
|
||||
|
||||
31
tipp/urls.py
Normal file
31
tipp/urls.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from django.contrib.auth import views as auth_views
|
||||
from django.urls import re_path
|
||||
from django.conf.urls import include
|
||||
from django.conf import settings
|
||||
from django.conf.urls.static import static
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
re_path(r'^$', views.home, name='home'),
|
||||
re_path(r'^getSeason/(?P<ls>.*)/(?P<season>\d{4})$',
|
||||
views.getSeason),
|
||||
re_path(r'^update/(?P<ls>.*)/(?P<season>\d{4})/(?P<cur_md>\d{2})$',
|
||||
views.update, name='update'),
|
||||
re_path(r'^matchday/(?P<ls>.{3,})/(?P<season>\d{4})/(?P<matchday>\d{2})$',
|
||||
views.matchday, name='matchday'),
|
||||
re_path(r'^charts/(?P<ls>\w{3,})/(?P<season>\d{4})$', views.charts,
|
||||
name='charts'),
|
||||
re_path(r'^charts/(?P<ls>\w{3,})/(?P<season>\d{4})/(?P<pos>\w{1,})$',
|
||||
views.charts, name='charts'),
|
||||
re_path(r'^accounts/profile/(\d+)', views.profile),
|
||||
re_path(r'^accounts/', include('django.contrib.auth.urls')),
|
||||
re_path(r'^blog/newpost$', views.newBlogpost),
|
||||
re_path(r'^blog/(?P<page>\d)$', views.blogindex),
|
||||
re_path(r'^about$', views.about),
|
||||
re_path(r'^accounts/login/', auth_views.LoginView.as_view()),
|
||||
re_path(r'^logout', auth_views.LogoutView.as_view())
|
||||
]
|
||||
|
||||
if settings.DEBUG is True:
|
||||
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
117
tipp/views.py
117
tipp/views.py
@@ -18,40 +18,29 @@ You should have received a copy of the GNU General Public License
|
||||
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.contrib.auth import authenticate, login
|
||||
from django.contrib.auth.models import User
|
||||
import django.shortcuts
|
||||
from django.contrib.auth.decorators import login_required
|
||||
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, \
|
||||
from django.core.paginator import Paginator, EmptyPage, \
|
||||
PageNotAnInteger
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.utils import timezone
|
||||
from django.utils.text import slugify
|
||||
from django.db.models import Sum, Max
|
||||
from django.db.models import Sum
|
||||
from django.conf import settings
|
||||
from os.path import join as pjoin
|
||||
from tipp.models import *
|
||||
from tipp.forms import *
|
||||
from openliga import *
|
||||
from tipp.openliga import *
|
||||
from datetime import datetime
|
||||
from PIL import Image as PImage
|
||||
import urllib2, pytz, os, sys
|
||||
|
||||
# setting utf-8 as default encoding to avoid errors in file
|
||||
# uploads and form data
|
||||
reload(sys)
|
||||
sys.setdefaultencoding('utf8')
|
||||
import pytz
|
||||
import os
|
||||
|
||||
timezoneLocal = pytz.timezone('Europe/Berlin')
|
||||
|
||||
|
||||
def about(request):
|
||||
return render(request, 'about.html')
|
||||
return django.shortcuts.render(request, 'about.html')
|
||||
|
||||
|
||||
@login_required
|
||||
@@ -60,12 +49,13 @@ def home(request):
|
||||
season = get_current_season()
|
||||
md = get_current_md(ls)
|
||||
|
||||
return redirect("matchday",
|
||||
return django.shortcuts.redirect("matchday",
|
||||
ls=ls,
|
||||
season=season,
|
||||
matchday=str(md).zfill(2)
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def profile(request, pk):
|
||||
user = User.objects.get(id=pk)
|
||||
@@ -124,9 +114,12 @@ def profile(request, pk):
|
||||
# Print problems to the terminal.
|
||||
# They'll also be shown to the user.
|
||||
else:
|
||||
print user_form.errors, profile_form.errors
|
||||
print(
|
||||
user_form.errors,
|
||||
profile_form.errors
|
||||
)
|
||||
|
||||
return redirect( '/accounts/profile/' + str(user.id) )
|
||||
return django.shortcuts.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.
|
||||
@@ -139,7 +132,7 @@ def profile(request, pk):
|
||||
)
|
||||
profile_form = UserProfileForm(instance=profile)
|
||||
|
||||
return render(request, 'registration/profile.html', {
|
||||
return django.shortcuts.render(request, 'registration/profile.html', {
|
||||
'user_form': user_form,
|
||||
'profile_form': profile_form,
|
||||
'debug': debug,
|
||||
@@ -152,7 +145,6 @@ def getSeason(request, ls, season):
|
||||
ol = OpenLiga()
|
||||
teams = ol.getTeams(str(season), ls)
|
||||
season = ol.getSeason(str(season), ls)
|
||||
md = get_current_md(ls)
|
||||
|
||||
return_vals = []
|
||||
for team in teams[0]:
|
||||
@@ -167,20 +159,17 @@ def getSeason(request, ls, season):
|
||||
"""
|
||||
try:
|
||||
to = Team.objects.get(teamID=int(t.teamID))
|
||||
if to.iconURL is None:
|
||||
t.save(update_fields=['iconURL'])
|
||||
except Team.DoesNotExist:
|
||||
t.save()
|
||||
|
||||
if to.iconURL is None:
|
||||
t.save(update_fields=['iconURL'])
|
||||
|
||||
|
||||
for match in season[0]:
|
||||
m = Match(matchID=unicode(match['matchID']),
|
||||
matchDateTime=datetime.strptime(
|
||||
unicode(match['matchDateTime']), '%Y-%m-%d %H:%M:%S'),
|
||||
m = Match(matchID=match['matchID'],
|
||||
matchDateTime=match['matchDateTime'],
|
||||
group=int(match['groupID']),
|
||||
matchday=int(match['groupOrderID']),
|
||||
matchday_name=unicode(match['groupName']),
|
||||
matchday_name=match['groupName'],
|
||||
idTeam1=Team.objects.get(teamID=int(match['idTeam1'])),
|
||||
idTeam2=Team.objects.get(teamID=int(match['idTeam2'])),
|
||||
pointsTeam1=match['pointsTeam1'],
|
||||
@@ -191,12 +180,13 @@ def getSeason(request, ls, season):
|
||||
)
|
||||
m.save()
|
||||
|
||||
return redirect("matchday",
|
||||
return django.shortcuts.redirect("matchday",
|
||||
ls=ls,
|
||||
season=get_current_season(),
|
||||
matchday=str(get_current_md(ls)).zfill(2)
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def update(request, ls, season, cur_md):
|
||||
"""
|
||||
@@ -219,6 +209,7 @@ def update(request, ls, season, cur_md):
|
||||
elif result['resultName'] == "Endergebnis":
|
||||
pointsTeam1 = int(result['pointsTeam1'])
|
||||
pointsTeam2 = int(result['pointsTeam2'])
|
||||
break
|
||||
elif str(result['resultName']) == u"nach Verlängerung":
|
||||
pointsTeam1 = int(result['pointsTeam1'])
|
||||
pointsTeam2 = int(result['pointsTeam2'])
|
||||
@@ -230,8 +221,7 @@ def update(request, ls, season, cur_md):
|
||||
pointsTeam1 = -1
|
||||
pointsTeam2 = -1
|
||||
|
||||
|
||||
m = Match(matchID=unicode(match['matchID']),
|
||||
m = Match(matchID=match['matchID'],
|
||||
matchDateTime=match['matchDateTime'],
|
||||
pointsTeam1=pointsTeam1,
|
||||
pointsTeam2=pointsTeam2,
|
||||
@@ -242,7 +232,13 @@ def update(request, ls, season, cur_md):
|
||||
pointsTeam2 = -1
|
||||
|
||||
# evaluate scores
|
||||
scores = Score.objects.get(client=Mandant.objects.get(name='huse'))
|
||||
""" get mandants current user is related """
|
||||
mandants = RelUserMandant.objects.filter(user=request.user). \
|
||||
values_list('mandant', flat=True)
|
||||
|
||||
# scores = Score.objects.get(client=Mandant.objects.get(name='huse'))
|
||||
scores = Score.objects.get(client=mandants[0])
|
||||
|
||||
finished_matches = Match.objects.filter(
|
||||
finished=True,
|
||||
leagueShortcut=ls,
|
||||
@@ -271,24 +267,24 @@ def update(request, ls, season, cur_md):
|
||||
winnerReal = None
|
||||
if match.pointsTeam1 > match.pointsTeam2:
|
||||
winnerReal = 1
|
||||
elif (match.pointsTeam2 > match.pointsTeam1):
|
||||
elif match.pointsTeam2 > match.pointsTeam1:
|
||||
winnerReal = 2
|
||||
elif (match.pointsTeam1 == match.pointsTeam2):
|
||||
elif match.pointsTeam1 == match.pointsTeam2:
|
||||
winnerReal = 0
|
||||
|
||||
winnerTipp = None
|
||||
if tipp.pointsTeam1 > tipp.pointsTeam2:
|
||||
winnerTipp = 1
|
||||
elif (tipp.pointsTeam2 > tipp.pointsTeam1):
|
||||
elif tipp.pointsTeam2 > tipp.pointsTeam1:
|
||||
winnerTipp = 2
|
||||
elif (tipp.pointsTeam1 == tipp.pointsTeam2):
|
||||
elif tipp.pointsTeam1 == tipp.pointsTeam2:
|
||||
winnerTipp = 0
|
||||
|
||||
diffReal = match.pointsTeam1 - match.pointsTeam2
|
||||
diffTipp = tipp.pointsTeam1 - tipp.pointsTeam2
|
||||
|
||||
if ( winnerTipp == winnerReal ):
|
||||
if ( diffTipp == diffReal ):
|
||||
if winnerTipp == winnerReal:
|
||||
if diffTipp == diffReal:
|
||||
score = scores.diff
|
||||
else:
|
||||
score = scores.tendency
|
||||
@@ -301,12 +297,13 @@ def update(request, ls, season, cur_md):
|
||||
tipp.save()
|
||||
continue
|
||||
|
||||
return redirect("matchday",
|
||||
return django.shortcuts.redirect("matchday",
|
||||
ls=ls,
|
||||
season=season,
|
||||
matchday=cur_md
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def matchday(request, ls, season, matchday, template_name='md.html'):
|
||||
debug = ''
|
||||
@@ -389,16 +386,16 @@ def matchday(request, ls, season, matchday, template_name='md.html'):
|
||||
f = TippForm(prefix=str(match.matchID))
|
||||
|
||||
item = {}
|
||||
item['matchDateTime'] = (match.matchDateTime. \
|
||||
item['matchDateTime'] = (match.matchDateTime.
|
||||
astimezone(timezoneLocal).strftime('%a %d.%m, %H:%M'))
|
||||
|
||||
item['iconTeam1'] = str(match.idTeam1.icon)
|
||||
item['iconURLTeam1'] = str(match.idTeam1.iconURL)
|
||||
item['nameTeam1']= str(match.idTeam1)
|
||||
item['nameTeam1'] = str(match.idTeam1.name)
|
||||
item['abbrTeam1'] = str(match.idTeam1.abbr)
|
||||
item['iconTeam2'] = str(match.idTeam2.icon)
|
||||
item['iconURLTeam2'] = str(match.idTeam2.iconURL)
|
||||
item['nameTeam2'] = str(match.idTeam2)
|
||||
item['nameTeam2'] = str(match.idTeam2.name)
|
||||
item['abbrTeam2'] = str(match.idTeam2.abbr)
|
||||
item['started'] = match_started
|
||||
item['finished'] = match.finished
|
||||
@@ -443,7 +440,6 @@ def matchday(request, ls, season, matchday, template_name='md.html'):
|
||||
mandant_dict[mandant] = sorted(mandant_dict[mandant],
|
||||
key=lambda k: k['sum_score'], reverse=True)
|
||||
|
||||
|
||||
matches.append(item)
|
||||
|
||||
# get the newest blogposts
|
||||
@@ -465,7 +461,7 @@ def matchday(request, ls, season, matchday, template_name='md.html'):
|
||||
|
||||
debug += str(mandant_dict)
|
||||
|
||||
return render(request, 'md.html', {
|
||||
return django.shortcuts.render(request, 'md.html', {
|
||||
'debug': debug,
|
||||
# 'mds_season': mds_in_season,
|
||||
'cur_md': matchday,
|
||||
@@ -481,10 +477,10 @@ def matchday(request, ls, season, matchday, template_name='md.html'):
|
||||
'has_refresh': has_refresh
|
||||
})
|
||||
|
||||
|
||||
@login_required
|
||||
def charts(request, ls, season, pos='default',
|
||||
template_name='charts.html'):
|
||||
|
||||
debug = ''
|
||||
|
||||
if pos == 'default':
|
||||
@@ -522,7 +518,7 @@ def charts(request, ls, season, pos='default',
|
||||
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, \
|
||||
score = Tipp.objects.filter(matchID__in=matches,
|
||||
tipperID=user).aggregate(Sum('score'))
|
||||
|
||||
if score['score__sum'] is None:
|
||||
@@ -533,7 +529,7 @@ def charts(request, ls, season, pos='default',
|
||||
mandant_dict[mandant.name] = sorted(user_dict.items(),
|
||||
key=lambda x: x[1], reverse=True)
|
||||
|
||||
return render(request, template_name, {
|
||||
return django.shortcuts.render(request, template_name, {
|
||||
# 'debug': debug,
|
||||
'mandant_dict': mandant_dict,
|
||||
'season': season,
|
||||
@@ -541,6 +537,7 @@ def charts(request, ls, season, pos='default',
|
||||
'pos': pos
|
||||
})
|
||||
|
||||
|
||||
@login_required
|
||||
def blogindex(request, page):
|
||||
# get the blog posts that are published
|
||||
@@ -568,13 +565,14 @@ def blogindex(request, page):
|
||||
except EmptyPage:
|
||||
posts = p.page(p.num_pages)
|
||||
|
||||
return render(request, 'blogindex.html', {
|
||||
return django.shortcuts.render(request, 'blogindex.html', {
|
||||
'posts': posts,
|
||||
'ls': get_current_ls(),
|
||||
'season': get_current_season(),
|
||||
'page': page
|
||||
})
|
||||
|
||||
|
||||
@login_required
|
||||
def newBlogpost(request):
|
||||
debug = ''
|
||||
@@ -583,7 +581,7 @@ def newBlogpost(request):
|
||||
mandants = RelUserMandant.objects.filter(user=request.user). \
|
||||
values_list('mandant', flat=True)
|
||||
choices = []
|
||||
if mandants.count > 1:
|
||||
if mandants.count() > 1:
|
||||
has_mandant = True
|
||||
for m in Mandant.objects.filter(id__in=mandants):
|
||||
choices.append((m.name, m.description))
|
||||
@@ -611,14 +609,14 @@ def newBlogpost(request):
|
||||
mandant=Mandant.objects.get(id=mandants[0]))
|
||||
m.save()
|
||||
|
||||
return redirect( '/blog/1')
|
||||
return django.shortcuts.redirect('/blog/1')
|
||||
|
||||
blogpostForm = BlogpostForm()
|
||||
form_mandant = MandantsForm()
|
||||
form_mandant.fields["mandants"].choices = choices
|
||||
cnt_mandants = len(choices)
|
||||
|
||||
return render(request, 'newblogpost.html', {
|
||||
return django.shortcuts.render(request, 'newblogpost.html', {
|
||||
'debug': debug,
|
||||
'form_bp': blogpostForm,
|
||||
'form_mandants': form_mandant,
|
||||
@@ -627,6 +625,7 @@ def newBlogpost(request):
|
||||
'season': get_current_season()
|
||||
})
|
||||
|
||||
|
||||
def logout(request):
|
||||
"""
|
||||
Log users out and re-direct them to the main page.
|
||||
@@ -634,6 +633,7 @@ def logout(request):
|
||||
logout(request)
|
||||
return HttpResponseRedirect('/')
|
||||
|
||||
|
||||
def get_current_md(ls):
|
||||
"""
|
||||
get current matchday()
|
||||
@@ -651,9 +651,10 @@ def get_current_md(ls):
|
||||
|
||||
return (cur_md['groupOrderID'])
|
||||
|
||||
|
||||
def get_current_ls():
|
||||
return ("bl1")
|
||||
|
||||
def get_current_season():
|
||||
return("2016")
|
||||
|
||||
def get_current_season():
|
||||
return ("2022")
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
__version__ = '1.0.1'
|
||||
@@ -1,188 +0,0 @@
|
||||
"""
|
||||
Django settings for tippy project.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/1.7/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/1.7/ref/settings/
|
||||
"""
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
import os
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
||||
|
||||
# Django settings for tippy project.
|
||||
DEBUG = True
|
||||
TEMPLATE_DEBUG = DEBUG
|
||||
|
||||
ADMINS = (
|
||||
('Martin Bley', 'martin@mb-oss.de'),
|
||||
)
|
||||
|
||||
MANAGERS = ADMINS
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
||||
'NAME': 'tippy',
|
||||
'USER': 'tippy',
|
||||
'PASSWORD': 'tippy',
|
||||
'HOST': 'localhost',
|
||||
'PORT': '5432',
|
||||
}
|
||||
}
|
||||
|
||||
# Hosts/domain names that are valid for this site; required if DEBUG is False
|
||||
# See https://docs.djangoproject.com/en/1.4/ref/settings/#allowed-hosts
|
||||
ALLOWED_HOSTS = ['*']
|
||||
|
||||
# Local time zone for this installation. Choices can be found here:
|
||||
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
|
||||
# although not all choices may be available on all operating systems.
|
||||
# In a Windows environment this must be set to your system time zone.
|
||||
TIME_ZONE = 'Europe/Berlin'
|
||||
|
||||
# Language code for this installation. All choices can be found here:
|
||||
# http://www.i18nguy.com/unicode/language-identifiers.html
|
||||
LANGUAGE_CODE = 'de-de'
|
||||
|
||||
SITE_ID = 1
|
||||
|
||||
# If you set this to False, Django will make some optimizations so as not
|
||||
# to load the internationalization machinery.
|
||||
USE_I18N = True
|
||||
|
||||
# If you set this to False, Django will not format dates, numbers and
|
||||
# calendars according to the current locale.
|
||||
USE_L10N = True
|
||||
|
||||
# If you set this to False, Django will not use timezone-aware datetimes.
|
||||
USE_TZ = True
|
||||
|
||||
# Absolute filesystem path to the directory that will hold user-uploaded files.
|
||||
# Example: "/home/media/media.lawrence.com/media/"
|
||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
|
||||
|
||||
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
|
||||
# trailing slash.
|
||||
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
|
||||
MEDIA_URL = '/media/'
|
||||
|
||||
# Absolute path to the directory static files should be collected to.
|
||||
# Don't put anything in this directory yourself; store your static files
|
||||
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
|
||||
# Example: "/home/media/media.lawrence.com/static/"
|
||||
STATIC_ROOT = '/home/martin/dev/TipPy/src/static/'
|
||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
|
||||
|
||||
# URL prefix for static files.
|
||||
# Example: "http://media.lawrence.com/static/"
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
# Additional locations of static files
|
||||
STATICFILES_DIRS = (
|
||||
# Put strings here, like "/home/html/static" or "C:/www/django/static".
|
||||
# Always use forward slashes, even on Windows.
|
||||
# Don't forget to use absolute paths, not relative paths.
|
||||
'/home/martin/dev/TipPy/src/tippy/static/',
|
||||
)
|
||||
|
||||
# List of finder classes that know how to find static files in
|
||||
# various locations.
|
||||
STATICFILES_FINDERS = (
|
||||
'django.contrib.staticfiles.finders.FileSystemFinder',
|
||||
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
|
||||
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
|
||||
)
|
||||
|
||||
# Make this unique, and don't share it with anybody.
|
||||
SECRET_KEY = '-7%ge^nl1b0t0694%ws&0$ft_lo)j4l1f-qv#ku^=$)s(sw6us'
|
||||
|
||||
# List of callables that know how to import templates from various sources.
|
||||
TEMPLATE_LOADERS = (
|
||||
'django.template.loaders.filesystem.Loader',
|
||||
'django.template.loaders.app_directories.Loader',
|
||||
# 'django.template.loaders.eggs.Loader',
|
||||
)
|
||||
|
||||
MIDDLEWARE_CLASSES = (
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
# Uncomment the next line for simple clickjacking protection:
|
||||
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
)
|
||||
|
||||
ROOT_URLCONF = 'tippy.urls'
|
||||
|
||||
# Python dotted path to the WSGI application used by Django's runserver.
|
||||
WSGI_APPLICATION = 'tippy.wsgi.application'
|
||||
|
||||
TEMPLATE_DIRS = (
|
||||
[os.path.join(BASE_DIR, 'templates')]
|
||||
)
|
||||
|
||||
INSTALLED_APPS = (
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.sites',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'django.contrib.humanize',
|
||||
# Uncomment the next line to enable the admin:
|
||||
'django.contrib.admin',
|
||||
# Uncomment the next line to enable admin documentation:
|
||||
'django.contrib.admindocs',
|
||||
'tipp',
|
||||
)
|
||||
|
||||
# URL of the login page.
|
||||
LOGIN_URL = '/login'
|
||||
|
||||
# A sample logging configuration. The only tangible logging
|
||||
# performed by this configuration is to send an email to
|
||||
# the site admins on every HTTP 500 error when DEBUG=False.
|
||||
# See http://docs.djangoproject.com/en/dev/topics/logging for
|
||||
# more details on how to customize your logging configuration.
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'filters': {
|
||||
'require_debug_false': {
|
||||
'()': 'django.utils.log.RequireDebugFalse'
|
||||
}
|
||||
},
|
||||
'handlers': {
|
||||
'mail_admins': {
|
||||
'level': 'ERROR',
|
||||
'filters': ['require_debug_false'],
|
||||
'class': 'django.utils.log.AdminEmailHandler'
|
||||
}
|
||||
},
|
||||
'loggers': {
|
||||
'django.request': {
|
||||
'handlers': ['mail_admins'],
|
||||
'level': 'ERROR',
|
||||
'propagate': True,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
EMAIL_USE_TLS = True
|
||||
EMAIL_HOST = 'hermes.mb-oss.de'
|
||||
EMAIL_PORT = 25
|
||||
EMAIL_HOST_USER = 'tippy@mb-oss.de'
|
||||
#EMAIL_HOST_PASSWORD = 'p@ssword'
|
||||
|
||||
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
|
||||
SERVER_EMAIL = EMAIL_HOST_USER
|
||||
|
||||
SESSION_COOKIE_AGE = 7200
|
||||
|
||||
AUTH_PROFILE_MODULE = 'tippy.UserProfile'
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
from django.conf.urls import patterns, include, url
|
||||
from django.conf import settings
|
||||
|
||||
# Uncomment the next two lines to enable the admin:
|
||||
from django.contrib import admin
|
||||
admin.autodiscover()
|
||||
|
||||
urlpatterns = patterns('',
|
||||
# Examples:
|
||||
url(r'^$', 'tipp.views.home', name='home'),
|
||||
url(r'^login$', 'django.contrib.auth.views.login', {
|
||||
'template_name': 'login.html'}),
|
||||
url(r'^logout$', 'django.contrib.auth.views.logout', {
|
||||
'next_page': '/'}),
|
||||
url(r'^getSeason/(?P<ls>.*)/(?P<season>\d{4})$',
|
||||
'tipp.views.getSeason'),
|
||||
url(r'^update/(?P<ls>.*)/(?P<season>\d{4})/(?P<cur_md>\d{2})$',
|
||||
'tipp.views.update', name='update'),
|
||||
url(r'^matchday/(?P<ls>.{3,})/(?P<season>\d{4})/(?P<matchday>\d{2})$',
|
||||
'tipp.views.matchday', name='matchday'),
|
||||
url(r'^charts/(?P<ls>\w{3,})/(?P<season>\d{4})$', 'tipp.views.charts',
|
||||
name='charts'),
|
||||
url(r'^charts/(?P<ls>\w{3,})/(?P<season>\d{4})/(?P<pos>\w{1,})$',
|
||||
'tipp.views.charts', name='charts'),
|
||||
url(r'^accounts/profile/(\d+)', 'tipp.views.profile'),
|
||||
url(r'^accounts/', include('django.contrib.auth.urls')),
|
||||
url(r'^blog/newpost$', 'tipp.views.newBlogpost'),
|
||||
url(r'^blog/(?P<page>\d)$', 'tipp.views.blogindex'),
|
||||
url(r'^about$', 'tipp.views.about'),
|
||||
|
||||
# Uncomment the admin/doc line below to enable admin documentation:
|
||||
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
|
||||
|
||||
# Uncomment the next line to enable the admin:
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
)
|
||||
|
||||
if settings.DEBUG:
|
||||
urlpatterns += patterns('',
|
||||
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
|
||||
'document_root': settings.MEDIA_ROOT,
|
||||
}),
|
||||
)
|
||||
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
"""
|
||||
WSGI config for tippy project.
|
||||
|
||||
This module contains the WSGI application used by Django's development server
|
||||
and any production WSGI deployments. It should expose a module-level variable
|
||||
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
|
||||
this application via the ``WSGI_APPLICATION`` setting.
|
||||
|
||||
Usually you will have the standard Django WSGI application here, but it also
|
||||
might make sense to replace the whole Django WSGI application with a custom one
|
||||
that later delegates to the Django one. For example, you could introduce WSGI
|
||||
middleware here, or combine a Django application with an application of another
|
||||
framework.
|
||||
|
||||
"""
|
||||
import os
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tippy.settings")
|
||||
|
||||
# This application object is used by any WSGI server configured to use this
|
||||
# file. This includes Django's development server, if the WSGI_APPLICATION
|
||||
# setting points here.
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
application = get_wsgi_application()
|
||||
|
||||
# Apply WSGI middleware here.
|
||||
# from helloworld.wsgi import HelloWorldApplication
|
||||
# application = HelloWorldApplication(application)
|
||||
Reference in New Issue
Block a user