Browse Source

Merge branch 'master' into stable

remotes/origin/prednasky
Bc. Petr Pecha 8 years ago
parent
commit
fdae413a35
  1. 5
      _git_hooks/pre-commit
  2. 10
      _git_hooks/update
  3. 2
      korektury/admin.py
  4. 19
      mamweb/static/css/printtable.css
  5. 3
      mamweb/urls.py
  6. 26
      prednasky/templates/prednasky/metaseznam_prednasek.html
  7. 21
      prednasky/templates/prednasky/seznam_prednasek.html
  8. 21
      prednasky/templates/prednasky/seznam_prednasek_export.txt
  9. 15
      prednasky/urls.py
  10. 35
      prednasky/views.py
  11. 17
      seminar/admin.py
  12. 31
      seminar/migrations/0042_auto_20161005_0847.py
  13. 6
      seminar/models.py
  14. 24
      seminar/static/seminar/stvrzenka.sty
  15. 13
      seminar/static/seminar/stvrzenky.tex
  16. 6
      seminar/templates/seminar/soustredeni/seznam_soustredeni.html
  17. 39
      seminar/templates/seminar/soustredeni/seznam_ucastniku.html
  18. 5
      seminar/templates/seminar/soustredeni/ucastnici.tex
  19. 61
      seminar/unicodecsv.py
  20. 8
      seminar/urls.py
  21. 49
      seminar/views.py

5
_git_hooks/pre-commit

@ -8,7 +8,10 @@ FLAKE8="`git rev-parse --show-toplevel`/bin/flake8"
status=0
git diff --unified=1 --cached HEAD -- '*py' > $TMPDIFF
# select only changed python files which are not migrations
changed=`git diff --cached --name-only | grep 'py$' | grep -v 'migrations/[0-9]'`
git diff --unified=1 --cached HEAD -- $changed > $TMPDIFF
# only do the check when there are some changes to be commited
# otherwise flake8 would hang waiting for input

10
_git_hooks/update

@ -27,7 +27,15 @@ TMPDIFF=`tempfile`
[ $refname != "refs/heads/master" -a $refname != "refs/heads/stable" ] && exit 0
git diff --unified=1 $oldrev $newrev -- '*.py' >${TMPDIFF}
# select only changed python files which are not migrations
changed=`git diff --name-only $oldrev $newrev | grep 'py$' | grep -v 'migrations/[0-9]'`
if [ -z $changed ] ; then
# Nothing to check. Note the exit is necessary -- we would not pass any
# paths to git diff below and it would output the diff unfiltered.
exit 0
fi
git diff --unified=1 $oldrev $newrev -- $changed >${TMPDIFF}
# there is no working tree in bare git repository, so we recreate it for flake8
git archive $newrev | tar -x -C ${TMPDIR}

2
korektury/admin.py

@ -12,7 +12,7 @@ class KorekturovanePDFAdmin(VersionAdmin):
['pdf', 'cas', 'org', 'stran', 'nazev', 'komentar']}),
# (u'PDF', {'fields': ['pdf']}),
]
list_display = ['nazev', 'cas', 'stran']
list_display = ['nazev', 'cas', 'stran', 'org']
list_filter = []
search_fields = []

19
mamweb/static/css/printtable.css

@ -0,0 +1,19 @@
table {
border-collapse: collapse;
width: 100%
}
table, th, td {
border: 1px solid black;
}
td {
width: 1%;
height: 1cm;
}
.fill {
width: 100%;
max-width: 100%
}

3
mamweb/urls.py

