1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from django.db import models
6 from django.db.models import permalink
7 from django.utils.translation import ugettext as _
8 from datetime import datetime
11 class Author(models.Model):
12 name = models.CharField(_('name'), max_length=50, db_index=True)
13 slug = models.SlugField(_('slug'), max_length=120, db_index=True, unique=True)
14 sort_key = models.CharField(_('sort key'), max_length=120, db_index=True)
15 description = models.TextField(_('description'), blank=True)
16 death = models.IntegerField(_(u'year of death'), blank=True, null=True)
17 gazeta_link = models.CharField(blank=True, max_length=240)
18 wiki_link = models.CharField(blank=True, max_length=240)
21 ordering = ('sort_key',)
22 verbose_name = _('author')
23 verbose_name_plural = _('authors')
29 def __unicode__(self):
33 return "Author(slug=%r)" % self.slug
36 def get_absolute_url(self):
37 return ('catalogue.views.tagged_object_list', [self.url_chunk])
39 def has_description(self):
40 return len(self.description) > 0
41 has_description.short_description = _('description')
42 has_description.boolean = True
45 return self.death is None
48 """ tests whether an author is in public domain """
49 return self.death is not None and self.goes_to_pd() <= datetime.now().year
52 """ calculates the year of public domain entry for an author """
53 return self.death + 71 if self.death is not None else None
57 return '/'.join(('autor', self.slug))
60 class BookStub(models.Model):
61 title = models.CharField(_('title'), max_length=120)
62 author = models.CharField(_('author'), max_length=120)
63 pd = models.IntegerField(_('goes to public domain'), null=True, blank=True)
64 slug = models.SlugField(_('slug'), max_length=120, unique=True, db_index=True)
65 translator = models.TextField(_('translator'), blank=True)
69 verbose_name = _('book stub')
70 verbose_name_plural = _('book stubs')
72 def __unicode__(self):
76 def get_absolute_url(self):
77 return ('catalogue.views.book_detail', [self.slug])
80 return self.pd is not None and self.pd <= datetime.now().year