Small fixes for Warnings found by PyCharm, mostly spellingerrors.

This commit is contained in:
2023-08-01 14:38:32 +02:00
parent ef00fc25f7
commit c62d2ee010
50 changed files with 294 additions and 385 deletions

View File

@@ -11,15 +11,15 @@ MAX_ARTICLE_ITEMS = 10 # Maximum count of articles in the news RSS feed.
MAX_COMMENT_ITEMS = 40 # Maximum count of comments in the comments RSS feed.
# Start ignoring PyLintBear (R0201)
# noinspection PyMethodMayBeStatic
class LatestNews(Feed):
""" An Feed with the latest news from this site """
link = "http://www.kasu.at/"
description = _("Current news from Kasu")
title = "Kasu - traditonelle asiatische Spielkultur"
link = "http://www.kasu.at/"
title = _("Current news from Kasu")
feed_type = Rss201rev2Feed
def items(self):
def items(self) -> object:
"""get the newest published news articles for the feed."""
return Article.objects.published()[:MAX_ARTICLE_ITEMS]
@@ -77,6 +77,4 @@ class LatestComments(Feed):
return 'From %(user_name)s in %(content_object)s' % {
'user_name': item.user_name,
'content_object': item.content_object
}
# Stop ignoring
}

View File

@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: kasu.content\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-06-09 22:00+0200\n"
"POT-Creation-Date: 2023-07-27 00:05+0200\n"
"PO-Revision-Date: 2018-01-12 15:25+0105\n"
"Last-Translator: b'Christian Berg <kasu@xendynastie.at>'\n"
"Language-Team: Deutsch <>\n"
@@ -210,21 +210,23 @@ msgstr "Teile auf"
msgid "Edit Article"
msgstr "Artikel bearbeiten"
#: templates/content/article_form.html:32 templates/content/page_form.html:42
#: templates/content/article_form.html:24
#: templates/content/article_form.html:31 templates/content/page_form.html:42
#: templates/content/page_form.html:49
msgid "German"
msgstr "Deutsch"
#: templates/content/article_form.html:33 templates/content/page_form.html:43
#: templates/content/article_form.html:25
#: templates/content/article_form.html:39 templates/content/page_form.html:43
#: templates/content/page_form.html:57
msgid "English"
msgstr "Englisch"
#: templates/content/article_form.html:59 templates/content/page_form.html:66
#: templates/content/article_form.html:47 templates/content/page_form.html:66
msgid "reset"
msgstr "Zurücksetzen"
#: templates/content/article_form.html:60 templates/content/page_form.html:67
#: templates/content/article_form.html:48 templates/content/page_form.html:67
msgid "save"
msgstr "Speichern"

View File

@@ -111,6 +111,7 @@ class Article(models.Model):
"""Returns the headline of this article."""
return self.headline
# noinspection PyUnresolvedReferences
@property
def get_image(self):
"""Return the article image, or the category image if unset."""
@@ -169,6 +170,7 @@ class Category(models.Model):
return self.name
# noinspection PyUnresolvedReferences
class Page(models.Model):
"""A page on this homepage. It can have a "static" HTML page, the URL of a
dynamic Django view, or a PDF document.
@@ -317,12 +319,12 @@ class Page(models.Model):
raise ValidationError(
_(u'Please upload a PDF-File to this PDF-Page.'))
def get_absolute_url(self):
def get_absolute_url(self) -> str:
"""Return the path with an extension that matches the content type.
It's useful for an user to match the URL to the contenttype.
It's useful for a user to match the URL to the contenttype.
:return: sting with the absolute URL of this page."""
return '/' + self.path + CONTENT_TYPE_EXTENSIONS[self.content_type]
:return: string with the absolute URL of this page."""
return '/' + str(self.path) + CONTENT_TYPE_EXTENSIONS[self.content_type]
class Meta(object):
"""Set default ordering and an unique priamry key to avoid dupes."""

View File

@@ -8,7 +8,7 @@ class ArticleSitemap(GenericSitemap):
min_priority = 0.25
@staticmethod
def items():
def items(**kwargs):
"""only add published articles to the sitemap"""
return Article.objects.published()
@@ -18,6 +18,6 @@ class PageSitemap(GenericSitemap):
min_priority = 0.5
@staticmethod
def items():
def items(**kwargs):
"""add all pages to the sitemap."""
return Page.objects.all()

View File

@@ -53,10 +53,10 @@
{% block navigation %}
<ul id="navigation">
<li><a href="{{current_top_page.get_absolute_url}}"
{% if not active_category %} class="active" {% endif %}>{% trans 'All Categories' %}</a></li>
class="active">{% trans 'All Categories' %}</a></li>
{% for category in categories %}
<li><a href="{% url 'article-archive' category=category.slug %}"
{% if category.slug == active_category.slug %} class="active"{% endif %}>{{ category.name }}</a></li>
class="active">{{ category.name }}</a></li>
{% endfor %}
</ul>
{% endblock %}

View File

@@ -9,56 +9,44 @@
{% endblock %}
{% block maincontent %}
{% get_fieldset "category, image" from form as fieldset_common %}
{% get_fieldset "headline_de" from form as fieldset_de %}
{% get_fieldset "headline_en" from form as fieldset_en %}
<form action="" method="post" enctype="multipart/form-data">
{{ form.media }} {% csrf_token %}
{{ form.media }} {% csrf_token %}
<fieldset>
<div>
<label for="id_category" class="field_name {{ form.category.css_classes }}">{{ form.category.label}}</label>
{{ form.category }}
{% if form.category.help_text %}<p class="help_text">{{form.category.help_text}}</p>{% endif %}
{% if form.category.errors %}{{ form.category.errors }}{% endif %}
</div>
<div>
<label for="id_image" class="field_name {{ form.image.css_classes }}">{{ form.image.label}}</label>
{{ form.image }}
{% if form.image.help_text %}<p class="help_text">{{form.image.help_text}}</p>{% endif %}
{% if form.image.errors %}{{ form.image.errors }}{% endif %}
</div>
<fieldset>
{% with fieldset_common as form %}{% include "form.html" %}{% endwith %}
</fieldset>
</fieldset>
<ul class="tabs">
<li><a href="#de">{% trans "German" %}</a></li>
<li><a href="#en">{% trans "English" %}</a></li>
</ul>
<ul class="tabs grid_12">
<li><a href="#de">{% trans "German" %}</a></li>
<li><a href="#en">{% trans "English" %}</a></li>
</ul>
<label for="id_{{ form.headline_de.html_name }}" class="fieldname {{ form.headline_de.css_classes }}">
{{ form.headline_de.label }}</label>
<p class="grid_10">{{ form.headline_de }}</p>
<div class="tab_container">
<div id="de" class="tab_content">
<fieldset>
<legend>Deutsch</legend>
<label for="id_{{ form.headline_de.html_name }}" class="fieldname {{ form.headline_de.css_classes }}">
{{ form.headline_de.label }}</label>
<p class="grid_10">{{ form.headline_de }}</p>
</fieldset>
{{ form.content_de }}
<div class="tab_container">
<section id="de" class="tab_content">
<fieldset class="grid_12">
<legend>{% trans "German" %}</legend>
{% with fieldset_de as form %}{% include "form.html" %}{% endwith %}
</fieldset>
<br>
{{form.content_de}}
</section>
<section id="en" class="tab_content">
<fieldset class="grid_12">
<legend>{% trans "English" %}</legend>
{% with fieldset_en as form %}{% include "form.html" %}{% endwith %}
</fieldset>
<br>
{{form.content_en}}
</section>
</div>
<div id="en" class="tab_content">
<h3 class="grid_12">English</h3>
<label for="id_{{ form.headline_en.html_name }}" class="grid_2 {{ form.headline_en.css_classes }}">
{{ form.headline_en.label }}</label>
<p class="grid_10">{{ form.headline_en }}</p>
<p>&nbsp;</p>
{{ form.content_en }}
</div>
</div>
<p class="buttonbar">
<button type="reset"><span class="fa fa-undo"></span> {% trans 'reset' %}</button>
<button type="submit"><span class="fa fa-hdd-o"></span> {% trans 'save' %}</button>
</p>
<p class="buttonbar">
<button type="reset"><span class="fa fa-undo"></span> {% trans 'reset' %}</button>
<button type="submit"><span class="fa fa-hdd-o"></span> {% trans 'save' %}</button>
</p>
</form>{% endblock %}
{% block buttonbar %}{% endblock %}

