e1c7e379a9109e9fb361321fd1fd9d8b7b78af45
[wolnelektury.git] / apps / social / models.py
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.
4 #
5 from django.db import models
6 from django.utils.translation import ugettext_lazy as _
7 from django.core.urlresolvers import reverse
8
9 from catalogue.models import Book
10
11
12 class Cite(models.Model):
13     book = models.ForeignKey(Book, verbose_name=_('book'))
14     text = models.TextField(_('text'))
15     small = models.BooleanField(_('small'), default=False,
16         help_text=_('Make this cite display smaller.'))
17     vip = models.CharField(_('VIP'), max_length=128, null=True, blank=True)
18     link = models.URLField(_('link'))
19     sticky = models.BooleanField(_('sticky'), default=False, db_index=True,
20         help_text=_('Sticky cites will take precedense.'))
21
22     image = models.ImageField(_('image'), upload_to='social/cite',
23                 null=True, blank=True)
24     image_title = models.CharField(_('title'), max_length=255,
25                 null=True, blank=True)
26     image_author = models.CharField(_('author'),
27                 max_length=255, blank=True, null=True)
28     image_link = models.URLField(_('link'), blank=True, null=True)
29     image_license = models.CharField(_('license name'),
30                 max_length=255, blank=True, null=True)
31     image_license_link = models.URLField(_('license link'), blank=True, null=True)
32
33     class Meta:
34         ordering = ('vip', 'text')
35         verbose_name = _('cite')
36         verbose_name_plural = _('cites')
37
38     def __unicode__(self):
39         return u"%s: %s…" % (self.vip, self.text[:60])
40
41     def get_absolute_url(self):
42         """This is used for testing."""
43         return "%s?choose_cite=%d" % (reverse('main_page'), self.id)