@ -19,6 +19,9 @@ urlpatterns = [
# Korekturovaci aplikace (ma vlastni podadresare)
url(r'^', include('korektury.urls')),
# Prednaskova aplikace (ma vlastni podadresare)
url(r'^', include('prednasky.urls')),
# Comments (interni i verejne)
url(r'^comments_dj/', include('django_comments.urls')),
url(r'^comments_fl/', include('fluent_comments.urls')),

26
prednasky/templates/prednasky/metaseznam_prednasek.html

@ -0,0 +1,26 @@
{% extends "prednasky/Base.html" %}
{% block header %}hlasovani{% endblock %}
{% block nadpis1a %}{% block nadpis1b %}
Hlasování o přednáškách
{% endblock %}{% endblock %}
{% block content %}
{# Projdi vsechny seznamy #}
<div class="mam-org-only">
<ul>
{% for seznam in object_list %}
<li>
{% if seznam.stav == 1 %} {# STAV_NAHRH = 1 #}
<a href="/prednasky/seznam_prednasek/{{seznam.id}}">Návrh přednášek na soustředění {{seznam.soustredeni.misto}} </a>
{% else %}
<a href="/prednasky/seznam_prednasek/{{seznam.id}}">Seznam přednášek na soustředění {{seznam.soustredeni.misto}} </a>
{% endif %}
<a href="/prednasky/seznam_prednasek/{{seznam.id}}/export">Export</a>
</li>
{% endfor %}
{% endblock %}

21
prednasky/templates/prednasky/seznam_prednasek.html

@ -0,0 +1,21 @@
{% extends "prednasky/Base.html" %}
{% block header %}seznam_prednasek{% endblock %}
{% block nadpis1a %}{% block nadpis1b %}
Seznam přednášek
{% endblock %}{% endblock %}
{% block content %}
<div class="mam-org-only">
<ul>
{# Projdi vsechny prednasky #}
{% for prednaska in object_list %}
<li>
<strong>{{prednaska.nazev}}</strong> (<i>{{prednaska.obor}},{{prednaska.obtiznost}}</i>) - {{prednaska.org}}
</li>
{% endfor %}
{% endblock %}

21
prednasky/templates/prednasky/seznam_prednasek_export.txt

@ -0,0 +1,21 @@
{% block content %}
{% spaceless %}
{% for hlas in hlasovani %}
hlas({{hlas.ucastnik}},{{hlas.prednaska.id}},{{hlas.body}})
{% endfor %}
{% for prednaska in prednasky %}
prednaska({{prednaska.id}},{{prednaska.org.id}},{{prednaska.obtiznost}},{{prednaska.obor}})
{% endfor %}
{% for org in orgove %}
org({{org.id}},4,0,15)
{% endfor %}
{% for org in orgove %}
{{org.id}};{{org}}
{% endfor %}
{% for prednaska in prednasky %}
{{prednaska.id}};{{prednaska.nazev}};{{prednaska.org.id}}
{{prednaska.body}}
{% endfor %}
{% endspaceless %}
{% endblock %}

15
prednasky/urls.py

@ -0,0 +1,15 @@
from django.conf.urls import * # NOQA
from django.conf.urls import patterns, url
from django.contrib.auth.decorators import user_passes_test
from . import views
staff_member_required = user_passes_test(lambda u: u.is_staff)
urlpatterns = [
url(r'^prednasky/$', views.newPrednaska),
url(r'^prednasky/hotovo$', views.Prednaska_hotovo),
url(r'^prednasky/metaseznam_prednasek$', staff_member_required(views.MetaSeznamListView.as_view()), name='metaseznam-list'),
url(r'^prednasky/seznam_prednasek/(?P<seznam>\d+)/$', staff_member_required(views.SeznamListView.as_view()), name='seznam-list'),
url(r'^prednasky/seznam_prednasek/(?P<seznam>\d+)/export$', staff_member_required(views.SeznamExportView), name='seznam-export'),
# url(r'^korektury/help/', staff_member_required(views.KorekturyHelpView.as_view()), name='korektury-help'),
]

35
prednasky/views.py

@ -1,4 +1,5 @@
from django.shortcuts import render
from django.shortcuts import render,get_object_or_404
from django.views import generic
from prednasky.forms import NewPrednaskyForm
from prednasky.models import Seznam, Hlasovani, Prednaska
from django.shortcuts import HttpResponseRedirect
@ -41,5 +42,35 @@ def newPrednaska(request):
def Prednaska_hotovo(request):
return render(request, 'prednasky/hotovo.html')
class MetaSeznamListView(generic.ListView):
model = Seznam
template_name = 'prednasky/metaseznam_prednasek.html'
class SeznamListView(generic.ListView):
template_name = 'prednasky/seznam_prednasek.html'
def get_queryset(self):
print self.kwargs
self.seznam = get_object_or_404(Seznam,id=self.kwargs["seznam"])
return Prednaska.objects.filter(seznamy = self.seznam)
def SeznamExportView(request,seznam):
seznam_obj = Seznam.objects.get(id=seznam)
hlasovani = Hlasovani.objects.filter(seznam=seznam)
prednasky = Prednaska.objects.filter(seznamy=seznam)
orgove = set(map(lambda x:x.org,prednasky))
ucastnici = list(set(map(lambda x:x.ucastnik,hlasovani)))
for p in prednasky:
p.body = []
for u in ucastnici:
p.body.append(hlasovani.get(ucastnik=u,prednaska=p).body)
for h in hlasovani:
h.ucastnik = hash(h.ucastnik)
return render(request, 'prednasky/seznam_prednasek_export.txt',
{"hlasovani":hlasovani,"prednasky":prednasky,"orgove":orgove},
content_type="text/plain")
# Create your views here.

17
seminar/admin.py

@ -11,7 +11,7 @@ from django.db import models
from django.contrib.auth.models import User
from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni, Soustredeni, Soustredeni_Ucastnici, Soustredeni_Organizatori, Novinky, Organizator, Prispevek, Pohadka
from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni, Soustredeni, Soustredeni_Ucastnici, Soustredeni_Organizatori, Novinky, Organizator, Prispevek, Pohadka, Konfera
from autocomplete_light import shortcuts as autocomplete_light
@ -181,6 +181,7 @@ class Soustredeni_UcastniciInline(admin.TabularInline):
qs = super(Soustredeni_UcastniciInline, self).get_queryset(request)
return qs.select_related('resitel', 'soustredeni')
class Soustredeni_OrganizatoriInline(admin.TabularInline):
form = autocomplete_light.modelform_factory(Soustredeni_Organizatori, autocomplete_fields=['organizator'], fields=['organizator'],)
model = Soustredeni_Organizatori
@ -468,6 +469,20 @@ class SoustredeniAdmin(VersionAdmin):
admin.site.register(Soustredeni, SoustredeniAdmin)
### Konfery
class KonferaAdminForm(forms.ModelForm):
class Meta:
model=Konfera
exclude = []
class KonferaAdmin(VersionAdmin):
form = KonferaAdminForm
list_filter = ['soustredeni']
list_display = ['nazev','soustredeni','organizator','typ_prezentace']
# inlines = [Konfera_UcastniciInline]
admin.site.register(Konfera,KonferaAdmin)
### Novinky
class NovinkyAdminForm(forms.ModelForm):

31
seminar/migrations/0042_auto_20161005_0847.py

@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
import seminar.models
class Migration(migrations.Migration):
dependencies = [
('seminar', '0041_konfery'),
]
operations = [
migrations.AlterField(
model_name='konfera',
name='materialy',
field=models.FileField(help_text='Dal\u0161\xed materi\xe1ly ke konfe\u0159e zabalen\xe9 do jednoho souboru', upload_to=seminar.models.generate_filename_konfera, verbose_name='materialy', blank=True),
),
migrations.AlterField(
model_name='konfera',
name='prezentace',
field=models.FileField(help_text='Prezentace nebo fotka posteru', upload_to=seminar.models.generate_filename_konfera, verbose_name='prezentace', blank=True),
),
migrations.AlterField(
model_name='konfera',
name='prispevek',
field=models.ForeignKey(related_name='konfery', on_delete=django.db.models.deletion.SET_NULL, blank=True, to='seminar.Problem', help_text='\xda\u010dastnick\xfd p\u0159\xedp\u011bvek o konfe\u0159e', null=True, verbose_name='p\u0159\xedsp\u011bvek do \u010d\xedsla'),
),
]

6
seminar/models.py

@ -859,7 +859,7 @@ class Konfera(models.Model):
org_poznamka = models.TextField(u'neveřejná poznámka', blank=True,
help_text=u'Neveřejná poznámka ke konfeře(plain text)')
prispevek = models.ForeignKey(Problem, verbose_name=u'příspěvek do čísla', related_name='konfery',
help_text=u'Účastnický přípěvek o konfeře',on_delete = models.SET_NULL, null=True)
help_text=u'Účastnický přípěvek o konfeře',on_delete = models.SET_NULL, null=True, blank=True)
TYP_VELETRH = 'veletrh'
TYP_PREZENTACE = 'prezentace'
TYP_CHOICES = [
@ -868,9 +868,9 @@ class Konfera(models.Model):
]
typ_prezentace = models.CharField(u'typ prezentace', max_length=16, choices=TYP_CHOICES, blank=False, default=TYP_VELETRH)
prezentace = models.FileField(u'prezentace',help_text = u'Prezentace nebo fotka posteru',
upload_to = generate_filename_konfera)
upload_to = generate_filename_konfera, blank=True)
materialy = models.FileField(u'materialy',help_text = u'Další materiály ke konfeře zabalené do jednoho souboru',
upload_to = generate_filename_konfera)
upload_to = generate_filename_konfera, blank=True)
def __str__(self):
return force_unicode(u"%s: (%s)" % (self.nazev, self.soustredeni))

24
seminar/static/seminar/stvrzenka.sty

@ -0,0 +1,24 @@
\newcommand{\stvrzenka}[6]{
\removelastskip\bigskip
\newpage
\noindent\textbf{Dodavatel:}\hfill\textbf{Stvrzenka č. {\Large #1}}
{Univerzita Karlova \\
\indent Matematicko-fyzikální fakulta \\
\indent OVVP, M\&M \\
\indent Ke Karlovu 3, 120 00 Praha 2 \\
\indent IČ: 00216208 DIČ: CZ00216208}
\parindent=0pt
\parskip=0.2in
\textbf{Celkem Kč:} 700,- \\
\textbf{Slovy:} sedmset korun českých
\textbf{Přijato od (firma, jméno, adresa):} #2 #3, #4, #5 #6
\textbf{Účel platby:} příspěvek na stravování
ze dne \datum \hfill Přijal:\hspace{3cm}
}

13
seminar/static/seminar/stvrzenky.tex

@ -0,0 +1,13 @@
\documentclass[12pt,a4paper]{article}
\usepackage[czech]{babel}
\usepackage[utf8]{inputenc}
\usepackage[margin=1in]{geometry}
\usepackage{stvrzenka}
\pagestyle{empty}
\begin{document}
\input{ucastnici}
\end{document}

6
seminar/templates/seminar/soustredeni/seznam_soustredeni.html

@ -46,7 +46,11 @@
{% if user.is_staff %}
<div class="mam-org-only">
<a href="../{{soustredeni.pk}}/fotogalerie/0/new/">Vytvořit novou fotogalerii</a><br>
<a href="../{{soustredeni.pk}}/obalky.pdf">Vygenerovat obálky pro účastníky</a>
<a href="../{{soustredeni.pk}}/obalky.pdf">Vygenerovat obálky pro účastníky</a><br>
Seznam účastníků -
<a href="../{{soustredeni.pk}}/seznam_ucastniku">HTML tabulka pro tisk</a>,
<a href="../{{soustredeni.pk}}/export_ucastniku">CSV</a><br>
<a href="../{{soustredeni.pk}}/stvrzenky/42">Stvrzenky <i>(42 v URL nahraďte prvním číslem z rozsahu)</i></a>
</div>
{% endif %}

39
seminar/templates/seminar/soustredeni/seznam_ucastniku.html

@ -0,0 +1,39 @@
{% load static %}
<html lang='cs'>
<head>
<title>Seznam účastníků</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="{% static 'css/printtable.css' %}" />
</head>
<body>
<h1>
{% with object_list|first as afirst %}
{{afirst.soustredeni.misto}}
{% endwith %}
- účastníci
</h1>
<table>
<tr>
<th nowrap>Jméno</th>
<th nowrap>Maturita</th>
<th nowrap>Mobil</th>
<th class="fill"></th>
</tr>
{% for sous_ucast in object_list %}
<tr>
<td nowrap>{{sous_ucast.resitel}}</td>
<td nowrap>{{sous_ucast.resitel.rok_maturity}}</td>
<td nowrap>{{sous_ucast.resitel.telefon}}</td>
<td class="fill"></td>
</tr>
{% empty %}
Žádní účastníci nebyli...
{% endfor %}
</table>
</ul>
</body>
</html>

5
seminar/templates/seminar/soustredeni/ucastnici.tex

@ -0,0 +1,5 @@
{% load tex %}
\newcommand{\datum}{{datum|date:"j. n. Y"|sloz}}
{% for u in ucastnici %}
\stvrzenka{{u.cislo_stvrzenky|sloz}}{{u.jmeno|sloz}}{{u.prijmeni|sloz}}{{u.ulice|sloz}}{{u.psc|sloz}}{{u.mesto|sloz}}
{% endfor %}

61
seminar/unicodecsv.py

@ -0,0 +1,61 @@
import csv, codecs, cStringIO
class UTF8Recoder:
"""
Iterator that reads an encoded stream and reencodes the input to UTF-8
"""
def __init__(self, f, encoding):
self.reader = codecs.getreader(encoding)(f)
def __iter__(self):
return self
def next(self):
return self.reader.next().encode("utf-8")
class UnicodeReader:
"""
A CSV reader which will iterate over lines in the CSV file "f",
which is encoded in the given encoding.
"""
def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
f = UTF8Recoder(f, encoding)
self.reader = csv.reader(f, dialect=dialect, **kwds)
def next(self):
row = self.reader.next()
return [unicode(s, "utf-8") for s in row]
def __iter__(self):
return self
class UnicodeWriter:
"""
A CSV writer which will write rows to CSV file "f",
which is encoded in the given encoding.
"""
def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
# Redirect output to a queue
self.queue = cStringIO.StringIO()
self.writer = csv.writer(self.queue, dialect=dialect, **kwds)
self.stream = f
self.encoder = codecs.getincrementalencoder(encoding)()
def writerow(self, row):
self.writer.writerow([s.encode("utf-8") for s in row])
# Fetch UTF-8 output from the queue ...
data = self.queue.getvalue()
data = data.decode("utf-8")
# ... and reencode it into the target encoding
data = self.encoder.encode(data)
# write to the target stream
self.stream.write(data)
# empty queue
self.queue.truncate(0)
def writerows(self, rows):
for row in rows:
self.writerow(row)

8
seminar/urls.py

@ -3,16 +3,11 @@ from django.conf.urls import patterns, url
from django.contrib.auth.decorators import user_passes_test
from . import views, export
from utils import staff_member_required
from prednasky.views import newPrednaska, Prednaska_hotovo
from django.views.generic.base import RedirectView
staff_member_required = user_passes_test(lambda u: u.is_staff)
urlpatterns = [
# prednasky
url(r'^prednasky/$', newPrednaska),
url(r'^prednasky/hotovo$', Prednaska_hotovo),
# REDIRECTy
url(r'^jak-resit/$', RedirectView.as_view(url='/co-je-MaM/jak-resit/')),
@ -33,6 +28,9 @@ urlpatterns = [
url(r'^soustredeni/probehlo/$', views.SoustredeniListView.as_view(),
name = 'seminar_seznam_soustredeni'),
url(r'^soustredeni/probehlo/(?P<soustredeni>\d+)/$', views.SoustredeniView.as_view(), name='seminar_soustredeni'),
url(r'^soustredeni/(?P<soustredeni>\d+)/seznam_ucastniku$', staff_member_required(views.SoustredeniUcastniciView.as_view()), name='soustredeni_ucastnici'),
url(r'^soustredeni/(?P<soustredeni>\d+)/stvrzenky/(?P<first_num>\d+)$', staff_member_required(views.soustredeniStvrzenkyExportView), name='soustredeni_stvrzenky'),
url(r'^soustredeni/(?P<soustredeni>\d+)/export_ucastniku$', staff_member_required(views.soustredeniUcastniciExportView), name='soustredeni_ucastnici_export'),
url(r'^soustredeni/(?P<soustredeni>\d+)/fotogalerie/', include('galerie.urls')),
# Zadani

49
seminar/views.py

@ -6,7 +6,7 @@ from django.core.urlresolvers import reverse
from django.core.exceptions import PermissionDenied, ObjectDoesNotExist
from django.views import generic
from django.utils.translation import ugettext as _
from django.http import Http404
from django.http import Http404,HttpResponseBadRequest
from django.db.models import Q
from django.views.decorators.csrf import ensure_csrf_cookie
from django.contrib.auth import authenticate, login
@ -14,6 +14,7 @@ from django.contrib.auth import authenticate, login
from .models import Problem, Cislo, Reseni, Nastaveni, Rocnik, Soustredeni, Organizator, Resitel, Novinky, Soustredeni_Ucastnici, Pohadka, Prispevek
from .models import VysledkyZaCislo, VysledkyKCisluZaRocnik, VysledkyKCisluOdjakziva
from . import utils
from .unicodecsv import UnicodeWriter
from datetime import timedelta, date, datetime
from itertools import groupby
@ -26,6 +27,7 @@ import unicodedata
import json
import traceback
import sys
import csv
def verejna_temata(rocnik):
@ -528,9 +530,52 @@ class SoustredeniView(generic.DetailView):
template_name = 'seminar/archiv/soustredeni.html'
def soustredeniObalkyView(request,soustredeni):
soustredeni = Soustredeni.objects.filter(id = soustredeni)[0]
soustredeni = get_object_or_404(Soustredeni,id = soustredeni)
return obalkyView(request,soustredeni.ucastnici.all())
class SoustredeniUcastniciView(generic.ListView):
model = Soustredeni_Ucastnici
template_name = 'seminar/soustredeni/seznam_ucastniku.html'
def get_queryset(self):
self.soustredeni = get_object_or_404(Soustredeni, id=self.kwargs["soustredeni"])
return Soustredeni_Ucastnici.objects.filter(soustredeni=self.soustredeni).select_related('resitel')
def soustredeniStvrzenkyExportView(request,soustredeni,first_num):
first_num = int(first_num)
soustredeni = get_object_or_404(Soustredeni,id = soustredeni)
ucastnici = Resitel.objects.filter(soustredeni=soustredeni)
for (idx,u) in enumerate(ucastnici):
u.cislo_stvrzenky = first_num+idx;
tex = render(request,'seminar/soustredeni/ucastnici.tex', {'ucastnici': ucastnici, 'datum':soustredeni.datum_zacatku }).content
tempdir = tempfile.mkdtemp()
with open(tempdir+"/ucastnici.tex","w") as texfile:
# Pokud TeX chce ISO Latin, tak se da encode nastavit
texfile.write(tex.decode("utf-8").encode("utf-8"))
shutil.copy(os.path.join(settings.STATIC_ROOT, 'seminar/stvrzenka.sty'),tempdir)
shutil.copy(os.path.join(settings.STATIC_ROOT, 'seminar/stvrzenky.tex'),tempdir)
subprocess.call(["cslatex","stvrzenky.tex"],cwd = tempdir)
subprocess.call(["dvipdf","stvrzenky.dvi"],cwd = tempdir)
with open(tempdir+"/stvrzenky.pdf","rb") as pdffile:
response = HttpResponse(pdffile.read(),content_type='application/pdf')
shutil.rmtree(tempdir)
return response
def soustredeniUcastniciExportView(request,soustredeni):
soustredeni = get_object_or_404(Soustredeni,id = soustredeni)
ucastnici = Resitel.objects.filter(soustredeni=soustredeni)
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="ucastnici.csv"'
writer = UnicodeWriter(response)
writer.writerow(["jmeno", "prijmeni", "rok_maturity", "telefon", "email", "ulice", "mesto", "psc","stat"])
for u in ucastnici:
writer.writerow([u.jmeno, u.prijmeni, str(u.rok_maturity), u.telefon, u.email, u.ulice, u.mesto, u.psc, u.stat.name])
return response
### Články

Loading…
Cancel
Save