View File

@@ -1,66 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>{% block title %}{{page.title}}{% endblock %}</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
@font-face {
font-family: 'Amerika Sans';
src: url('{{ STATIC_ROOT }}/fonts/amerika_sans.ttf');
}
@font-face {
font-family: 'Philosopher';
src: url('{{ STATIC_ROOT }}/fonts/philosopher-regular.ttf');
font-weight: normal;
font-style: normal;
}
h1,h2,h3,h4,h5,h6 {
font-family: 'Amerika Sans', Helvetica;
font-variant: small-caps;
font-weight: bold;
margin: 0.5em 0 0.2em 0;
}
body {
font-family: Philosopher;
font-size: 12pt;
}
#page_header {
text-align: right;
}
@page {
margin-right: 0;
margin-bottom: 0;
margin-top: 35mm;
margin-left: 2cm;
@frame header {
-pdf-frame-content : page_header;
top: 0;
margin: 5mm;
height: 4cm;
}
@frame footer {
-pdf-frame-content: page_footer;
bottom: 0cm;
height: 2cm;
margin: 5mm;
}
}
</style>
</head>
<body>
<h1>{{ page.title }}</h1>
{{ page.content }}
<div id="page_header">
<img src="{{STATIC_ROOT}}/img/logo.png" alt="Kasu">
</div>
<div id="page_footer">
{{ page.title }} Seite:
<pdf:pagenumber />
</div>
</body>
</html>

View File

@@ -19,7 +19,7 @@ class WYSIWYGEditorMixin(PermissionRequiredMixin):
@csp_update(SCRIPT_SRC="'unsafe-eval'")
def dispatch(self, request, *args, **kwargs):
"""Add "unsafe-eval" to the Content-Secuirty-Policy HTTP Headers for the
"""Add "unsafe-eval" to the Content-Security-Policy HTTP Headers for the
WYSIWYG Editor.
:param request: the HTTP Request Object
@@ -40,7 +40,7 @@ class ArticleArchiveMixin(object):
Filter the queryset by category if one has been specified in the URL
:param queryset: an model.Article.objects Queryset
:return: an model.Article.objects Queryset filterd by category
:return: an model.Article.objects Queryset filtered by category
"""
category_slug = self.kwargs.get('category')
@@ -90,7 +90,7 @@ class ArticleArchiveIndex(ArticleArchiveMixin, generic.ArchiveIndexView):
class ArticleYearArchive(ArticleArchiveMixin, generic.YearArchiveView):
"""
Displays the Articles filterd by a specific year
Displays the Articles filtered by a specific year
"""
queryset = models.Article.objects.filter(status=models.STATUS_PUBLISHED)
@@ -113,7 +113,7 @@ class ArticleYearArchive(ArticleArchiveMixin, generic.YearArchiveView):
class ArticleMonthArchive(ArticleArchiveMixin, generic.MonthArchiveView):
"""
Displays the Articles filterd by a specific month
Displays the Articles filtered by a specific month
"""
queryset = models.Article.objects.filter(status=models.STATUS_PUBLISHED)
@@ -138,6 +138,7 @@ class ArticleDetail(generic.DetailView):
"""
Render the news Article, but only if it got published.
"""
def get_queryset(self):
queryset = models.Article.objects.filter(status=models.STATUS_PUBLISHED)
queryset = queryset.filter(date_created__year=self.kwargs['year'])
@@ -173,7 +174,7 @@ class ArticleForm(WYSIWYGEditorMixin, generic.UpdateView):
class PageAddForm(WYSIWYGEditorMixin, generic.CreateView):
""" Renders an Form to create a new page for users with conforming
""" Renders a Form to create a new page for users with conforming
permissions."""
form_class = forms.PageForm
@@ -195,7 +196,7 @@ class PageAddForm(WYSIWYGEditorMixin, generic.CreateView):
class PageEditForm(WYSIWYGEditorMixin, generic.UpdateView):
"""Renders an Form to edit a page for users with conforming permissions."""
"""Renders a Form to edit a page for users with conforming permissions."""
form_class = forms.PageForm
model = models.Page
@@ -204,7 +205,7 @@ class PageEditForm(WYSIWYGEditorMixin, generic.UpdateView):
def get_object(self, queryset=None):
""" Get the path from the URL and fetch the corresponding page.
First get the path wihout fileextentsion leading or trailing slashes,
First get the path without file extension leading or trailing slashes,
then search in the database if such a page exists.
:param queryset: Get the single item from this filtered queryset.
@@ -273,9 +274,9 @@ class PagePdf(generic.DeleteView):
def render_to_response(self, context, **response_kwargs):
"""Stream the PDF File to the client and set the right content headers.
:param context: useless only for compatility
:param context: useless only for compatibility
:param response_kwargs: will be added to the HttpResponse kwargs.
:return: an HTTPResponse with PDF Content or an Http404 exception
:return: an HTTPResponse with PDF Content or a Http404 exception
"""
try:
with open(self.object.pdf_file.path, 'rb') as pdf_file:
@@ -285,8 +286,8 @@ class PagePdf(generic.DeleteView):
**response_kwargs
)
return response
except:
raise Http404('File not Found %s.pdf' % self.kwargs['path'])
except FileExistsError:
raise Http404('File %s.pdf not found' % self.kwargs['path'])
class StartPage(generic.TemplateView):
@@ -294,7 +295,7 @@ class StartPage(generic.TemplateView):
template_name = 'index.html'
def get_context_data(self):
""" Adds recent ariticles and recent comments to the context.
""" Adds recent articles and recent comments to the context.
:return: array() with the context data
"""

View File

@@ -1,6 +1,6 @@
"""Django admin interface for the event app.
It's the best way to add eventseries, or edit/delete events."""
It's the best way to add event-series, or edit/delete events."""
from django.contrib import admin
from django.utils.translation import gettext as _
@@ -8,7 +8,7 @@ from events.models import Event, Photo, Location
class EventInline(admin.TabularInline):
"""To list events of an eventseries below the 'master event'"""
"""To list events of an event-series below the 'master event'"""
model = Event
fields = ('name', 'start', 'end')
verbose_name_plural = _('Event Series')

View File

@@ -1,20 +1,20 @@
""" Content processor to display upcoming events on every page you want. """
from django.core.cache import cache
from django.http import HttpRequest
from .models import Event
def events_overview(request): # Ignore PyLintBear (W0613)
def events_overview(request: HttpRequest) -> dict[str, Event]:
"""
Adds event information as variables to the template context on every page.
For speed reasons everything will be cached for an hour. the following
variables will be added to the template context:
* current_event: If an event is running at this moment, the correspondi
event object.
* current_event: If an event is running at this moment, the corresponding event object.
* next_event: the next event that is upcoming.
* upcoming_events: the next 3 events that are upcoming.
:param request: An Django HTTPRequest object
:param request: a Django HTTPRequest object
:return: dict() with the new context variables
"""
current_event = cache.get('current_event', False)

