- getSeason() only for staff members

- new view staff()
- updated bootstrap to version 3.4.1
- updated jquery to 3.6.3
- changed container layout in main view 'matchday'
This commit is contained in:
Martin Bley
2023-04-02 21:24:20 +02:00
parent 446a55f3e5
commit 99eaafff00
11 changed files with 127 additions and 78 deletions

View File

@@ -17,9 +17,9 @@ GNU General Public License for more details.
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.db import models
"""
from django.contrib.auth.models import User
from django.db import models
class UserProfile(models.Model):
user = models.OneToOneField(
@@ -30,14 +30,16 @@ class UserProfile(models.Model):
def __unicode__(self):
return self.user.username
class Competition(models.Model):
leagueShortcut = models.CharField(max_length=32)
leagueName = models.CharField(max_length=128)
season = models.CharField(max_length=4)
def __unicode__(self):
return(self.leagueShortcut)
return (self.leagueShortcut)
class Team(models.Model):
teamID = models.IntegerField(unique=True, primary_key=True)
@@ -50,12 +52,12 @@ class Team(models.Model):
return self.name
class Meta:
managed = True
app_label = 'tipp'
managed = True
app_label = 'tipp'
class Match(models.Model):
matchID = models.IntegerField(unique=True,primary_key=True)
matchID = models.IntegerField(unique=True, primary_key=True)
matchDateTime = models.DateTimeField()
group = models.IntegerField()
matchday = models.IntegerField()
@@ -77,6 +79,7 @@ class Match(models.Model):
def __unicode__(self):
return (str(self.matchID))
class Tipp(models.Model):
matchID = models.ForeignKey(
Match,
@@ -95,12 +98,15 @@ class Tipp(models.Model):
class Meta:
unique_together = ("matchID", "tipperID")
class Mandant(models.Model):
name = models.CharField(max_length=32, unique=True)
description = models.CharField(max_length=255)
def __unicode__(self):
return self.name
class Score(models.Model):
client = models.ForeignKey(
Mandant,
@@ -110,9 +116,11 @@ class Score(models.Model):
exact = models.PositiveSmallIntegerField()
diff = models.PositiveSmallIntegerField()
tendency = models.PositiveSmallIntegerField()
def __unicode__(self):
return str(self.client)
class chart(models.Model):
team = models.ForeignKey(
Team,
@@ -128,7 +136,8 @@ class chart(models.Model):
class Meta:
unique_together = ("team", "competition")
class RelUserMandant(models.Model):
user = models.ForeignKey(
User,
@@ -141,9 +150,11 @@ class RelUserMandant(models.Model):
class Meta:
unique_together = ("user", "mandant")
def __unicode__(self):
return (str(self.user) + " -> " + str(self.mandant))
class Post(models.Model):
content = models.TextField()
published = models.BooleanField(default=True)
@@ -152,13 +163,14 @@ class Post(models.Model):
User,
on_delete=models.CASCADE
)
class Meta:
ordering = ['-created']
def __unicode__(self):
return u'%s' % self.created
class RelPostMandant(models.Model):
post = models.ForeignKey(
Post,
@@ -171,6 +183,6 @@ class RelPostMandant(models.Model):
class Meta:
unique_together = ("post", "mandant")
def __unicode__(self):
return (str(self.post) + " -> " + str(self.mandant))

View File

@@ -18,25 +18,25 @@
# 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
import locale
from suds.client import Client
import urllib.request
import urllib.error
import urllib.parse
import psycopg2
import urllib.request
from suds.client import Client
class OpenLiga(object):
version = "0.1"
error = ""
proxyurl = None
debug = None
client = None
version = "0.1"
error = ""
proxyurl = None
debug = None
client = None
def __init__(self, proxyurl=None, debug=False):
# set locale to environment (for dispaying localized dates)
locale.setlocale(locale.LC_TIME, "")
locale.setlocale(locale.LC_TIME, "")
self.debug = debug
@@ -44,30 +44,30 @@ class OpenLiga(object):
if self.proxyurl is None:
try:
self.client = Client(
'http://www.openligadb.de/'
+ 'Webservices/Sportsdata.asmx?WSDL')
except (urllib.error.URLError):
'http://www.openligadb.de/'
+ 'Webservices/Sportsdata.asmx?WSDL')
except (urllib.error.URLError):
self.error += "Connect to webservice failed."
else:
try:
t = suds.transport.http.HttpTransport()
proxy = urllib.request.ProxyHandler({'http':proxyurl})
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 urllib.error.URLError as e:
'http://www.openligadb.de/Webservices/'
+ 'Sportsdata.asmx?WSDL', transport=t)
except urllib.error.URLError as e:
self.error += "Connect to webservice failed " \
+ "(via proxy " + proxyurl + "): " + str(e) + "\n"
+ "(via proxy " + proxyurl + "): " + str(e) + "\n"
def getSeason(self, season, league='bl1'):
""" Get the whole season.
Args: season and league shortcut (optional)
"""
return(self.client.service.GetMatchdataByLeagueSaison(
leagueShortcut=league,leagueSaison=season)
return (self.client.service.GetMatchdataByLeagueSaison(
leagueShortcut=league, leagueSaison=season)
)
def getMatchday(self, season, matchdaynumber, league='bl1'):
@@ -75,22 +75,19 @@ class OpenLiga(object):
Args: season, matchdaynumber and league shortcut (optional)
"""
return(self.client.service.GetMatchdataByGroupLeagueSaison(
return (self.client.service.GetMatchdataByGroupLeagueSaison(
groupOrderID=matchdaynumber,
leagueShortcut=league,
leagueSaison=season)
)
def getTeams(self, season, league='bl1'):
return(self.client.service.GetTeamsByLeagueSaison(
return (self.client.service.GetTeamsByLeagueSaison(
leagueShortcut=league,
leagueSaison=season)
)
def getCurrentGroup(self, league):
return(self.client.service.GetCurrentGroup(
return (self.client.service.GetCurrentGroup(
leagueShortcut=league)
)

View File

@@ -22,6 +22,7 @@ urlpatterns = [
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'^staff', views.staff),
re_path(r'^accounts/login/', auth_views.LoginView.as_view()),
re_path(r'^accounts/logout/', auth_views.LogoutView.as_view())
]

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"""
Copyright (c) 2015-2016 by Martin Bley (martin@mb-oss.de)
Copyright (c) 2015-2016 by Martin Bley (dev@mb-oss.de)
This file is part of TipPy.
@@ -18,23 +18,25 @@ You should have received a copy of the GNU General Public License
along with TipPy. If not, see <http://www.gnu.org/licenses/>.
"""
import os
from os.path import join as pjoin
import django.shortcuts
import pytz
from PIL import Image as PImage
from django.conf import settings
from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.auth.decorators import login_required
from django.core.exceptions import ObjectDoesNotExist
from django.core.paginator import Paginator, EmptyPage, \
PageNotAnInteger
from django.db.models import Sum
from django.http import HttpResponseRedirect
from django.utils import timezone
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 tipp.models import *
from tipp.openliga import *
from datetime import datetime
from PIL import Image as PImage
import pytz
import os
timezoneLocal = pytz.timezone('Europe/Berlin')
@@ -139,8 +141,16 @@ def profile(request, pk):
'img': img}
)
@staff_member_required
def staff(request):
season = get_current_season(),
""" get available competitions """
competitions = Competition.objects.filter(season=season).order_by('leagueName')
@login_required
return django.shortcuts.render(request, 'staff.html', {'competitions': competitions})
@staff_member_required
def getSeason(request, ls, season):
ol = OpenLiga()
teams = ol.getTeams(str(season), ls)
@@ -306,6 +316,7 @@ def update(request, ls, season, cur_md):
@login_required
def matchday(request, ls, season, matchday, template_name='md.html'):
update(request, ls, season, matchday)
debug = ''
debug += "Debugging: "
has_refresh = True