]> gitweb.fperrin.net Git - djsite.git/blob - quotes/models.py
Fix display when quotes contain unicode
[djsite.git] / quotes / models.py
1 from django.db import models
2 from django.urls import reverse
3
4 from localmodels import HTMLField
5
6 # Create your models here.
7 class BaseTag(models.Model):
8     tag = models.CharField(max_length=100, unique=True)
9
10     def __unicode__(self):
11         return self.tag
12
13     class Meta(object):
14         abstract = True
15
16 class AuthorTag(BaseTag): pass
17 class WorkTag(BaseTag): pass
18 class QuoteTag(BaseTag):
19     def get_absolute_url(self):
20         return reverse('quotes:tags', args=[str(self.id)])
21
22 class CommonData(models.Model):
23     creation_date = models.DateTimeField(auto_now_add=True)
24     last_modification = models.DateTimeField(auto_now=True)
25
26     notes = HTMLField(blank=True, help_text= \
27                       "Notes about the entry; may be left blank. Displayed \
28                       on the public pages")
29     pvt_notes = HTMLField(blank=True, help_text= \
30                           "Notes about the entry; not displayed on \
31                           the public interface")
32
33     nb_display = models.BigIntegerField(default=0)
34     def incr_display(self):
35         self.nb_display = models.F('nb_display') + 1
36         self.save()
37
38     class Meta(object):
39         abstract = True
40
41 class Author(CommonData):
42     name = models.CharField(max_length=100,
43                             help_text="Name of the author",
44                             unique=True)
45
46     tags = models.ManyToManyField(AuthorTag, blank=True,
47                                   help_text='Not implemented yet')
48
49     birth_date = models.DateField(blank=True, null=True,
50                                   help_text="Date of birth")
51     death_date = models.DateField(blank=True, null=True,
52                                   help_text="Date of death (leave blank \
53                                   if still alive!)")
54
55     def __unicode__(self):
56         return self.name
57
58     def get_absolute_url(self):
59         return reverse('quotes:author', args=[str(self.id)])
60
61 # class DatePrecision(models.CharField):
62 #     DAY = "D"
63 #     MONTH = "M"
64 #     YEAR = "Y"
65 #     DECADE = "X"
66 #     CENTURY = "C"
67 #     UNKNOWN = "?"
68 #     PRECISION_CHOICES = [
69 #         (DAY, "Day"),
70 #         (MONTH, "Month"),
71 #         (YEAR, "Year"),
72 #         (DECADE, "Decade"),
73 #         (CENTURY, "Century"),
74 #         (UNKNOWN, "Unknown"),
75 #     ]
76 #     def __init__(self, **kwargs):
77 #         models.CharField(max_length=1, choices=self.PRECISION_CHOICES,
78 #                          default=self.DAY, **kwargs)
79
80 class Work(CommonData):
81     name = models.CharField(max_length=100,
82                             help_text="Name of the context for the quote \
83                             (title of the work or speech it appears in)",
84                             unique=True)
85     author = models.ForeignKey(Author)
86     date = models.DateField(blank=True, null=True,
87                             help_text="Date of the quote")
88     tags = models.ManyToManyField(WorkTag, blank=True,
89                                   help_text='Not implemented yet')
90
91     def __unicode__(self):
92         return "%s: %s (%s)" % (self.author.name, self.name, self.date)
93
94     def get_absolute_url(self):
95         return reverse('quotes:work', args=[str(self.id)])
96
97 class Quote(CommonData):
98     text = HTMLField()
99     tags = models.ManyToManyField(QuoteTag, blank=True)
100     work = models.ForeignKey(Work)
101
102     def __unicode__(self):
103         return self.work.author.name + ": " + self.text
104
105     def get_absolute_url(self):
106         return reverse('quotes:onequote', args=[str(self.id)])