Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a221c0e37d | |||
| 72be0aebdb | |||
| 929b540753 | |||
| b44d31d128 | |||
| 26833e389a | |||
| ffed1ef6e8 | |||
| db5ece431b | |||
| 20ef745b3f | |||
| 45293586a7 | |||
| 8f9398ced5 | |||
| 589884c4be | |||
| 5c3c56ecc3 | |||
| 6042838f28 | |||
| c2eede9500 | |||
| e3ef06a41a | |||
| 9be82123da | |||
| 911b19068c | |||
| c02f137c0b | |||
| 538f6262fd | |||
| 4b2f7e4641 | |||
| d99eee4751 | |||
| 5a0a1daa39 | |||
| 20f0a836e5 | |||
| c0eb583a69 | |||
| 7292957497 | |||
| 62ec42297d | |||
| 5b033803a8 | |||
| 364166d84b | |||
| de904d4ad4 | |||
| 7c66399c8f | |||
| 6332b49eac | |||
| ae3d3d2c12 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -7,3 +7,4 @@ old_stuff/
|
|||||||
static/
|
static/
|
||||||
templates/blogindex.html-media
|
templates/blogindex.html-media
|
||||||
tippy/static/
|
tippy/static/
|
||||||
|
warnings.txt
|
||||||
|
|||||||
29
templates/about.html
Normal file
29
templates/about.html
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% load i18n static %}
|
||||||
|
{% load humanize %}
|
||||||
|
{% block head %}
|
||||||
|
<script type="text/javascript" src="{{ STATIC_URL }}javascript/tippy.js"></script>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block nav %}
|
||||||
|
{% include "nav.html" with ls=ls season=season %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<div id="content-main">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-7">
|
||||||
|
<h2>Über TipPy</h2>
|
||||||
|
<p>TipPy ist eine responsive Web-Applikation für Tippspiele mit
|
||||||
|
einem "Mobile-First-Ansatz" . Unterstützt werden alle auf
|
||||||
|
<a href="http://www.OpenLigaDB.de">OpenLigaDB</a> bereitgestellten
|
||||||
|
Sportarten und Ligen.
|
||||||
|
|
||||||
|
TipPy wurde in <a href="http://www.python.org">Python</a> umgesetzt
|
||||||
|
und benutzt die Frameworks <a href="http://www.django.org">Django</a>
|
||||||
|
als Web Application Framework, und Twitters <a href="www.getbootstrap.com">
|
||||||
|
Bootstrap</a> für CSS.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@@ -51,8 +51,13 @@
|
|||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-7">
|
<div class="col-md-7">
|
||||||
<p>© Martin Bley, 2014-2015 | Dank an <a href="http://openligadb.de">OpenLigaDB</a> für
|
<p>
|
||||||
die Bereitstellung der Spielergebnisse.</p>
|
<div class="pull-left">
|
||||||
|
© Martin Bley, 2014-2016 | Dank an
|
||||||
|
<a href="http://openligadb.de">OpenLigaDB</a> für die Bereitstellung der
|
||||||
|
Spielergebnisse.
|
||||||
|
</div>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -24,8 +24,7 @@
|
|||||||
<div class="col-md-7">
|
<div class="col-md-7">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
{{post.author.first_name}} schrieb {{post.created|naturaltime}},
|
{{post.author.first_name}} schrieb {{post.created|naturaltime}}
|
||||||
<a href="{{post.get_absolute_url}}">{{post.title}}</a>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
{% if avatar %}
|
{% if avatar %}
|
||||||
|
|||||||
@@ -20,8 +20,7 @@
|
|||||||
{% for post, avatar in posts %}
|
{% for post, avatar in posts %}
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
{{post.author.first_name}} schrieb {{post.created|naturaltime}},
|
{{post.author.first_name}} schrieb {{post.created|naturaltime}}
|
||||||
<a href="{{post.get_absolute_url}}">{{post.title}}</a>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
{% if avatar %}
|
{% if avatar %}
|
||||||
@@ -41,7 +40,7 @@
|
|||||||
<nav>
|
<nav>
|
||||||
<ul class="pager">
|
<ul class="pager">
|
||||||
<li data-toggle="tooltip" title="{% trans 'previous' %}" class="previous"><a href="/matchday/{{ ls }}/{{ season }}/{{ cur_md|add:"-1"|stringformat:"02i" }}"><span aria-hidden="true">←</span></a></li>
|
<li data-toggle="tooltip" title="{% trans 'previous' %}" class="previous"><a href="/matchday/{{ ls }}/{{ season }}/{{ cur_md|add:"-1"|stringformat:"02i" }}"><span aria-hidden="true">←</span></a></li>
|
||||||
{{ cur_md }}. Spieltag
|
{{ md_name }}
|
||||||
<li data-toggle="tooltip" title="{% trans 'next' %}" class="next"><a href="/matchday/{{ ls }}/{{ season }}/{{ cur_md|add:"1"|stringformat:"02i" }}"><span aria-hidden="true">→</span></a></li>
|
<li data-toggle="tooltip" title="{% trans 'next' %}" class="next"><a href="/matchday/{{ ls }}/{{ season }}/{{ cur_md|add:"1"|stringformat:"02i" }}"><span aria-hidden="true">→</span></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
@@ -52,18 +51,26 @@
|
|||||||
<th>Anstoß</th>
|
<th>Anstoß</th>
|
||||||
<th>Heim</th>
|
<th>Heim</th>
|
||||||
<th>Gast</th>
|
<th>Gast</th>
|
||||||
<th>Erg.></th>
|
<th>Erg.</th>
|
||||||
<th colspan="2">Tipp</th>
|
<th colspan="2">Tipp</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for match in matches %}
|
{% for match in matches %}
|
||||||
{% if match.started and not match.finished %}
|
{% if match.started and not match.finished %}
|
||||||
<tr class="danger">{% else %}<tr>{% endif %}
|
<tr class="danger">{% else %}<tr>{% endif %}
|
||||||
<td>{{ match.matchDateTime }}</td>
|
<td>{{ match.matchDateTime }}</td>
|
||||||
|
{% if match.iconURLTeam1 != "" %}
|
||||||
|
<td><img src="{{ match.iconURLTeam1 }}" width="20"/>
|
||||||
|
{% else %}
|
||||||
<td><img src="{{ STATIC_URL}}{{ match.iconTeam1 }}" />
|
<td><img src="{{ STATIC_URL}}{{ match.iconTeam1 }}" />
|
||||||
|
{% endif %}
|
||||||
<span class="hidden-xs"> {{ match.nameTeam1 }}</span>
|
<span class="hidden-xs"> {{ match.nameTeam1 }}</span>
|
||||||
<span class="visible-xs"> {{ match.abbrTeam1 }}</span>
|
<span class="visible-xs"> {{ match.abbrTeam1 }}</span>
|
||||||
</td>
|
</td>
|
||||||
|
{% if match.iconURLTeam1 != "" %}
|
||||||
|
<td><img src="{{ match.iconURLTeam2 }}" width="20"/>
|
||||||
|
{% else %}
|
||||||
<td><img src="{{ STATIC_URL}}{{ match.iconTeam2 }}" />
|
<td><img src="{{ STATIC_URL}}{{ match.iconTeam2 }}" />
|
||||||
|
{% endif %}
|
||||||
<span class="hidden-xs"> {{ match.nameTeam2 }}</span>
|
<span class="hidden-xs"> {{ match.nameTeam2 }}</span>
|
||||||
<span class="visible-xs"> {{ match.abbrTeam2 }}</span>
|
<span class="visible-xs"> {{ match.abbrTeam2 }}</span>
|
||||||
</td>
|
</td>
|
||||||
@@ -80,30 +87,43 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
{% for mandant, list in mandant_dict.items %}
|
||||||
<div class="col-md-7">
|
<div class="col-md-7">
|
||||||
<h2>Mitspieler</h2>
|
<h4>Mitspieler {{ mandant }}</h4>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-hover table-condensed">
|
<table class="table table-hover table-condensed">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Tipper</th>
|
<th>Tipper</th>
|
||||||
<th>Gesamt</th>
|
<th>Gesamt</th>
|
||||||
{% for match in matches %}
|
{% for match in matches %}
|
||||||
<th><img src="{{ STATIC_URL }}{{ match.iconTeam1 }}" /><br /><br />
|
<th>
|
||||||
<img src="{{ STATIC_URL }}{{ match.iconTeam2 }}" /></th>
|
{% if match.iconURLTeam1 != "" %}
|
||||||
|
<img src="{{ match.iconURLTeam1 }}" width="20"/>
|
||||||
|
{% else %}
|
||||||
|
<img src="{{ STATIC_URL }}{{ match.iconTeam1 }}" />
|
||||||
|
{% endif %}
|
||||||
|
<br /><br />
|
||||||
|
{% if match.iconURLTeam2 != "" %}
|
||||||
|
<img src="{{ match.iconURLTeam2 }}" width="20"/>
|
||||||
|
{% else %}
|
||||||
|
<img src="{{ STATIC_URL }}{{ match.iconTeam2 }}" />
|
||||||
|
{% endif %}
|
||||||
|
</th>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tr>
|
</tr>
|
||||||
{% for mate in tipp_mates %}
|
{% for mate in list %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ mate.mate }}</td>
|
<td>{{ mate.mate.first_name }}</td>
|
||||||
<td>{{ mate.sum_score }}</td>
|
<td>{{ mate.sum_score }}</td>
|
||||||
{% for tipp in mate.tipps %}
|
{% for tipp in mate.tipps %}
|
||||||
<td>{{ tipp }}</td>
|
<td>{{ tipp }}</td>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<span class="icon-bar"></span>
|
<span class="icon-bar"></span>
|
||||||
<span class="icon-bar"></span>
|
<span class="icon-bar"></span>
|
||||||
</button>
|
</button>
|
||||||
<span class="navbar-brand">TipPy 1.0</span>
|
<a class="navbar-brand" href="/about">TipPy 1.0</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="navbar-collapse collapse">
|
<div class="navbar-collapse collapse">
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
|
|||||||
@@ -10,10 +10,10 @@
|
|||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<div id="content-main">
|
<div id="content-main">
|
||||||
{% if form.errors %}
|
{% if form_bp.errors %}
|
||||||
<div>
|
<div>
|
||||||
<p class="errornote">
|
<p class="errornote">
|
||||||
{% if form.errors.items|length == 1 %}
|
{% if form_bp.errors.items|length == 1 %}
|
||||||
{% trans "Please correct the error below." %}
|
{% trans "Please correct the error below." %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% trans "Please correct the errors below." %}
|
{% trans "Please correct the errors below." %}
|
||||||
@@ -24,17 +24,19 @@
|
|||||||
<div class="col-md-8">
|
<div class="col-md-8">
|
||||||
<form class="form-horizontal" action="" method="post">{% csrf_token %}
|
<form class="form-horizontal" action="" method="post">{% csrf_token %}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
{{form.title.errors}}
|
{{form_bp.content.errors}}
|
||||||
<label for="id_title" class="col-sm-4 control-label required">{% trans 'Title' %}</label>
|
|
||||||
<div class="col-sm-5">
|
|
||||||
<input id="id_title" maxlength="32" name="title" class="form-control" type="text" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
{{form.content.errors}}
|
|
||||||
<label for="id_content" class="col-sm-4 control-label required">{% trans 'Content' %}</label>
|
<label for="id_content" class="col-sm-4 control-label required">{% trans 'Content' %}</label>
|
||||||
<div class="col-sm-5">
|
<div class="col-sm-5">
|
||||||
<textarea class="form-control" maxlength="256" rows="2" id="id_content" name="content"></textarea>
|
<textarea class="form-control" maxlength="256" rows="2"
|
||||||
|
id="id_content" name="content"></textarea>
|
||||||
|
{% if cnt_mandants > 1 %}
|
||||||
|
{{ form_mandants.mandants.label_tag }}
|
||||||
|
{% for choice in form_mandants.mandants %}
|
||||||
|
<label for="{{choice.id_for_label}}">
|
||||||
|
{{ choice.tag }} {{choice.choice_label}}
|
||||||
|
</label>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@@ -45,5 +47,12 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% if debug %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-8">
|
||||||
|
<p>{{ debug }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -18,24 +18,20 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with TipPy. If not, see <http://www.gnu.org/licenses/>.
|
along with TipPy. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from tipp.models import Team, Match, Tipp, Score, Mandant, RelUserMandant, Competition, Post, UserProfile
|
from tipp.models import *
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
class PostAdmin(admin.ModelAdmin):
|
class PostAdmin(admin.ModelAdmin):
|
||||||
# fields display on change list
|
# fields display on change list
|
||||||
list_display = ['title']
|
list_display = ['content']
|
||||||
# fields to filter the change list with
|
# fields to filter the change list with
|
||||||
list_filter = ['published', 'created']
|
list_filter = ['published', 'created']
|
||||||
# fields to search in change list
|
# fields to search in change list
|
||||||
search_fields = ['title', 'content']
|
search_fields = ['content']
|
||||||
# enable the date drill down on change list
|
# enable the date drill down on change list
|
||||||
date_hierarchy = 'created'
|
date_hierarchy = 'created'
|
||||||
# enable the save buttons on top on change form
|
# enable the save buttons on top on change form
|
||||||
save_on_top = True
|
save_on_top = True
|
||||||
# prepopulate the slug from the title - big timesaver!
|
|
||||||
prepopulated_fields = {"slug": ("title",)}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Team)
|
admin.site.register(Team)
|
||||||
admin.site.register(Match)
|
admin.site.register(Match)
|
||||||
@@ -45,4 +41,5 @@ admin.site.register(Score)
|
|||||||
admin.site.register(RelUserMandant)
|
admin.site.register(RelUserMandant)
|
||||||
admin.site.register(Competition)
|
admin.site.register(Competition)
|
||||||
admin.site.register(Post, PostAdmin)
|
admin.site.register(Post, PostAdmin)
|
||||||
|
admin.site.register(RelPostMandant)
|
||||||
|
|
||||||
|
|||||||
@@ -22,31 +22,42 @@ from django import forms
|
|||||||
from django.forms import ModelForm
|
from django.forms import ModelForm
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core.files.images import get_image_dimensions
|
from django.core.files.images import get_image_dimensions
|
||||||
from tipp.models import Match, Competition, Post, UserProfile
|
from tipp.models import Match, Competition, Post, UserProfile, \
|
||||||
|
Mandant, RelUserMandant
|
||||||
|
|
||||||
class NumberInput(forms.TextInput):
|
class NumberInput(forms.TextInput):
|
||||||
input_type = 'number'
|
input_type = 'number'
|
||||||
|
|
||||||
class TippForm(forms.Form):
|
class TippForm(forms.Form):
|
||||||
tippTeam1 = forms.IntegerField(required=True,widget=NumberInput(attrs={
|
tippTeam1 = forms.IntegerField(required=True,widget=NumberInput(
|
||||||
|
attrs={
|
||||||
'cols': '2',
|
'cols': '2',
|
||||||
'min': '0', 'max': '99', 'step': '1',
|
'min': '0', 'max': '99', 'step': '1',
|
||||||
'class':'form-inline',
|
'class':'form-inline',
|
||||||
'role': 'form'}
|
'role': 'form'
|
||||||
|
}
|
||||||
))
|
))
|
||||||
tippTeam2 = forms.IntegerField(required=True,widget=NumberInput(attrs={
|
tippTeam2 = forms.IntegerField(required=True,widget=NumberInput(
|
||||||
|
attrs={
|
||||||
'cols': '2',
|
'cols': '2',
|
||||||
'min': '0', 'max': '99', 'step': '1',
|
'min': '0', 'max': '99', 'step': '1',
|
||||||
'class':'form-inline',
|
'class':'form-inline',
|
||||||
'role': 'form'}
|
'role': 'form'
|
||||||
|
}
|
||||||
))
|
))
|
||||||
tippTeam1.widget.attrs['style'] = "width:35px"
|
tippTeam1.widget.attrs['style'] = "width:45px"
|
||||||
tippTeam2.widget.attrs['style'] = "width:35px"
|
tippTeam2.widget.attrs['style'] = "width:45px"
|
||||||
|
|
||||||
class BlogpostForm(ModelForm):
|
class BlogpostForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Post
|
model = Post
|
||||||
fields = ['title', 'content']
|
fields = ['content']
|
||||||
|
|
||||||
|
class MandantsForm(forms.Form):
|
||||||
|
mandants = forms.MultipleChoiceField(
|
||||||
|
label= "Posten in",
|
||||||
|
widget=forms.CheckboxSelectMultiple({'checked':'checked'})
|
||||||
|
)
|
||||||
|
|
||||||
class UserForm(forms.ModelForm):
|
class UserForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
@@ -42,15 +42,22 @@ class Team(models.Model):
|
|||||||
name = models.CharField(max_length=200)
|
name = models.CharField(max_length=200)
|
||||||
icon = models.FileField(upload_to="images/team_logos/")
|
icon = models.FileField(upload_to="images/team_logos/")
|
||||||
abbr = models.CharField(max_length=3)
|
abbr = models.CharField(max_length=3)
|
||||||
|
iconURL = models.CharField(max_length=2000)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
managed = True
|
||||||
|
app_label = 'tipp'
|
||||||
|
|
||||||
|
|
||||||
class Match(models.Model):
|
class Match(models.Model):
|
||||||
matchID = models.IntegerField(unique=True,primary_key=True)
|
matchID = models.IntegerField(unique=True,primary_key=True)
|
||||||
matchDateTime = models.DateTimeField()
|
matchDateTime = models.DateTimeField()
|
||||||
group = models.IntegerField()
|
group = models.IntegerField()
|
||||||
matchday = models.IntegerField()
|
matchday = models.IntegerField()
|
||||||
|
matchday_name = models.CharField(max_length=128)
|
||||||
idTeam1 = models.ForeignKey(Team, related_name='+')
|
idTeam1 = models.ForeignKey(Team, related_name='+')
|
||||||
idTeam2 = models.ForeignKey(Team, related_name='+')
|
idTeam2 = models.ForeignKey(Team, related_name='+')
|
||||||
pointsTeam1 = models.SmallIntegerField()
|
pointsTeam1 = models.SmallIntegerField()
|
||||||
@@ -60,11 +67,6 @@ class Match(models.Model):
|
|||||||
leagueShortcut = models.CharField(max_length=12)
|
leagueShortcut = models.CharField(max_length=12)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
"""
|
|
||||||
return (str(self.matchID) +
|
|
||||||
str(Team.objects.get(teamID=int(self.idTeam1)).values(name)) + " - " +
|
|
||||||
str(Team.objects.get(teamID=int(self.idTeam2)).values(name)))
|
|
||||||
"""
|
|
||||||
return (str(self.matchID))
|
return (str(self.matchID))
|
||||||
|
|
||||||
class Tipp(models.Model):
|
class Tipp(models.Model):
|
||||||
@@ -72,7 +74,9 @@ class Tipp(models.Model):
|
|||||||
tipperID = models.ForeignKey(User)
|
tipperID = models.ForeignKey(User)
|
||||||
pointsTeam1 = models.PositiveSmallIntegerField()
|
pointsTeam1 = models.PositiveSmallIntegerField()
|
||||||
pointsTeam2 = models.PositiveSmallIntegerField()
|
pointsTeam2 = models.PositiveSmallIntegerField()
|
||||||
score = models.PositiveIntegerField(blank=True, null=True)
|
score = models.PositiveIntegerField(
|
||||||
|
blank=True, null=True
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = ("matchID", "tipperID")
|
unique_together = ("matchID", "tipperID")
|
||||||
@@ -112,8 +116,6 @@ class RelUserMandant(models.Model):
|
|||||||
return (str(self.user) + " -> " + str(self.mandant))
|
return (str(self.user) + " -> " + str(self.mandant))
|
||||||
|
|
||||||
class Post(models.Model):
|
class Post(models.Model):
|
||||||
title = models.CharField(max_length=255, null=False, blank=False)
|
|
||||||
slug = models.SlugField(unique=True, max_length=255)
|
|
||||||
content = models.TextField()
|
content = models.TextField()
|
||||||
published = models.BooleanField(default=True)
|
published = models.BooleanField(default=True)
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
@@ -123,9 +125,14 @@ class Post(models.Model):
|
|||||||
ordering = ['-created']
|
ordering = ['-created']
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return u'%s' % self.title
|
return u'%s' % self.created
|
||||||
|
|
||||||
def get_absolute_url(self):
|
class RelPostMandant(models.Model):
|
||||||
return reverse('tipp.views.blogpost', args=[self.slug])
|
post = models.ForeignKey(Post)
|
||||||
|
mandant = models.ForeignKey(Mandant)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
unique_together = ("post", "mandant")
|
||||||
|
def __unicode__(self):
|
||||||
|
return (str(self.post) + " -> " + str(self.mandant))
|
||||||
|
|
||||||
|
|||||||
32
tipp/openliga.py
Executable file → Normal file
32
tipp/openliga.py
Executable file → Normal file
@@ -37,7 +37,9 @@ class OpenLiga(object):
|
|||||||
# get a SUDS client object
|
# get a SUDS client object
|
||||||
if self.proxyurl is None:
|
if self.proxyurl is None:
|
||||||
try:
|
try:
|
||||||
self.client = suds.client.Client('http://www.openligadb.de/Webservices/Sportsdata.asmx?WSDL')
|
self.client = suds.client.Client(
|
||||||
|
'http://www.openligadb.de/'
|
||||||
|
+ 'Webservices/Sportsdata.asmx?WSDL')
|
||||||
except (urllib2.URLError):
|
except (urllib2.URLError):
|
||||||
self.error += "Connect to webservice failed."
|
self.error += "Connect to webservice failed."
|
||||||
else:
|
else:
|
||||||
@@ -46,25 +48,43 @@ class OpenLiga(object):
|
|||||||
proxy = urllib2.ProxyHandler({'http':proxyurl})
|
proxy = urllib2.ProxyHandler({'http':proxyurl})
|
||||||
opener = urllib2.build_opener(proxy)
|
opener = urllib2.build_opener(proxy)
|
||||||
t.urlopener = opener
|
t.urlopener = opener
|
||||||
self.client = suds.client.Client('http://www.openligadb.de/Webservices/Sportsdata.asmx?WSDL', transport=t)
|
self.client = suds.client.Client(
|
||||||
|
'http://www.openligadb.de/Webservices/'
|
||||||
|
+ 'Sportsdata.asmx?WSDL', transport=t)
|
||||||
except urllib2.URLError as e:
|
except urllib2.URLError as e:
|
||||||
self.error += "Connect to webservice failed (via proxy " + proxyurl + "): " + str(e) + "\n"
|
self.error += "Connect to webservice failed " \
|
||||||
|
+ "(via proxy " + proxyurl + "): " + str(e) + "\n"
|
||||||
|
|
||||||
def getSeason(self, season, league='bl1'):
|
def getSeason(self, season, league='bl1'):
|
||||||
""" Get the whole season.
|
""" Get the whole season.
|
||||||
|
|
||||||
Args: season and league shortcut (optional)
|
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'):
|
def getMatchday(self, season, matchdaynumber, league='bl1'):
|
||||||
""" Get matchday.
|
""" Get matchday.
|
||||||
|
|
||||||
Args: season, matchdaynumber and league shortcut (optional)
|
Args: season, matchdaynumber and league shortcut (optional)
|
||||||
"""
|
"""
|
||||||
return(self.client.service.GetMatchdataByGroupLeagueSaison(groupOrderID=matchdaynumber,leagueShortcut=league,leagueSaison=season))
|
return(self.client.service.GetMatchdataByGroupLeagueSaison(
|
||||||
|
groupOrderID=matchdaynumber,
|
||||||
|
leagueShortcut=league,
|
||||||
|
leagueSaison=season)
|
||||||
|
)
|
||||||
|
|
||||||
def getTeams(self, season, league='bl1'):
|
def getTeams(self, season, league='bl1'):
|
||||||
return(self.client.service.GetTeamsByLeagueSaison(leagueShortcut=league,leagueSaison=season))
|
return(self.client.service.GetTeamsByLeagueSaison(
|
||||||
|
leagueShortcut=league,
|
||||||
|
leagueSaison=season)
|
||||||
|
)
|
||||||
|
|
||||||
|
def getCurrentGroup(self, league):
|
||||||
|
return(self.client.service.GetCurrentGroup(
|
||||||
|
leagueShortcut=league)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"""
|
"""
|
||||||
This file demonstrates writing tests using the unittest module. These will pass
|
This file demonstrates writing tests using the unittest module.
|
||||||
when you run "manage.py test".
|
These will pass when you run "manage.py test".
|
||||||
|
|
||||||
Replace this with more appropriate tests for your application.
|
Replace this with more appropriate tests for your application.
|
||||||
"""
|
"""
|
||||||
|
|||||||
355
tipp/views.py
355
tipp/views.py
@@ -19,15 +19,18 @@ along with TipPy. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
from django.http import HttpResponse
|
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 import authenticate, login
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.auth.decorators import login_required
|
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.context_processors import csrf
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.core.urlresolvers import reverse
|
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 import timezone
|
||||||
from django.utils.text import slugify
|
from django.utils.text import slugify
|
||||||
from django.db.models import Sum, Max
|
from django.db.models import Sum, Max
|
||||||
@@ -38,19 +41,29 @@ from tipp.forms import *
|
|||||||
from openliga import *
|
from openliga import *
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from PIL import Image as PImage
|
from PIL import Image as PImage
|
||||||
import urllib2, pytz, os
|
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')
|
||||||
|
|
||||||
timezoneLocal = pytz.timezone('Europe/Berlin')
|
timezoneLocal = pytz.timezone('Europe/Berlin')
|
||||||
|
|
||||||
|
def about(request):
|
||||||
|
return render(request, 'about.html')
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def home(request):
|
def home(request):
|
||||||
ls = get_current_ls()
|
ls = get_current_ls()
|
||||||
season = get_current_season()
|
season = get_current_season()
|
||||||
|
md = get_current_md(ls)
|
||||||
|
|
||||||
return redirect("matchday",
|
return redirect("matchday",
|
||||||
ls = ls,
|
ls = ls,
|
||||||
season = season,
|
season = season,
|
||||||
matchday=str(get_current_md(ls, season)).zfill(2)
|
matchday=str(md).zfill(2)
|
||||||
)
|
)
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@@ -68,25 +81,19 @@ def profile(request, pk):
|
|||||||
|
|
||||||
# If it's a HTTP POST, we're interested in processing form data.
|
# If it's a HTTP POST, we're interested in processing form data.
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
# Attempt to grab information from the raw form information.
|
|
||||||
# Note that we make use of both UserForm and UserProfileForm.
|
|
||||||
user_form = UserForm(data=request.POST, instance=user)
|
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 the two forms are valid...
|
|
||||||
if user_form.is_valid() and profile_form.is_valid():
|
if user_form.is_valid() and profile_form.is_valid():
|
||||||
|
|
||||||
# Save the user's form data to the database.
|
|
||||||
user = user_form.save()
|
user = user_form.save()
|
||||||
|
|
||||||
# Now sort out the UserProfile instance.
|
|
||||||
# Since we need to set the user attribute ourselves, we set commit=False.
|
|
||||||
# This delays saving the model until we're ready to avoid integrity problems.
|
|
||||||
profile = profile_form.save(commit=False)
|
profile = profile_form.save(commit=False)
|
||||||
profile.user = user
|
profile.user = user
|
||||||
|
|
||||||
# Did the user provide a profile picture?
|
# Did the user provide a profile picture?
|
||||||
# If so, we need to get it from the input form and put it in the UserProfile model.
|
|
||||||
if 'avatar' in request.FILES:
|
if 'avatar' in request.FILES:
|
||||||
profile.avatar = request.FILES['avatar']
|
profile.avatar = request.FILES['avatar']
|
||||||
# Now we save the UserProfile model instance.
|
# Now we save the UserProfile model instance.
|
||||||
@@ -100,15 +107,18 @@ def profile(request, pk):
|
|||||||
if 'avatar-clear' in request.POST:
|
if 'avatar-clear' in request.POST:
|
||||||
if 'on' in request.POST['avatar-clear']:
|
if 'on' in request.POST['avatar-clear']:
|
||||||
image = pjoin(settings.MEDIA_ROOT, img)
|
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):
|
if os.path.isfile(image):
|
||||||
os.remove(image)
|
os.remove(image)
|
||||||
profile.save()
|
profile.save()
|
||||||
|
|
||||||
for item in request.POST:
|
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?
|
# Invalid form or forms - mistakes or something else?
|
||||||
# Print problems to the terminal.
|
# Print problems to the terminal.
|
||||||
@@ -117,8 +127,9 @@ def profile(request, pk):
|
|||||||
print user_form.errors, profile_form.errors
|
print user_form.errors, profile_form.errors
|
||||||
|
|
||||||
return redirect( '/accounts/profile/' + str(user.id) )
|
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:
|
else:
|
||||||
user_form = UserForm(
|
user_form = UserForm(
|
||||||
initial={ 'last_name': user.last_name,
|
initial={ 'last_name': user.last_name,
|
||||||
@@ -135,6 +146,57 @@ def profile(request, pk):
|
|||||||
'img': img}
|
'img': img}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
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]:
|
||||||
|
t = Team(
|
||||||
|
teamID=team['teamID'],
|
||||||
|
name=team['teamName'],
|
||||||
|
iconURL = team['teamIconURL']
|
||||||
|
)
|
||||||
|
|
||||||
|
"""
|
||||||
|
check if object exits and do insert if not
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
to = Team.objects.get(teamID=int(t.teamID))
|
||||||
|
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'),
|
||||||
|
group=int(match['groupID']),
|
||||||
|
matchday=int(match['groupOrderID']),
|
||||||
|
matchday_name=unicode(match['groupName']),
|
||||||
|
idTeam1=Team.objects.get(teamID=int(match['idTeam1'])),
|
||||||
|
idTeam2=Team.objects.get(teamID=int(match['idTeam2'])),
|
||||||
|
pointsTeam1=match['pointsTeam1'],
|
||||||
|
pointsTeam2=match['pointsTeam2'],
|
||||||
|
finished=bool(match['matchIsFinished']),
|
||||||
|
season=match['leagueSaison'],
|
||||||
|
leagueShortcut=match['leagueShortcut']
|
||||||
|
)
|
||||||
|
m.save()
|
||||||
|
|
||||||
|
return redirect("matchday",
|
||||||
|
ls=ls,
|
||||||
|
season=get_current_season(),
|
||||||
|
matchday=str(get_current_md(ls)).zfill(2)
|
||||||
|
)
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def update(request, ls, season, cur_md):
|
def update(request, ls, season, cur_md):
|
||||||
"""
|
"""
|
||||||
@@ -151,43 +213,47 @@ def update(request, ls, season, cur_md):
|
|||||||
matchResults = match['matchResults']
|
matchResults = match['matchResults']
|
||||||
try:
|
try:
|
||||||
for result in matchResults[0]:
|
for result in matchResults[0]:
|
||||||
if result['resultName'] == "Endergebnis":
|
if result['resultName'] == "Halbzeit":
|
||||||
pointsTeam1=int(result['pointsTeam1'])
|
pointsTeam1=int(result['pointsTeam1'])
|
||||||
pointsTeam2=int(result['pointsTeam2'])
|
pointsTeam2=int(result['pointsTeam2'])
|
||||||
elif result['resultName'] == "Halbzeitergebnis":
|
elif result['resultName'] == "Endergebnis":
|
||||||
|
pointsTeam1=int(result['pointsTeam1'])
|
||||||
|
pointsTeam2=int(result['pointsTeam2'])
|
||||||
|
elif str(result['resultName']) == u"nach Verlängerung":
|
||||||
pointsTeam1=int(result['pointsTeam1'])
|
pointsTeam1=int(result['pointsTeam1'])
|
||||||
pointsTeam2=int(result['pointsTeam2'])
|
pointsTeam2=int(result['pointsTeam2'])
|
||||||
except:
|
except:
|
||||||
pointsTeam1=-1
|
pointsTeam1=-1
|
||||||
pointsTeam2=-1
|
pointsTeam2=-1
|
||||||
|
|
||||||
|
|
||||||
m = Match(matchID=unicode(match['matchID']),
|
m = Match(matchID=unicode(match['matchID']),
|
||||||
matchDateTime=datetime.strptime(unicode(match['matchDateTime']), '%Y-%m-%d %H:%M:%S'),
|
matchDateTime=match['matchDateTime'],
|
||||||
group=int(match['groupID']),
|
|
||||||
matchday=int(match['groupOrderID']),
|
|
||||||
idTeam1=Team.objects.get(teamID=int(match['idTeam1'])),
|
|
||||||
idTeam2=Team.objects.get(teamID=int(match['idTeam2'])),
|
|
||||||
pointsTeam1=pointsTeam1,
|
pointsTeam1=pointsTeam1,
|
||||||
pointsTeam2=pointsTeam2,
|
pointsTeam2=pointsTeam2,
|
||||||
finished=bool(match['matchIsFinished']),
|
finished=bool(match['matchIsFinished']),
|
||||||
season=match['leagueSaison'],
|
|
||||||
leagueShortcut=match['leagueShortcut']
|
|
||||||
)
|
)
|
||||||
m.save()
|
m.save(update_fields=['matchDateTime', 'pointsTeam1', 'pointsTeam2', 'finished'])
|
||||||
pointsTeam1=-1
|
pointsTeam1=-1
|
||||||
pointsTeam2=-1
|
pointsTeam2=-1
|
||||||
|
|
||||||
""" evaluate scores """
|
# evaluate scores
|
||||||
scores = Score.objects.get(client=Mandant.objects.get(name='huse'))
|
scores = Score.objects.get(client=Mandant.objects.get(name='huse'))
|
||||||
finished_matches=Match.objects.filter(finished=True)
|
finished_matches=Match.objects.filter(
|
||||||
|
finished=True,
|
||||||
|
leagueShortcut=ls,
|
||||||
|
season=season,
|
||||||
|
matchday = cur_md
|
||||||
|
)
|
||||||
for match in finished_matches:
|
for match in finished_matches:
|
||||||
tipps = Tipp.objects.filter(matchID=match.matchID)
|
tipps = Tipp.objects.filter(matchID=match.matchID)
|
||||||
for tipp in tipps:
|
for tipp in tipps:
|
||||||
score = 0
|
score = 0
|
||||||
goals_total = match.pointsTeam1 + match.pointsTeam2
|
goals_total = match.pointsTeam1 + match.pointsTeam2
|
||||||
|
|
||||||
""" Tipp is acurate """
|
# 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:
|
if goals_total >= 5:
|
||||||
score = scores.exact_high
|
score = scores.exact_high
|
||||||
else:
|
else:
|
||||||
@@ -197,7 +263,7 @@ def update(request, ls, season, cur_md):
|
|||||||
tipp.save()
|
tipp.save()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
""" who won? """
|
# who won?
|
||||||
winnerReal = None
|
winnerReal = None
|
||||||
if match.pointsTeam1 > match.pointsTeam2:
|
if match.pointsTeam1 > match.pointsTeam2:
|
||||||
winnerReal = 1
|
winnerReal = 1
|
||||||
@@ -231,7 +297,11 @@ def update(request, ls, season, cur_md):
|
|||||||
tipp.save()
|
tipp.save()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
return redirect("matchday", ls=ls, season=season, matchday=cur_md)
|
return redirect("matchday",
|
||||||
|
ls=ls,
|
||||||
|
season=season,
|
||||||
|
matchday=str(get_current_md(ls)).zfill(2)
|
||||||
|
)
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def matchday(request, ls, season, matchday, template_name='md.html'):
|
def matchday(request, ls, season, matchday, template_name='md.html'):
|
||||||
@@ -239,21 +309,26 @@ def matchday(request, ls, season, matchday, template_name='md.html'):
|
|||||||
debug += "Debugging: "
|
debug += "Debugging: "
|
||||||
has_refresh = True
|
has_refresh = True
|
||||||
|
|
||||||
""" get matchday closest to current date """
|
""" get matches of the matchday """
|
||||||
md_matches = Match.objects.filter(leagueShortcut=ls, season=season, matchday=int(matchday)).order_by('matchDateTime')
|
md_matches = Match.objects.filter(leagueShortcut=ls, season=season,
|
||||||
|
matchday=int(matchday)).order_by('matchDateTime')
|
||||||
|
|
||||||
""" get the current user """
|
""" get the current user """
|
||||||
user = User.objects.get(username=request.user.username)
|
user = User.objects.get(username=request.user.username)
|
||||||
|
|
||||||
""" get mandants current user is related """
|
""" 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 """
|
""" get mates """
|
||||||
tipp_mates = []
|
mandant_dict = {}
|
||||||
for m in mandants:
|
for m in mandants:
|
||||||
|
mandant = Mandant.objects.get(id=m)
|
||||||
|
mandant_dict[mandant.description] = []
|
||||||
rs = RelUserMandant.objects.filter(mandant=m)
|
rs = RelUserMandant.objects.filter(mandant=m)
|
||||||
|
|
||||||
for r in rs:
|
for r in rs:
|
||||||
tipp_mates.append({
|
mandant_dict[mandant.description].append({
|
||||||
'mate': r.user,
|
'mate': r.user,
|
||||||
'tipps': [],
|
'tipps': [],
|
||||||
'sum_score': 0
|
'sum_score': 0
|
||||||
@@ -270,7 +345,8 @@ def matchday(request, ls, season, matchday, template_name='md.html'):
|
|||||||
check if Tipp already exists
|
check if Tipp already exists
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
tipp = Tipp.objects.get(tipperID=user.id,matchID=match.matchID)
|
tipp = Tipp.objects.get(tipperID=user.id,
|
||||||
|
matchID=match.matchID)
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
tipp = None
|
tipp = None
|
||||||
|
|
||||||
@@ -302,27 +378,33 @@ def matchday(request, ls, season, matchday, template_name='md.html'):
|
|||||||
|
|
||||||
if tipp is not None:
|
if tipp is not None:
|
||||||
f = TippForm(prefix=str(match.matchID),
|
f = TippForm(prefix=str(match.matchID),
|
||||||
initial={'tippTeam1': tipp.pointsTeam1, 'tippTeam2': tipp.pointsTeam2}
|
initial={'tippTeam1': tipp.pointsTeam1,
|
||||||
|
'tippTeam2': tipp.pointsTeam2}
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
f = TippForm(prefix=str(match.matchID))
|
f = TippForm(prefix=str(match.matchID))
|
||||||
|
|
||||||
item = {}
|
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['iconTeam1']= str(match.idTeam1.icon)
|
||||||
|
item['iconURLTeam1'] = str(match.idTeam1.iconURL)
|
||||||
item['nameTeam1']= str(match.idTeam1)
|
item['nameTeam1']= str(match.idTeam1)
|
||||||
item['abbrTeam1']= str(match.idTeam1.abbr)
|
item['abbrTeam1']= str(match.idTeam1.abbr)
|
||||||
item['iconTeam2'] = str(match.idTeam2.icon)
|
item['iconTeam2'] = str(match.idTeam2.icon)
|
||||||
|
item['iconURLTeam2'] = str(match.idTeam2.iconURL)
|
||||||
item['nameTeam2'] = str(match.idTeam2)
|
item['nameTeam2'] = str(match.idTeam2)
|
||||||
item['abbrTeam2']= str(match.idTeam2.abbr)
|
item['abbrTeam2']= str(match.idTeam2.abbr)
|
||||||
item['started'] = match_started
|
item['started'] = match_started
|
||||||
item['finished'] = match.finished
|
item['finished'] = match.finished
|
||||||
|
item['md_name'] = match.matchday_name
|
||||||
|
|
||||||
if (match.pointsTeam1 == -1 or match.pointsTeam2 == -1):
|
if (match.pointsTeam1 == -1 or match.pointsTeam2 == -1):
|
||||||
item['matchResult'] = "-:-"
|
item['matchResult'] = "-:-"
|
||||||
else:
|
else:
|
||||||
item['matchResult'] = str(match.pointsTeam1) + ":" + str(match.pointsTeam2)
|
item['matchResult'] = str(match.pointsTeam1) + ":" \
|
||||||
|
+ str(match.pointsTeam2)
|
||||||
|
|
||||||
item['tippFormTeam1'] = f['tippTeam1']
|
item['tippFormTeam1'] = f['tippTeam1']
|
||||||
item['tippFormTeam2'] = f['tippTeam2']
|
item['tippFormTeam2'] = f['tippTeam2']
|
||||||
@@ -331,11 +413,21 @@ def matchday(request, ls, season, matchday, template_name='md.html'):
|
|||||||
f.fields['tippTeam1'].widget.attrs['disabled'] = True
|
f.fields['tippTeam1'].widget.attrs['disabled'] = True
|
||||||
f.fields['tippTeam2'].widget.attrs['disabled'] = True
|
f.fields['tippTeam2'].widget.attrs['disabled'] = True
|
||||||
|
|
||||||
for mate in tipp_mates:
|
""" get tipps from mates """
|
||||||
|
for mandant in mandant_dict:
|
||||||
|
for mate in mandant_dict[mandant]:
|
||||||
try:
|
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 match_started is True:
|
||||||
mate['tipps'].append(str(matetipp.pointsTeam1) + ":" + str(matetipp.pointsTeam2) + "(" + str(matetipp.score) + ")")
|
if matetipp.score is None:
|
||||||
|
score = u'\u231B'
|
||||||
|
else:
|
||||||
|
score = matetipp.score
|
||||||
|
|
||||||
|
mate['tipps'].append(str(matetipp.pointsTeam1)
|
||||||
|
+ ":" + str(matetipp.pointsTeam2)
|
||||||
|
+ "(" + str(score) + ")")
|
||||||
if match.finished is True:
|
if match.finished is True:
|
||||||
mate['sum_score'] += matetipp.score
|
mate['sum_score'] += matetipp.score
|
||||||
else:
|
else:
|
||||||
@@ -343,50 +435,75 @@ def matchday(request, ls, season, matchday, template_name='md.html'):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
mate['tipps'].append(u'\u2717')
|
mate['tipps'].append(u'\u2717')
|
||||||
|
|
||||||
|
""" sort items in mandant_dict by score """
|
||||||
|
mandant_dict[mandant] = sorted(mandant_dict[mandant],
|
||||||
|
key=lambda k: k['sum_score'], reverse=True)
|
||||||
|
|
||||||
|
|
||||||
matches.append(item)
|
matches.append(item)
|
||||||
|
|
||||||
# get the newest blogposts
|
# get the newest blogposts
|
||||||
|
pm = RelPostMandant.objects.filter(mandant__in=mandants). \
|
||||||
|
values_list('post', flat=True)
|
||||||
posts = []
|
posts = []
|
||||||
for post in Post.objects.filter(published=True)[:2]:
|
for post in Post.objects.filter(id__in=pm, published=True)[:1]:
|
||||||
try:
|
try:
|
||||||
avatar = UserProfile.objects.get(user_id=post.author_id).avatar.name
|
avatar = UserProfile.objects.get(user_id=post.author_id). \
|
||||||
|
avatar.name
|
||||||
except:
|
except:
|
||||||
avatar = None
|
avatar = None
|
||||||
posts.append( (post, avatar) )
|
posts.append( (post, avatar) )
|
||||||
|
|
||||||
|
try:
|
||||||
|
cur_group = matches[0]['md_name']
|
||||||
|
except:
|
||||||
|
cur_group = "N/A"
|
||||||
|
|
||||||
|
debug += str(mandant_dict)
|
||||||
|
|
||||||
return render(request, 'md.html', {
|
return render(request, 'md.html', {
|
||||||
#'debug': debug,
|
'debug': debug,
|
||||||
#'mds_season': mds_in_season,
|
#'mds_season': mds_in_season,
|
||||||
'cur_md': matchday,
|
'cur_md': matchday,
|
||||||
|
'md_name': cur_group,
|
||||||
'matches': matches,
|
'matches': matches,
|
||||||
'ls': ls,
|
'ls': ls,
|
||||||
'season': season,
|
'season': season,
|
||||||
'username': user,
|
'username': user,
|
||||||
'tipp_mates': sorted(tipp_mates, key=lambda k: k['sum_score'], reverse=True),
|
'mandant_dict': mandant_dict,
|
||||||
|
#'tipp_mates': sorted(tipp_mates, key=lambda k: k['sum_score'],
|
||||||
|
#reverse=True),
|
||||||
'posts': posts,
|
'posts': posts,
|
||||||
'has_refresh': has_refresh
|
'has_refresh': has_refresh
|
||||||
})
|
})
|
||||||
|
|
||||||
@login_required
|
@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 = ''
|
debug = ''
|
||||||
|
|
||||||
if pos == 'default':
|
if pos == 'default':
|
||||||
if get_current_md(ls, season) < 18:
|
if get_current_md(ls) < 18:
|
||||||
pos = 'hin'
|
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:
|
else:
|
||||||
pos = 'rueck'
|
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':
|
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':
|
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:
|
else:
|
||||||
matches = Match.objects.filter(leagueShortcut=ls, season=season)
|
matches = Match.objects.filter(leagueShortcut=ls, season=season)
|
||||||
|
|
||||||
# get mandants of current user
|
# 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
|
# main loop
|
||||||
mandant_dict = {}
|
mandant_dict = {}
|
||||||
@@ -394,17 +511,23 @@ def charts(request, ls, season, pos='default', template_name='charts.html'):
|
|||||||
mandant = Mandant.objects.get(id=m)
|
mandant = Mandant.objects.get(id=m)
|
||||||
|
|
||||||
# get users
|
# 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 = {}
|
user_dict = {}
|
||||||
for userid in users:
|
for userid in users:
|
||||||
# get user object, then fetch matches for user
|
# get user object, then fetch matches for user
|
||||||
user = User.objects.get(id=userid)
|
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']
|
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, {
|
return render(request, template_name, {
|
||||||
#'debug': debug,
|
#'debug': debug,
|
||||||
@@ -417,10 +540,17 @@ def charts(request, ls, season, pos='default', template_name='charts.html'):
|
|||||||
@login_required
|
@login_required
|
||||||
def blogindex(request, page):
|
def blogindex(request, page):
|
||||||
# get the blog posts that are published
|
# 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)
|
||||||
|
|
||||||
post_list = []
|
post_list = []
|
||||||
for post in Post.objects.filter(published=True):
|
for post in Post.objects.filter(published=True, id__in=posts):
|
||||||
try:
|
try:
|
||||||
avatar = UserProfile.objects.get(user_id=post.author_id).avatar.name
|
avatar = UserProfile.objects.get(user_id=post.author_id). \
|
||||||
|
avatar.name
|
||||||
except:
|
except:
|
||||||
avatar = None
|
avatar = None
|
||||||
post_list.append( (post, avatar) )
|
post_list.append( (post, avatar) )
|
||||||
@@ -430,13 +560,10 @@ def blogindex(request, page):
|
|||||||
try:
|
try:
|
||||||
posts = p.page(page)
|
posts = p.page(page)
|
||||||
except PageNotAnInteger:
|
except PageNotAnInteger:
|
||||||
# If page is not an integer, deliver first page.
|
|
||||||
posts = p.page(1)
|
posts = p.page(1)
|
||||||
except EmptyPage:
|
except EmptyPage:
|
||||||
# If page is out of range (e.g. 9999), deliver last page of results.
|
|
||||||
posts = p.page(p.num_pages)
|
posts = p.page(p.num_pages)
|
||||||
|
|
||||||
# now return the rendered template
|
|
||||||
return render(request, 'blogindex.html', {
|
return render(request, 'blogindex.html', {
|
||||||
'posts': posts,
|
'posts': posts,
|
||||||
'ls': get_current_ls(),
|
'ls': get_current_ls(),
|
||||||
@@ -444,44 +571,54 @@ def blogindex(request, page):
|
|||||||
'page': page
|
'page': page
|
||||||
})
|
})
|
||||||
|
|
||||||
@login_required
|
|
||||||
def blogpost(request, slug):
|
|
||||||
# get the Post object
|
|
||||||
post = get_object_or_404(Post, slug=slug)
|
|
||||||
# now return the rendered template
|
|
||||||
return render(request, 'blogpost.html', {
|
|
||||||
'post': post,
|
|
||||||
'ls': get_current_ls(),
|
|
||||||
'season': get_current_season()
|
|
||||||
})
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def newBlogpost(request):
|
def newBlogpost(request):
|
||||||
"""
|
debug = ''
|
||||||
if this is a POST request we need to process the form data
|
|
||||||
"""
|
has_mandant = False
|
||||||
|
mandants = RelUserMandant.objects.filter(user=request.user). \
|
||||||
|
values_list('mandant', flat=True)
|
||||||
|
choices = []
|
||||||
|
if mandants.count > 1:
|
||||||
|
has_mandant = True
|
||||||
|
for m in Mandant.objects.filter(id__in=mandants):
|
||||||
|
choices.append( (m.name, m.description) )
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
# create form instance and populate it with data from the request
|
form_bp = BlogpostForm(request.POST)
|
||||||
form = BlogpostForm(request.POST)
|
if has_mandant is True:
|
||||||
# check whether it's valid:
|
form_mandant = MandantsForm(request.POST)
|
||||||
if form.is_valid():
|
form_mandant.fields["mandants"].choices = choices
|
||||||
# process the data
|
|
||||||
# fix me
|
if form_bp.is_valid():
|
||||||
# What to to, if subject is empty?
|
data = form_bp.cleaned_data
|
||||||
data = form.cleaned_data
|
p = Post(author_id=request.user.id, content=data['content'])
|
||||||
slug = slugify(data['title'])
|
|
||||||
p = Post(author_id=request.user.id, slug=slug, title=data['title'], content=data['content'])
|
|
||||||
p.save()
|
p.save()
|
||||||
|
|
||||||
# ...
|
if has_mandant is True and form_mandant.is_valid():
|
||||||
# redirect to a new URL:
|
data = form_mandant.cleaned_data
|
||||||
|
for m in data['mandants']:
|
||||||
|
debug += str(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.save()
|
||||||
|
|
||||||
return redirect( '/blog/1')
|
return redirect( '/blog/1')
|
||||||
|
|
||||||
# if a GET (or any other method) we'll create a blank form
|
|
||||||
else:
|
|
||||||
blogpostForm = BlogpostForm()
|
blogpostForm = BlogpostForm()
|
||||||
|
form_mandant = MandantsForm()
|
||||||
|
form_mandant.fields["mandants"].choices = choices
|
||||||
|
cnt_mandants = len(choices)
|
||||||
|
|
||||||
return render(request, 'newblogpost.html', {
|
return render(request, 'newblogpost.html', {
|
||||||
'form': blogpostForm,
|
'debug': debug,
|
||||||
|
'form_bp': blogpostForm,
|
||||||
|
'form_mandants': form_mandant,
|
||||||
|
'cnt_mandants' : cnt_mandants,
|
||||||
'ls': get_current_ls(),
|
'ls': get_current_ls(),
|
||||||
'season': get_current_season()
|
'season': get_current_season()
|
||||||
})
|
})
|
||||||
@@ -493,20 +630,26 @@ def logout(request):
|
|||||||
logout(request)
|
logout(request)
|
||||||
return HttpResponseRedirect('/')
|
return HttpResponseRedirect('/')
|
||||||
|
|
||||||
def get_current_md(ls,season):
|
def get_current_md(ls):
|
||||||
""" get current matchday """
|
"""
|
||||||
try:
|
get current matchday()
|
||||||
current_md = Match.objects.filter(leagueShortcut=ls, season=season, \
|
returns dict with keys
|
||||||
finished=False).order_by('matchday').values_list('matchday', \
|
['groupName']
|
||||||
flat=True).distinct()[0]
|
['groupOrderID']
|
||||||
except IndexError:
|
['groupID']
|
||||||
current_md = Match.objects.filter(leagueShortcut=ls, season=season).aggregate(Max('matchday'))
|
"""
|
||||||
|
|
||||||
return(current_md)
|
try:
|
||||||
|
ol = OpenLiga()
|
||||||
|
cur_md = ol.getCurrentGroup(ls)
|
||||||
|
except:
|
||||||
|
cur_md = {'groupName': u"1. Spieltag", 'groupOrderID': 1}
|
||||||
|
|
||||||
|
return(cur_md['groupOrderID'])
|
||||||
|
|
||||||
def get_current_ls():
|
def get_current_ls():
|
||||||
return("bl1")
|
return("bl1")
|
||||||
|
|
||||||
def get_current_season():
|
def get_current_season():
|
||||||
return("2015")
|
return("2016")
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
__version__ = '1.0.1'
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ MANAGERS = ADMINS
|
|||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
||||||
'NAME': 'django_tippy',
|
'NAME': 'tippy',
|
||||||
'USER': 'tippy',
|
'USER': 'tippy',
|
||||||
'PASSWORD': 'tippy',
|
'PASSWORD': 'tippy',
|
||||||
'HOST': 'localhost',
|
'HOST': 'localhost',
|
||||||
@@ -73,7 +73,7 @@ MEDIA_URL = '/media/'
|
|||||||
# Don't put anything in this directory yourself; store your static files
|
# Don't put anything in this directory yourself; store your static files
|
||||||
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
|
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
|
||||||
# Example: "/home/media/media.lawrence.com/static/"
|
# Example: "/home/media/media.lawrence.com/static/"
|
||||||
STATIC_ROOT = '/home/martin/dev/tippy/TipPy/static/'
|
STATIC_ROOT = '/home/martin/dev/TipPy/src/static/'
|
||||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
|
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
|
||||||
|
|
||||||
# URL prefix for static files.
|
# URL prefix for static files.
|
||||||
@@ -85,7 +85,7 @@ STATICFILES_DIRS = (
|
|||||||
# Put strings here, like "/home/html/static" or "C:/www/django/static".
|
# Put strings here, like "/home/html/static" or "C:/www/django/static".
|
||||||
# Always use forward slashes, even on Windows.
|
# Always use forward slashes, even on Windows.
|
||||||
# Don't forget to use absolute paths, not relative paths.
|
# Don't forget to use absolute paths, not relative paths.
|
||||||
'/home/martin/dev/tippy/TipPy/tippy/static',
|
'/home/martin/dev/TipPy/src/tippy/static/',
|
||||||
)
|
)
|
||||||
|
|
||||||
# List of finder classes that know how to find static files in
|
# List of finder classes that know how to find static files in
|
||||||
|
|||||||
@@ -8,17 +8,25 @@ admin.autodiscover()
|
|||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
# Examples:
|
# Examples:
|
||||||
url(r'^$', 'tipp.views.home', name='home'),
|
url(r'^$', 'tipp.views.home', name='home'),
|
||||||
url(r'^login$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}),
|
url(r'^login$', 'django.contrib.auth.views.login', {
|
||||||
url(r'^logout$', 'django.contrib.auth.views.logout', {'next_page': '/'}),
|
'template_name': 'login.html'}),
|
||||||
url(r'^update/(?P<ls>.*)/(?P<season>\d{4})/(?P<cur_md>\d{2})$', 'tipp.views.update', name='update'),
|
url(r'^logout$', 'django.contrib.auth.views.logout', {
|
||||||
url(r'^matchday/(?P<ls>.{3,})/(?P<season>\d{4})/(?P<matchday>\d{2})$', 'tipp.views.matchday', name='matchday'),
|
'next_page': '/'}),
|
||||||
url(r'^charts/(?P<ls>\w{3,})/(?P<season>\d{4})$', 'tipp.views.charts', name='charts'),
|
url(r'^getSeason/(?P<ls>.*)/(?P<season>\d{4})$',
|
||||||
url(r'^charts/(?P<ls>\w{3,})/(?P<season>\d{4})/(?P<pos>\w{1,})$', 'tipp.views.charts', name='charts'),
|
'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/profile/(\d+)', 'tipp.views.profile'),
|
||||||
url(r'^accounts/', include('django.contrib.auth.urls')),
|
url(r'^accounts/', include('django.contrib.auth.urls')),
|
||||||
url(r'^blog/newpost$', 'tipp.views.newBlogpost'),
|
url(r'^blog/newpost$', 'tipp.views.newBlogpost'),
|
||||||
url(r'^blog/(?P<page>\d)$', 'tipp.views.blogindex'),
|
url(r'^blog/(?P<page>\d)$', 'tipp.views.blogindex'),
|
||||||
url(r'^blog/(?P<slug>[\w\-]+)', 'tipp.views.blogpost'),
|
url(r'^about$', 'tipp.views.about'),
|
||||||
|
|
||||||
# Uncomment the admin/doc line below to enable admin documentation:
|
# Uncomment the admin/doc line below to enable admin documentation:
|
||||||
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
|
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
|
||||||
|
|||||||
Reference in New Issue
Block a user