View File

@@ -1,4 +1,3 @@
""" urls for the event gallery part of the events app. """
from django.urls import path
from . import views

View File

@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: kasu.events\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-06-11 10:15+0200\n"
"POT-Creation-Date: 2023-07-26 18:31+0200\n"
"PO-Revision-Date: 2018-01-12 15:25+0105\n"
"Last-Translator: b'Christian Berg <kasu@xendynastie.at>'\n"
"Language-Team: Kasu <verein@kasu.at>\n"
@@ -35,7 +35,7 @@ msgstr "Beginn"
msgid "end"
msgstr "Ende"
#: mixins.py:86
#: mixins.py:87
msgid "Event does not exist"
msgstr "Veranstaltung gibt es nicht"

View File

@@ -1,4 +1,5 @@
"""Mixins for Events."""
from django.core.exceptions import ImproperlyConfigured
from django.db.models import Q
from django.http import Http404
from django.shortcuts import get_object_or_404
@@ -32,8 +33,7 @@ class EventDetailMixin(object):
event = None
def get_context_data(self, **kwargs):
"""Add self.event or the related event of self.object to the template
context.
"""Add this event or the related event of the given object to the template context.
:return: TemplateContext object"""
context = super(EventDetailMixin, self).get_context_data(**kwargs)

View File

@@ -1,4 +1,4 @@
"""Models to solitary events, events series with an location and photos."""
"""Models to solitary events, events series with a location and photos."""
import os
from ckeditor.fields import RichTextField
@@ -16,14 +16,15 @@ from utils import COUNTRIES, OverwriteStorage
from .managers import EventManager
def get_upload_path(instance, filename):
def get_upload_path(instance: models.Model, filename: str) -> str:
"""
Generates the desired file path and filename for an uploaded Image.
With this function Django can save the uploaded images to subfolders that
With this function Django can save the uploaded images to a subfolder that
also have a meaning for humans.
@param instance: an Django Object for which the Image has been uploaded.
@type instance: a instace of an models.Model sub-class.
@return: String: path for the image.
@param instance: a Django Object for which the Image has been uploaded.
@type instance: an instance of a models.Model subclass.
@param filename: The filename of the uploaded image.
@type filename: String
"""
@@ -48,7 +49,7 @@ def get_upload_path(instance, filename):
class Event(models.Model):
"""An Event that could be a tournament, a game session, or an convention."""
"""An Event that could be a tournament, a game session, or a convention."""
name = models.CharField(_('Name'), max_length=255)
description = RichTextField(_("Description"), blank=True)
location = models.ForeignKey('Location', on_delete=models.PROTECT)
@@ -131,7 +132,7 @@ class Event(models.Model):
'year': self.start.strftime('%Y'),
'month': self.start.strftime('%m')
}
return reverse('eventseries-form', kwargs=kwargs)
return reverse('event-series-form', kwargs=kwargs)
def get_edit_url(self):
kwargs = {
@@ -167,7 +168,7 @@ class Event(models.Model):
self.photo_count = self.photo_set.count()
super(Event, self).save(**kwargs)
# Update the Hanchans if necesery:
# Update the Hanchans if necessary:
for hanchan in self.hanchan_set.all():
hanchan.save()
@@ -267,7 +268,7 @@ class Photo(models.Model):
return os.path.basename(self.image.name)
def rotate(self, rotate):
# TODO: Eine vernüftigte Methode ohne viele Abhängigkeiten finden um
# TODO: Eine vernünftige Methode ohne viele Abhängigkeiten finden um
# die Bilder bei Bedarf zu drehen.
if rotate == 'clockwise':
pass

View File

@@ -1,4 +1,3 @@
"""To geneate a Sitemap with all events."""
from kasu.sitemaps import GenericSitemap
from django.utils import timezone
from .models import Event
@@ -6,11 +5,13 @@ from .models import Event
class EventSitemap(GenericSitemap):
"""sitemap to help indexing all events on this site."""
changefreq = "never"
protocol = 'https'
priority_field = 'start'
changefreq: str = "never"
protocol: str = 'https'
priority_field: str = 'start'
@staticmethod
def items():
"""add all upcoming and archived events to the sitemap."""
def items(**kwargs) -> Event:
"""add all upcoming and archived events to the sitemap.
@param **kwargs:
"""
return Event.objects.all()

View File

@@ -58,7 +58,7 @@
<li><span class="fa fa-comments" title="{% trans 'Comments' %}"></span> <a href="{{event.get_absolute_url}}#comments">{{ comment_count }}</a></li>
<li><span class="fa fa-camera-retro" title="{% trans 'Photos' %}"></span> <a href="{% url 'event-photo-list' event.pk %}">{{ event.photo_count }}</a></li>
<li><span class="fa fa-table" title="{% trans 'Hanchans' %}"></span> <a href="{% url 'event-hanchan-list' event.pk %}">{{ event.hanchan_set.count }}</a></li>
<li><span class="fa fa-glass" title="{% trans 'Hanchans' %}"></span> <a href="{% url 'maistar-game-list' event.pk %}">{{ event.maistargame_set.count }}</a></li>
<li><span class="fa fa -glass" title="{% trans 'Hanchans' %}"></span> <a href="{% url 'maistar-game-list' event.pk %}">{{ event.maistargame_set.count }}</a></li>
</ul>
{% if perms.events.change_event %}
<p class="right"><a href="{{ event.get_edit_url }}" class="button"><span class="fa fa-pencil"></span></a></p>
@@ -66,4 +66,5 @@
</div>
{% endfor %}
{% endfor %}
{% block form %}{% endblock %}
{% endblock %}

View File

@@ -10,7 +10,7 @@
{% include "form.html" %}
{% if event.id and event.event_set.count %}
<p class="warning">
<strong>Achtung! Das ist eine Veranstaltungsreihe!</strong> Diese kann man im Moment nur im Admin-Interface vernünfig bearbeiten.<br />
<strong>Achtung! Das ist eine Veranstaltungsreihe!</strong> Diese kann man im Moment nur im Admin-Interface vernünftig bearbeiten.<br />
Du bearbeitest hier den "Hauptevent" der Reihe ({{event.event_set.count}}). Alle Änderungen (abgesehen von Name, Start und Ende) werden von den darauf folgendem Veranstaltungen übernommen.
</p>
{% endif %}

View File

@@ -5,7 +5,7 @@
<form action="" method="post" class="grid_12">
{% csrf_token %}
<header>
<h1 class="grid_12">Dieses Photo wirklich löschen?</h1>
<h1 class="grid_12">Dieses Foto wirklich löschen?</h1>
</header>
<p>Sind Sie sicher, dass Sie das Bild &ldquo;{{photo.name}}&rdquo; löschen wollen?</p>
<img src="{{photo.image|thumbnail_url:'display'}}" alt="{{photo.name}}" title="{{photo.name}}" class="grid_10 push_1"/>

View File

@@ -59,9 +59,6 @@ if ($('a.next').attr('href')) {
<a class="button" href="http://facebook.com/sharer.php?u=http%3A%2F%2Fwww.kasu.at{{photo.get_absolute_url|urlencode}}" target="_blank" rel="nofollow">
<span class="fa fa-twitter"></span>Facebook
</a>
<a class="button" href="https://m.google.com/app/plus/x/?v=compose&amp;content={{photo.headline|urlencode}}+-+http%3A%2F%2Fwww.kasu.at/{{photo.get_absolute_url|urlencode}}" target="_blank" rel="nofollow">
<span class="fa fa-google-plus"></span> Google+
</a>
<a class="button" href="https://twitter.com/share?url=http%3A%2F%2Fwww.kasu.at/{{photo.get_absolute_url|urlencode}}" target='_blank' rel="nofollow">
<span class="fa fa-twitter"></span> Twitter
</a>

View File

@@ -1,46 +1,10 @@
{% extends "base.html" %}
{% extends "events/event_archive.html" %}
{% load i18n comments thumbnail %}
{% block maincontent %}
{% for event in event_list %}
{% get_comment_count for event as comment_count %}
{% ifchanged %}<h3 class="grid_12">{{ event.start|date:'F Y' }}</h3>{% endifchanged %}
<div style="float:left">
<a href="{% url 'event-photo-list' event.pk %}"><img src="{{ event.get_image|thumbnail_url:'thumbnail' }}" alt="" class="thumbnail"/></a>
<div class="grid_4" />
<h4><a href="{% url 'event-photo-list' event.pk %}">{{ event.name }}</a></h4>
<div class="info">
<span class="fa fa-calendar-o" title="{% trans 'Start' %}"></span>
{{ event.start|date }}
{% if event.end %}
{% trans "from" %} {{ event.start|time:'H:i' }} {% trans "to" %} {{ event.end|time:'H:i' }}
{% else %}
{{ event.start|time:'H:i' }}
{% endif %}
</div>
{% if event.description %}<p>{{event.description}}</p>{% endif %}
<div class="info">
<span class="fa fa-map-marker" title="{% trans 'Location' %}"></span>
{{ event.location }}
<span class="fa fa-comments" title="{% trans 'Comments' %}"></span>
<a href="{{event.get_absolute_url}}#comments">{{ comment_count }} {% trans 'Comments' %}</a>
<span class="fa fa-camera-retro" title="{% trans 'Photos' %}"></span>
<a href="{% url 'event-photo-list' event.pk %}">{{ event.photo_count }} {% trans 'Photos' %}</a>
</div>
<p style="text-align:right">
{% if perms.events.add_photo %}
<a href="{% url 'event-photo-list' event.pk %}" class="button">
<span class="fa fa-cloud-upload"></span>
{%trans "Upload" %}</a>
{% endif %}
</p>
</div>
{% endfor %}
{% block bottom %}
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
<fieldset class="grid_8 push_2">
<fieldset id="bottom_buttonbar" class="grid_12">
<legend>Photos hochladen</legend>
{% include "form.html" %}
<p class="buttonbar">
@@ -52,5 +16,5 @@
</fieldset>
</form>
{% endblock %}
{% block buttonbar %}
{% endblock %}

View File

@@ -1,20 +1,19 @@
"""
This file should test the functionality of the events app using the unittest
module. These will pass when you run "manage.py test".
Usefull tests have to been written yet. sorry!
useful tests have to be written yet. sorry!
"""
from django.test import TestCase
class EventTest(TestCase):
""" Here we should test the creation and modifiaction of Events. """
""" Here we should test the creation and modification of Events. """
class LocationTest(TestCase):
""" Here we should test the creation and modifiaction of Locations. """
""" Here we should test the creation and modification of Locations. """
class PhotoTest(TestCase):
""" Here we should test the creation and modifiaction of Photos. """
""" Here we should test the creation and modification of Photos. """

View File

@@ -8,7 +8,7 @@ urlpatterns = [
path('<int:year>/', views.EventArchiveYear.as_view(), name='event-archive'),
path('<int:year>/<int:month>/', views.EventArchiveMonth.as_view(), name='event-archive'),
path('<int:year>/<int:month>/<int:pk>/', views.EventDetail.as_view(), name='event-detail'),
path('<int:year>/<int:month>/<int:pk>/add_dates/', views.EventSeriesForm.as_view(), name='eventseries-form'),
path('<int:year>/<int:month>/<int:pk>/add_dates/', views.EventSeriesForm.as_view(), name='event-series-form'),
path('<int:year>/<int:month>/<int:pk>/edit/', views.EventForm.as_view(), name='event-form'),
path('add/', views.EventForm.as_view(), name='event-form'),
path('archive/', views.EventArchiveIndex.as_view(), name='event-archive'),

View File

@@ -50,19 +50,15 @@ class EventDetail(mixins.EventDetailMixin, generic.DetailView):
class EventForm(PermissionRequiredMixin, mixins.EventDetailMixin,
generic.UpdateView):
"""Frontend formular to add or edit a Event."""
"""Frontend formular to add or edit an Event."""
form_class = forms.EventForm
template_name = 'events/event_form.html'
permission_required = 'events.add_event'
def get_context_data(self, **kwargs):
"""Dynamicle set the title to Add or Edit Event, depanding if an
event ID was given, or not."""
"""set the title to add or edit Event, depending on the fact if an event ID was given."""
context = super(EventForm, self).get_context_data(**kwargs)
if self.kwargs.get('pk'):
context['title'] = _("Edit Event")
else:
context['title'] = _("Add Event")
context['title'] = _("Edit Event") if self.kwargs.get('pk') else _("Add Event")
return context
def get_object(self, queryset=None):
@@ -74,7 +70,7 @@ class EventForm(PermissionRequiredMixin, mixins.EventDetailMixin,
class EventGallery(generic.ListView):
"""Display a overview of all event photo albums."""
"""Display an overview of all event photo albums."""
template_name = 'events/photo_gallery.html'
paginate_by = 24
@@ -89,7 +85,7 @@ class EventGallery(generic.ListView):
class EventListIcal(generic.View):
"""Generates an returns an iCal File with all upcoming events."""
"""Generates and returns an iCal File with all upcoming events."""
def get(self, request, *args, **kwargs):
"""Add all upcoming events to an .ics file and send it."""
@@ -132,7 +128,7 @@ class EventPhoto(mixins.EventPhotoMixin, generic.UpdateView):
class EventPhotoList(mixins.EventPhotoMixin, generic.ListView):
"""List all Photos of the event or event series in an album."""
"""List all Photos of the event or event series."""
context_object_name = 'photo_list'
event = None
paginate_by = 36

View File

@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: kasu.utils\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-07-20 21:25+0200\n"
"POT-Creation-Date: 2023-07-26 18:31+0200\n"
"PO-Revision-Date: 2018-12-30 11:14+0105\n"
"Last-Translator: b' <kasu@xendynastie.at>'\n"
"Language-Team: Kasu <verein@kasu.at>\n"
@@ -215,11 +215,11 @@ msgstr "Besuche uns auf"
msgid "Add Article"
msgstr "Artikel hinzufügen"
#: templates/paginator.html:8
#: templates/paginator.html:7
msgid "Previous"
msgstr "Vorherige"
#: templates/paginator.html:20
#: templates/paginator.html:18
msgid "Next"
msgstr "Nächste"

View File

@@ -37,7 +37,7 @@
{% block extra_head %}{% endblock %}
<script src="{{ STATIC_URL }}js/piwik.js"></script>
</head>
<body id="body" {% block itemscope %}{% endblock %}>
<body id="body" itemscope>
<header id="siteheader">
<div id="sitelogo"><a href="/index.html">Kasu - traditionelle asiatische Spielkultur</a></div>
<nav id="mainnav">
@@ -51,7 +51,7 @@
<ul class="main_dropdown">
{% for subpage in item.subpages.all %}<li><a
href="{{subpage.get_absolute_url}}"
{% if subpage == current_page %}class="active"{% endif %}>{{subpage.menu_name}}</a></li>
>{{subpage.menu_name}}</a></li>
{% endfor %}
</ul>
{% endif %}
@@ -142,20 +142,21 @@
{% endblock %}
{% block comments %}{% endblock %}
<br class="clear"/>
<p id="bottom_buttonbar" class="buttonbar">
{% block bottom %}
<div id="bottom_buttonbar" class="buttonbar">
{% block buttonbar %}
{% if current_page and perms.content.add_page %}
<a href="{% url 'add-page' current_page.path %}" class="button"><span class="fa fa-plus"></span>
{% trans "Add Subpage" %}</a>
{% endif %}
{% if current_page and perms.content.change_page %}
<a href="{% url 'edit-page' current_page.path %}" class="button"><span class="fa fa-pencil"></span>
{% trans "Edit Page" %}</a>
{% endif %}
{% block additional_buttonbar %}{% endblock %}
{% endblock %}
</p>
</div>
{% endblock %}
</main>
<footer id="footer">
<p><strong>Herausgeber:</strong> Verein Kasu - traditionelle asiatische Spielkultur (<a
@@ -169,8 +170,8 @@
<select name="language" id="language">
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<option value="{{language.code}}" {% if language.code == LANGUAGE_CODE %}
selected="selected" {% endif %}>{{ language.name_local }} ({{ language.code }})
<option value="{{language.code}}"
selected="selected">{{ language.name_local }} ({{ language.code }})
</option>
{% endfor %}
</select>

View File

@@ -16,7 +16,7 @@
</div>
<header class="comment_header">
<a href="{{ user.get_profile.get_absolute_url }}" class="user">{{comment.user}}</a>
<div class="submit_date"><time time="{% now 'c' %}">{% now 'DATETIME_FORMAT' %}</time></div>
<div class="submit_date"><time>{% now 'DATETIME_FORMAT' %}</time></div>
</header>
<div class="comment_text">{{comment}}</div>
</article>

View File

@@ -1 +1,2 @@
<input type="{{ type|default:'text' }}" name="{{ widget.name }}"{% if widget.value != None %} value="{{ widget.value|stringformat:'s' }}"{% endif %}{% include "django/forms/widgets/attrs.html" %} />
<input type="{{ type|default:'text' }}" name="{{ widget.name }}"
value="{{ widget.value|stringformat:'s' }}" "django/forms/widgets/attrs.html" %} />

View File

@@ -2,7 +2,7 @@
{% for hidden in form.hidden_fields %}{{ hidden }}{% endfor %}
{% for field in form.visible_fields %}
<div>
<label {% if field.html_name != 'recaptcha' %} for="id_{{ field.html_name}}" {% endif %}
<label for="id_{{ field.html_name}}"
class="field_name {{ field.css_classes }}">{{ field.label}}</label>
{{ field }}
{% if field.field.widget.input_type == 'checkbox' %}

View File

@@ -1,22 +1,22 @@
{% load i18n %}
<nav class="grid_12 pagination">
<a {% if page_obj.has_previous %}
class="previous" href="?page={{ page_obj.previous_page_number }}"
{% else %}
class="previous disabled"
{% endif %}>
<span class="fa fa-arrow-left"></span>{% trans "Previous" %}
</a>
{% if page_obj.has_previous %}
<a class="previous" href="?page={{ page_obj.previous_page_number }}"><span class="fa fa-arrow-left"></span>
{% trans "Previous" %}</a>
{% else %}
<a class="previous disabled"><span class="fa fa-arrow-left"></span>{% trans "Previous" %}</a>
{% endif %}
{% for page in paginator.page_range %}
<a {% if page_obj.number == page %}class="active"{% else %}href="?page={{page}}"{% endif %}>{{page}}</a>
{% if page_obj.number == page %}
<a class="active">{{page}}</a>
{% else %}
<a href="?page={{page}}">{{page}}</a>
{% endif %}
{% endfor %}
<a {% if page_obj.has_next %}
class="next" href="?page={{ page_obj.next_page_number }}"
{% else %}
class="next disabled"
{% endif %}>
{% trans "Next" %} <span class="fa fa-arrow-right"></span>
</a>
{% if page_obj.has_next %}
<a class="next" href="?page={{ page_obj.next_page_number }}">{% trans "Next" %}
<span class="fa fa-arrow-right"></span></a>
{% else %}
<a class="next disabled">{% trans "Next" %} <span class="fa fa-arrow-right"></span></a>
{% endif %}
</nav>

View File

@@ -20,7 +20,7 @@ admin.autodiscover()
sitemaps = {
'event_rankings': EventRankingSitemap,
'event_hanchans': EventHanchanSitemap,
'mahjong_seasons': MajongSeasonSitemap,
'mahjong_seasons': MahjongSeasonSitemap,
'maistar_games': MaistarGamesSitemap,
'articles': ArticleSitemap,
'events': EventSitemap,

View File

@@ -1,4 +1,4 @@
""" Adds management of the mahong ranking system to the admin interface. """
""" Adds management of the mahjong ranking system to the admin interface. """
from django.contrib import admin
from django.utils.translation import gettext as _
@@ -36,14 +36,14 @@ def confirm(modeladmin, request, queryset): # Ignore PyLintBear (W0613)
confirm.short_description = _("Confirm")
def unconfirm(modeladmin, request, queryset): # Ignore PyLintBear (W0613)
def reject(modeladmin, request, queryset): # Ignore PyLintBear (W0613)
"""An admin action to quickly set selected hanchans to unconfirmed. """
for hanchan in queryset:
hanchan.confirmed = False
hanchan.save()
unconfirm.short_description = _('Set unconfirmed')
reject.short_description = _('Reject')
class EventRankingAdmin(admin.ModelAdmin):
@@ -57,7 +57,7 @@ class EventRankingAdmin(admin.ModelAdmin):
class HanchanAdmin(admin.ModelAdmin):
""" To administrate the stored Hanchans. """
actions = [recalculate, confirm, unconfirm]
actions = [recalculate, confirm, reject]
date_hierarchy = 'start'
list_filter = ('season', 'event', 'confirmed')
search_fields = ('player_names',)

View File

@@ -64,7 +64,7 @@ class HanchanAdminForm(HanchanForm):
""" Extends the HanchanForm for users with admin privileges.
They are allowed to confirm/unconfirm Hanchans, this could be userful if
one games smells fishy and needs the opinion of an referee."""
one games smells fishy and needs the opinion of a referee."""
class Meta(object):
""" Extend the formfields to add the confirmed checkbox. """

