Merge branch 'Petr'
This commit is contained in:
commit
584108444f
3 changed files with 113 additions and 2 deletions
|
@ -8,7 +8,7 @@ from ckeditor.widgets import CKEditorWidget
|
|||
from django.db.models import Count
|
||||
from django.db import models
|
||||
|
||||
from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni, Soustredeni, Soustredeni_Ucastnici, Novinky
|
||||
from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni, Soustredeni, Soustredeni_Ucastnici, Novinky, Organizator
|
||||
import autocomplete_light
|
||||
|
||||
|
||||
|
@ -329,5 +329,11 @@ class NovinkyAdminForm(forms.ModelForm):
|
|||
class NovinkyAdmin(admin.ModelAdmin):
|
||||
form = NovinkyAdminForm
|
||||
|
||||
|
||||
admin.site.register(Novinky, NovinkyAdmin)
|
||||
|
||||
### Organizator
|
||||
|
||||
@admin.register(Organizator)
|
||||
class OrganizatorAdmin(admin.ModelAdmin):
|
||||
list_filter = ['organizuje_do_roku']
|
||||
|
||||
|
|
35
seminar/migrations/0024_add_organizator.py
Normal file
35
seminar/migrations/0024_add_organizator.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('seminar', '0023_add_novinky'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Organizator',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('prezdivka', models.CharField(max_length=32, null=True, verbose_name=b'P\xc5\x99ezd\xc3\xadvka', blank=True)),
|
||||
('organizuje_od_roku', models.IntegerField(null=True, verbose_name=b'Organizuje od roku', blank=True)),
|
||||
('organizuje_do_roku', models.IntegerField(null=True, verbose_name=b'Organizuje do roku', blank=True)),
|
||||
('studuje', models.CharField(max_length=256, null=True, verbose_name=b'Studuje', blank=True)),
|
||||
('strucny_popis_organizatora', models.TextField(null=True, verbose_name=b'Stru\xc4\x8dn\xc3\xbd popis organiz\xc3\xa1tora', blank=True)),
|
||||
('foto', models.ImageField(help_text=b'Vlo\xc5\xbe fotografii organiz\xc3\xa1tora o libovon\xc3\xa9 velikosti', upload_to=b'image_organizatori/%Y/', null=True, verbose_name=b'Fotografie organiz\xc3\xa1tora', blank=True)),
|
||||
('foto_male', models.ImageField(upload_to=b'image_organizatori/male/%Y/', null=True, editable=False, blank=True)),
|
||||
('user', models.OneToOneField(verbose_name=b'Osoba', to=settings.AUTH_USER_MODEL, help_text=b'Vyber \xc3\xba\xc4\x8det sp\xc5\x99a\xc5\xbeen\xc3\xbd s organiz\xc3\xa1torem.')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Organiz\xe1tor',
|
||||
'verbose_name_plural': 'Organiz\xe1to\u0159i',
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
]
|
|
@ -12,6 +12,10 @@ from django.utils.text import slugify
|
|||
from django.core.urlresolvers import reverse
|
||||
from django.core.cache import cache
|
||||
|
||||
from PIL import Image
|
||||
import os
|
||||
from cStringIO import StringIO
|
||||
from django.core.files.base import ContentFile
|
||||
|
||||
from django_countries.fields import CountryField
|
||||
from solo.models import SingletonModel
|
||||
|
@ -637,3 +641,69 @@ class Novinky(models.Model):
|
|||
verbose_name = 'Novinka'
|
||||
verbose_name_plural = 'Novinky'
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Organizator(models.Model):
|
||||
user = models.OneToOneField(settings.AUTH_USER_MODEL, verbose_name='Osoba',
|
||||
help_text = 'Vyber účet spřažený s organizátorem.')
|
||||
prezdivka = models.CharField('Přezdívka', max_length = 32,
|
||||
null = True, blank = True)
|
||||
organizuje_od_roku = models.IntegerField('Organizuje od roku',
|
||||
null = True, blank = True)
|
||||
organizuje_do_roku = models.IntegerField('Organizuje do roku',
|
||||
null = True, blank = True)
|
||||
studuje = models.CharField('Studuje', max_length = 256,
|
||||
null = True, blank = True)
|
||||
strucny_popis_organizatora = models.TextField('Stručný popis organizátora',
|
||||
null = True, blank = True)
|
||||
foto = models.ImageField('Fotografie organizátora',
|
||||
upload_to='image_organizatori/%Y/', null = True, blank = True,
|
||||
help_text = 'Vlož fotografii organizátora o libovoné velikosti')
|
||||
foto_male = models.ImageField(upload_to='image_organizatori/male/%Y/',
|
||||
null = True, blank = True, editable = False)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.user)
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'Organizátor'
|
||||
verbose_name_plural = 'Organizátoři'
|
||||
|
||||
def save(self):
|
||||
if self.foto:
|
||||
original = Image.open(self.foto)
|
||||
jmeno = os.path.basename(self.foto.file.name)
|
||||
Organizator._vyrobMiniaturu(original, jmeno, 500, self.foto)
|
||||
Organizator._vyrobMiniaturu(original, jmeno, 200, self.foto_male)
|
||||
super(Organizator, self).save()
|
||||
|
||||
@staticmethod
|
||||
def _vyrobMiniaturu(original, jmeno, maximum, field):
|
||||
zmensenina = Organizator._zmensiObrazek(original, maximum)
|
||||
f = StringIO()
|
||||
try:
|
||||
zmensenina.save(f, format=original.format)
|
||||
data = ContentFile(f.getvalue())
|
||||
finally:
|
||||
f.close()
|
||||
field.save(jmeno, data, save = False)
|
||||
|
||||
@staticmethod
|
||||
def _zmensiObrazek(original, maximum):
|
||||
"""Preskaluje obrazek tak, aby byl zachovan pomer stran
|
||||
a zadny rozmer nepresahoval maxRozmer. Pokud zadny rozmer
|
||||
nepresahuje maxRozmer, tak vrati puvodni obrazek
|
||||
(tj. nedojde ke zvetseni obrazku)."""
|
||||
novaVelikost = Organizator._zmensiVelikost(original.size, maximum)
|
||||
return original.resize(novaVelikost, Image.ANTIALIAS)
|
||||
|
||||
@staticmethod
|
||||
def _zmensiVelikost(velikost, maximum):
|
||||
maximum = float(maximum)
|
||||
w, h = velikost
|
||||
soucasneMaximum = max(w, h)
|
||||
if soucasneMaximum <= maximum:
|
||||
return velikost
|
||||
pomer = maximum/soucasneMaximum
|
||||
return (int(w * pomer), int(h * pomer))
|
||||
|
||||
|
|
Loading…
Reference in a new issue