View File

@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: kasu.mahjong_ranking\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-07-20 21:25+0200\n"
"POT-Creation-Date: 2023-07-27 00:05+0200\n"
"PO-Revision-Date: 2018-05-08 00:20+0105\n"
"Last-Translator: b'Christian Berg <kasu@xendynastie.at>'\n"
"Language-Team: Kasu <verein@kasu.at>\n"

View File

@@ -1,4 +1,4 @@
"""Export Mahjong Rankings as excel files."""
"""Export Mahjong Rankings as Excel files."""
import os
from datetime import date, time, datetime

View File

@@ -74,12 +74,13 @@ class HanchanManager(models.Manager):
[hanchan.get_playerdata(user) for hanchan in queryset]
return queryset
def season_hanchans(self, user=None, season=None, until=None):
def season_hanchans(self, user: object = None, season: int = None, until: date = None):
"""Return all Hanchans that belong to a given or the current season.
:param user: Only return Hanchans where this user participated.
:param season: the year of the wanted season, current year if None.
:return: QuerySet Object
:param season: the year of the wanted season, current year if None.
:param until: only return hanchans played until the given date.
:return: QuerySet Object
"""
try:
season = season or until.year
@@ -92,6 +93,7 @@ class HanchanManager(models.Manager):
:param user: Return Hanchans where this user participated.
:param since: only return Hanchans played since the given datetime
:param until: only return hanchans played until the given date.
:param filter_args: To add specific arguments to the Django filter.
:return: a QuerySet Object
"""
@@ -199,10 +201,8 @@ class SeasonRankingManager(models.Manager):
class KyuDanRankingManager(models.Manager):
def json_data(self):
""" Get all Rankings for a given Season and return them as a list of
dict objects, suitable for JSON exports and other processings.
:param season: Season that should be exported, current season if empty
:return: a list() of dict() objects suiteable for JSON export.
dict objects, suitable for JSON exports and other processing.
:return: a list() of dict() objects suitable for JSON export.
"""
json_data = list()
values = self.all()

View File

@@ -48,11 +48,11 @@ class EventRanking(models.Model):
def recalculate(self):
"""
Berechnet die durschnittliche Platzierung und Punkte, u.v.m. neu.
Berechnet die durchschnittliche Platzierung und Punkte, u.v.m. neu.
Diese Daten werden benötigt um die Platzierung zu erstellen. Sie
Diese Daten werden benötigt, um die Platzierung zu erstellen. Sie
können zwar sehr leicht errechnet werden, es macht trotzdem Sinn
sie zwischen zu speichern.
sie zwischenzuspeichern.
"""
LOGGER.info(
u'Recalculate EventRanking for Player %s in %s',
@@ -291,9 +291,8 @@ class Hanchan(models.Model):
self.bonus_points = getattr(self, '%s_bonus_points' % player)
self.player_comment = getattr(self, '%s_comment' % player)
def update_playerdata(self, user, **kwargs):
"""i small workaround to access score, placement of a specific user
prominent from a in the user templates"""
def update_player_data(self, user, **kwargs):
"""to access scores and placement of a specific user from templates"""
for player in ('player1', 'player2', 'player3', 'player4'):
if getattr(self, player) == user:
setattr(self, '%s_input_score' % player, self.input_score)
@@ -423,7 +422,7 @@ class KyuDanRanking(models.Model):
def append_tournament_bonuspoints(self, hanchan):
"""
Prüft ob es die letzte Hanchan in einem Turnier war. Wenn ja werden
Prüft, ob es die letzte Hanchan in einem Turnier war. Wenn ja, werden
bei Bedarf Bonuspunkte vergeben, falls der Spieler das Turnier
gewonnen hat.
:param hanchan: Ein Player Objekt
@@ -525,7 +524,7 @@ class KyuDanRanking(models.Model):
self.append_tournament_bonuspoints(hanchan)
self.update_rank()
self.append_3_in_a_row_bonuspoints(hanchan)
hanchan.update_playerdata(self.user)
hanchan.update_player_data(self.user)
hanchan.save(recalculate=False)
self.won_hanchans += 1 if hanchan.placement == 1 else 0
self.good_hanchans += 1 if hanchan.placement == 2 else 0
@@ -536,7 +535,7 @@ class KyuDanRanking(models.Model):
"""
Berechne die Kyu bzw. Dan Punkte für eine Hanchan neu.
:type hanchan: Hanchan
:param hanchan: Das Player Objekt das neuberechnet werden soll.
:param hanchan: das Player-Objekt, welches neu berechnet werden soll.
"""
hanchan.kyu_points = None
hanchan.dan_points = None

View File

@@ -11,38 +11,42 @@ from .models import SeasonRanking
class EventRankingSitemap(GenericSitemap):
@staticmethod
def items():
"""add all upcoming and archived events to the sitemap."""
def items(**kwargs):
"""add all upcoming and archived events to the sitemap.
@param **kwargs:
"""
return Event.objects.all().exclude(eventranking=None)
@staticmethod
def location(event):
def location(event, **kwargs):
return reverse('event-ranking', kwargs={'event': event.id})
class EventHanchanSitemap(GenericSitemap):
@staticmethod
def items():
"""add all upcoming and archived events to the sitemap."""
def items(**kwargs):
"""add all upcoming and archived events to the sitemap.
@param **kwargs:
"""
return Event.objects.all().exclude(eventranking=None)
@staticmethod
def location(event):
def location(event, **kwargs):
return reverse('event-hanchan-list', kwargs={'event': event.id})
class MajongSeasonSitemap(Sitemap):
class MahjongSeasonSitemap(Sitemap):
priority = 0.5
@staticmethod
def items():
def items(**kwargs):
seasons = SeasonRanking.objects.all().distinct('season').order_by(
'season')
seasons = seasons.values_list('season', flat=True)
return seasons
@staticmethod
def location(season):
def location(season, **kwargs):
return reverse('mahjong-ladder', kwargs={'season': season})
@staticmethod

View File

@@ -18,7 +18,7 @@
<fieldset class="hanchan">
{% for hidden in form.hidden_fields %} {{ hidden }} {% endfor %}
<p>
<label for="id_{{ form.start.html_name }}_0" class="field_name {{ form.start.css_classes }}">{{ form.start.label }}:</label>
<label for="{{ form.start.if_for_label }}" class="field_name {{ form.start.css_classes }}">{{ form.start.label }}:</label>
{{ form.start }}
{{ form.start.errors }}
</p>

View File

@@ -33,7 +33,7 @@
<legend>{% trans "Delete Hanchan" %}</legend>
{% include 'form.html' %}
<label class="field_name fa fa-exclamation-triangle fa-5x fa-pull-left" ></label>
<p>Bist du sicher dass du diese Hanchan und alle Ergebnisse und Wertungen welche sich hierauf beziehen löschen möchtest?</p>
<p>Bist du sicher, dass du diese Hanchan und alle Ergebnisse und Wertungen, welche sich hierauf beziehen löschen möchtest?</p>
<br class="clear">
<p class="buttonbar">
<button type="button" onclick="window.history.back()"><span class="fa fa-close"></span> {% trans 'Cancel' %}</button>

View File

@@ -31,7 +31,7 @@
{% for season_link in season_list%}
<option
value="{% url 'mahjong-ladder' season_link %}"
{% if season == season_link %} selected="selected"{% endif %}>{{ season_link }}
selected="selected">{{ season_link }}
</option>
{% endfor %}
</select>

View File

@@ -52,7 +52,7 @@
</table>
{% if kyu_dan_ranking.legacy_date %}
<p><strong>Frühere Dan Punkte vom {{ kyu_dan_ranking.legacy_date|date }}:</strong> {{kyu_dan_ranking.legacy_dan_points }}</p>
<p><strong>Frühere Dan Punkte vom {{kyu_dan_ranking.legacy_date|date}}:</strong> {{kyu_dan_ranking.legacy_dan_points}}</p>
{% endif %}
{% endblock %}

View File

@@ -64,8 +64,8 @@
<select id="season" name="season" size="1">
{% for season_link in season_list%}
<option
{% if season == season_link %} selected="selected"{% endif %}
value="{{ season_link }}">{{ season_link }}</option>
selected="selected"
value="{{ season_link }}">{{ season_link }}</option>
{% endfor %}
</select>
<button type="submit">{% trans 'Go' %}</button>
@@ -75,5 +75,5 @@
{% endblock %}
{% block buttonbar %}
<a href="?download=xlsx" class="button"><span class="fa fa-table"></span> Download</a>
{% endblock %}
<a href="?download=xlsx{% if season %}&season={{ season }}{% endif %}" class="button"><span class="fa fa-table"></span> Download</a>
{% endblock %}

View File

@@ -50,7 +50,7 @@
{% empty %}
<tr>
<td colspan="8">Leider hat es noch niemand in das Ranking geschafft.
Ein Spieler wird erst ins Ranking genommen wenn er 5 Hanchans absolviert hat.
Spieler werden erst ins Ranking genommen, wenn sie 5 Hanchans absolviert haben.
</td>
</tr>
{% endfor %}

View File

@@ -45,7 +45,7 @@ def get_kyu_dan_ranking(user=None):
class DeleteHanchan(EventDetailMixin, PermissionRequiredMixin,
generic.DeleteView):
"""Deletes a Hanchan if confimration has been answerd with 'yes'."""
"""Deletes a Hanchan if confirmation has been answered with 'yes'."""
form_class = forms.HanchanForm
model = models.Hanchan
permission_required = 'mahjong_ranking.delete_hanchan'
@@ -53,7 +53,7 @@ class DeleteHanchan(EventDetailMixin, PermissionRequiredMixin,
def get_success_url(self):
"""
Return to the HachanList of the event form the deleted hanchan.
Return to the HanchanList of the event form the deleted hanchan.
:return: URL of the EventHanchanList for the event
"""
return reverse('event-hanchan-list',
@@ -71,7 +71,7 @@ class HanchanForm(SuccessMessageMixin, EventDetailMixin,
def get_form_class(self):
"""
Users with hanchan edit persmission can also un-/confirm hanchans.
Users with hanchan edit permission can also un-/confirm a Hanchan.
:return: forms.HanchanForm, or forms.HanchanAdminForm
"""
return forms.HanchanAdminForm if self.request.user.has_perm(
@@ -123,27 +123,27 @@ class HanchanForm(SuccessMessageMixin, EventDetailMixin,
class EventHanchanForm(EventDetailMixin, PermissionRequiredMixin,
generic.TemplateView):
"""Display a Formset to add and Edit Hanchans of the specific Event."""
formset: forms.HanchanFormset
permission_required = 'mahjong_ranking.add_hanchan'
template_name = 'mahjong_ranking/eventhanchan_form.html'
model = models.Hanchan
def get_context_data(self, **kwargs):
self.event = models.Event.objects.get(pk=self.kwargs['event'])
self.formset = forms.HanchanFormset(
instance=self.event,
initial=[{'start': self.event.start}]
)
context = super(EventHanchanForm, self).get_context_data()
context['formset'] = self.formset
return context
def get(self, request, *args, **kwargs):
self.get_queryset()
self.formset = forms.HanchanFormset(
instance=self.event,
initial=[{'start': self.event.start}]
)
context = self.get_context_data(**kwargs)
return self.render_to_response(context)
def post(self, request, *args, **kwargs):
print("ICH WURDE GEPOSTET!!!!")
self.get_queryset()
self.formset = forms.HanchanFormset(
self.request.POST,
@@ -172,9 +172,9 @@ class EventRankingList(EventDetailMixin, generic.ListView):
class KyuDanRankingList(MahjongMixin, generic.ListView):
"""List all Players with an Kyu or Dan score. """
"""List all Players with a Kyu or Dan score. """
order_by = None
paginate_by = 25
paginate_by = 100
def dispatch(self, request, *args, **kwargs):
"""Set the order_by settings, revert to default_order if necessary."""
@@ -192,7 +192,7 @@ class KyuDanRankingList(MahjongMixin, generic.ListView):
class SeasonRankingList(MahjongMixin, generic.ListView):
model = models.SeasonRanking
paginate_by = 25
paginate_by = 100
season = None
def get_queryset(self):
@@ -205,18 +205,23 @@ class SeasonRankingList(MahjongMixin, generic.ListView):
class PlayerScore(LoginRequiredMixin, generic.ListView):
paginate_by = 25
paginate_by: int = 100
user = auth.get_user_model()
kyu_dan_ranking = None
season = None
def get(self, request, *args, **kwargs):
user_model = auth.get_user_model()
try:
self.user = user_model.objects.get(
username=self.kwargs.get('username'))
self.kyu_dan_ranking = get_kyu_dan_ranking(user=self.user)
self.season = int(self.request.GET.get('season', date.today().year))
except user_model.DoesNotExist:
raise django.http.Http404(
_("No user found matching the name {}").format(
self.kwargs.get('username')))
if request.GET.get('download') == 'xlsx':
return self.get_xlsx(request, *args, **kwargs)
return super(PlayerScore, self).get(request, *args, **kwargs)
@@ -228,7 +233,7 @@ class PlayerScore(LoginRequiredMixin, generic.ListView):
context['kyu_dan_ranking'] = models.KyuDanRanking.objects.get(
user=self.user)
except models.KyuDanRanking.DoesNotExist:
context['ranking'] = None
context['kyu_dan_ranking'] = None
try:
context['ladder_ranking'] = models.SeasonRanking.objects.get(
user=self.user,
@@ -238,27 +243,31 @@ class PlayerScore(LoginRequiredMixin, generic.ListView):
return context
def get_xlsx(self, request, *args, **kwargs):
self.object_list = self.get_queryset()
response = django.http.HttpResponse(
content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
response['Content-Disposition'] = 'attachment; ' \
'filename="{xlsx_filename}"'.format(
xlsx_filename=self.xlsx_filename)
xlxs_workbook = xlsx.Workbook()
xlxs_workbook.generate_sheet(
response['Content-Disposition'] = f'attachment; filename="{self.xlsx_filename}"'
xlsx_workbook = xlsx.Workbook()
xlsx_workbook.generate_sheet(
title=self.xlsx_filename.split('.')[0],
columns_settings=self.xlsx_columns,
object_list=self.object_list
object_list=self.get_queryset()
)
xlxs_workbook.save(response)
xlsx_workbook.save(response)
return response
@property
def xlsx_columns(self):
return {}
@property
def xlsx_filename(self):
return ""
class PlayerDanScore(PlayerScore):
template_name = 'mahjong_ranking/player_dan_score.html'
def get_queryset(self):
self.kyu_dan_ranking = get_kyu_dan_ranking(user=self.user)
return models.Hanchan.objects.dan_hanchans(
user=self.user,
since=self.kyu_dan_ranking.legacy_date)
@@ -298,17 +307,20 @@ class PlayerDanScore(PlayerScore):
@property
def xlsx_filename(self):
return "{username}_dan_score.xlsx".format(username=self.user.username)
return f"{self.user.username}_dan_score.xlsx"
class PlayerInvalidScore(PlayerScore):
template_name = 'mahjong_ranking/player_invalid_score.html'
def get_queryset(self):
self.xlsx_filename = "{username}_invalid_score.xlsx".format(
username=self.user.username)
return models.Hanchan.objects.unconfirmed(user=self.user)
@property
def xlsx_filename(self):
return f"{self.user.username}_invalid_score.xlsx"
class PlayerKyuScore(PlayerScore):
template_name = 'mahjong_ranking/player_kyu_score.html'
@@ -354,7 +366,7 @@ class PlayerKyuScore(PlayerScore):
@property
def xlsx_filename(self):
return "{username}_kyu_score.xlsx".format(username=self.user.username)
return f"{self.user.username}_kyu_score.xlsx"
class PlayerLadderScore(PlayerScore):
@@ -370,7 +382,6 @@ class PlayerLadderScore(PlayerScore):
return context
def get_queryset(self, **kwargs):
self.season = int(self.request.GET.get('season', date.today().year))
hanchan_list = models.Hanchan.objects.season_hanchans(
user=self.user,
season=self.season
@@ -408,7 +419,4 @@ class PlayerLadderScore(PlayerScore):
@property
def xlsx_filename(self):
return "{username}_ladder_score_{season}.xlsx".format(
username=self.user.username,
season=self.season
)
return f"{self.user.username}_ladder_{self.season}_score.xlsx"

View File

@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: kasu.mahjong_ranking\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-06-09 22:00+0200\n"
"POT-Creation-Date: 2023-07-26 18:31+0200\n"
"PO-Revision-Date: 2016-09-28 00:24+0200\n"
"Last-Translator: Christian Berg <xeniac.at@gmail.com>\n"
"Language-Team: Kasu <verein@kasu.at>\n"
@@ -79,6 +79,30 @@ msgstr "Saison"
msgid "Mai-Star Game with {0} from {1:%Y-%m-%d}"
msgstr "Mai-Star Spiel mit {0} vom {1:%Y-%m-%d}"
#: templates/maistar_ranking/game_confirm_delete.html:4
#: templates/maistar_ranking/game_confirm_delete.html:9
msgid "Delete game"
msgstr "Spiel löschen"
#: templates/maistar_ranking/game_confirm_delete.html:12
#: templates/maistar_ranking/game_list.html:14
msgid "Place"
msgstr "Platz"
#: templates/maistar_ranking/game_confirm_delete.html:18
#: templates/maistar_ranking/game_list.html:19
#: templates/maistar_ranking/player_game_list.html:36
msgid "Points"
msgstr "Punkte"
#: templates/maistar_ranking/game_confirm_delete.html:23
msgid "Cancel"
msgstr "Abbrechen"
#: templates/maistar_ranking/game_confirm_delete.html:25
msgid "Delete"
msgstr "Löschen"
#: templates/maistar_ranking/game_form.html:5
#: templates/maistar_ranking/game_form.html:16
#: templates/maistar_ranking/game_list.html:27
@@ -113,15 +137,6 @@ msgstr "Gespielte Mai-Star Spiele"
msgid "Game"
msgstr "Spiel"
#: templates/maistar_ranking/game_list.html:14
msgid "Place"
msgstr "Platz"
#: templates/maistar_ranking/game_list.html:19
#: templates/maistar_ranking/player_game_list.html:36
msgid "Points"
msgstr "Punkte"
#: templates/maistar_ranking/game_list.html:24
#: templates/maistar_ranking/player_game_list.html:41
msgid "Delete Game"
@@ -135,19 +150,6 @@ msgstr "Für diese Veranstaltung wurden noch keine Mai-Star Spiele erfasst."
msgid "Edit Event"
msgstr "Veranstaltung bearbeiten"
#: templates/maistar_ranking/hanchan_confirm_delete.html:4
#: templates/maistar_ranking/hanchan_confirm_delete.html:10
msgid "Delete game"
msgstr "Spiel löschen"
#: templates/maistar_ranking/hanchan_confirm_delete.html:13
msgid "Cancel"
msgstr "Abbrechen"
#: templates/maistar_ranking/hanchan_confirm_delete.html:14
msgid "Delete"
msgstr "Löschen"
#: templates/maistar_ranking/page.html:5
msgid "Archive"
msgstr "Archiv"

View File

@@ -0,0 +1,30 @@
{% extends "base.html" %}
{% load i18n humanize thumbnail %}
{% block meta_title %}{% trans 'Delete game' %}{% endblock %}
{% block maincontent %}
<form method="post">
{% csrf_token %}
<h2 class="grid_12">{% trans "Delete game" %}</h2>
{% for player in game.player_list %}
<div class="grid_2 center">
<h4>{{ player.placement|ordinal }} {% trans 'Place' %}</h4>
<a class="avatar player"
href="{% url 'maistar-player-games' username=player.user.username season=game.season %}"><img
src="{% thumbnail player.user.avatar|default:'unknown_profile.jpg' 'avatar' %}"
width="70" height="70" alt=""/></a>
<p><a href="{% url 'maistar-player-games' username=player.user.username season=game.season %}">{{player.user.username}}</a><br/>
{{player.score}} {% trans 'Points' %}</p>
</div>
{% endfor %}
{% include 'form.html' %}
<p class="buttonbar grid_12">
<button type="button" onclick="window.history.back()"><span class="fa fa-close"></span>{% trans 'Cancel' %}
</button>
<button type="submit"><span class="fa fa-trash"></span>{% trans 'Delete' %}</button>
</p>
</form>
{% endblock %}
{% block buttonbar %}{% endblock %}

View File

@@ -1,20 +0,0 @@
{% extends "base.html" %}
{% load i18n comments %}
{% block meta_title %}{% trans 'Delete game' %}{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
<fieldset>
<legend>{% trans "Delete game" %}</legend>
{% include 'form.html' %}
<p class="buttonbar">
<button type="button" onclick="window.history.back()"><span class="fa fa-close"></span>{% trans 'Cancel' %}</button>
<button type="submit"><span class="fa fa-trash"></span>{% trans 'Delete' %}</button>
</p>
</fieldset>
</form>
{% endblock %}
{% block buttonbar %}{% endblock %}

View File

@@ -73,8 +73,8 @@
<select id="season" name="season" size="1" onChange="window.location.href = document.season_select.season.options[document.season_select.season.selectedIndex].value;">
{% for season_link in season_list%}
<option
{% if season == season_link %} selected="selected"{% endif %}
value="{% url 'maistar-ranking' season=season_link %}" >{{ season_link }}</option>
selected="selected"
value="{% url 'maistar-ranking' season=season_link %}" >{{ season_link }}</option>
{% endfor %}
</select>
</form>

View File

@@ -6,11 +6,11 @@ from . import views
urlpatterns = [
path("", views.ListRankings.as_view()),
path('event/<int:event>/maistar/', views.ListGames.as_view(), name="maistar-game-list"),
path('event/<int:event>/maistar/add/$', views.GameForm.as_view(), name="maistar-add-game"),
path('event/<int:event>/maistar/add/', views.GameForm.as_view(), name="maistar-add-game"),
path('maistar/', views.ListRankings.as_view(), name="maistar-ranking"),
path('maistar/<int:season>/', views.ListRankings.as_view(), name="maistar-ranking"),
path('maistar/<int:game>/edit/', views.GameForm.as_view(), name="maistar-edit-game"),
path('maistar/<int:game>/delete/', views.DeleteGame.as_view(), name="maistar-delete-game"),
path('maistar/<int:season>/', views.ListRankings.as_view(), name="maistar-ranking"),
path('player/<slug:username>/maistar/', views.ListPlayerGames.as_view(), name="maistar-player-games"),
path('player/<slug:username>/maistar/<int:season>/', views.ListPlayerGames.as_view(), name="maistar-player-games"),
]

View File

@@ -31,11 +31,11 @@ class GameForm(EventDetailMixin, PermissionRequiredMixin, generic.UpdateView):
class DeleteGame(EventDetailMixin, PermissionRequiredMixin, generic.DeleteView):
"""
Fragt zuerst nach, ob die Hanchan wirklich gelöscht werden soll.
Wir die Frage mit "Ja" beantwortet, wird die die Hanchan gelöscht.
Wir die Frage mit "Ja" beantwortet, wird die Hanchan gelöscht.
"""
model = models.Game
permission_required = 'maistar_ranking.delete_game'
pk_url_kwarg = 'hanchan'
pk_url_kwarg = 'game'
def get_success_url(self):
return reverse(
@@ -46,11 +46,12 @@ class DeleteGame(EventDetailMixin, PermissionRequiredMixin, generic.DeleteView):
class UpdateGame(EventDetailMixin, PermissionRequiredMixin, generic.UpdateView):
"""
Ein Formular um eine neues Spiel anzulegen, bzw. eine bestehendes zu
Ein Formular um ein neues Spiel anzulegen, bzw. eine bestehendes zu
bearbeiten.
"""
model = models.Game
permission_required = 'maistar_ranking.update_game'
pk_url_kwarg = 'game'
def get_object(self, queryset=None): # @UnusedVariable
game = models.Game.objects.get(id=self.kwargs['game'])