1 # -*- coding: utf-8 -*-
2 from django.db import models
3 from django.db.models import permalink
4 from django.utils.translation import ugettext_lazy as _
5 from django.contrib.auth.models import User
7 from newtagging.models import TagBase
8 from newtagging import managers
12 ('author', _('author')),
13 ('epoch', _('epoch')),
15 ('genre', _('genre')),
16 ('theme', _('theme')),
21 class TagSubcategoryManager(models.Manager):
22 def __init__(self, subcategory):
23 super(TagSubcategoryManager, self).__init__()
24 self.subcategory = subcategory
26 def get_query_set(self):
27 return super(TagSubcategoryManager, self).get_query_set().filter(category=self.subcategory)
31 name = models.CharField(_('name'), max_length=50, unique=True, db_index=True)
32 slug = models.SlugField(_('slug'), unique=True, db_index=True)
33 sort_key = models.SlugField(_('sort key'), db_index=True)
34 category = models.CharField(_('category'), max_length=50, blank=False, null=False,
35 db_index=True, choices=TAG_CATEGORIES)
36 description = models.TextField(blank=True)
38 user = models.ForeignKey(User, blank=True, null=True)
40 def has_description(self):
41 return len(self.description) > 0
42 has_description.short_description = _('Has description')
43 has_description.boolean = True
46 def get_absolute_url(self):
47 return ('catalogue.views.tagged_book_list', [self.slug])
50 ordering = ('sort_key',)
51 verbose_name = _('tag')
52 verbose_name_plural = _('tags')
54 def __unicode__(self):
58 class Book(models.Model):
59 title = models.CharField(_('title'), max_length=120)
60 slug = models.SlugField(_('slug'), unique=True, db_index=True)
61 description = models.TextField(_('description'), blank=True)
62 created_at = models.DateTimeField(_('creation date'), auto_now=True)
65 pdf_file = models.FileField(_('PDF file'), upload_to='books/pdf', blank=True)
66 odt_file = models.FileField(_('ODT file'), upload_to='books/odt', blank=True)
67 html_file = models.FileField(_('HTML file'), upload_to='books/html', blank=True)
69 objects = managers.ModelTaggedItemManager(Tag)
70 tags = managers.TagDescriptor(Tag)
72 def has_description(self):
73 return len(self.description) > 0
74 has_description.short_description = _('Has description')
75 has_description.boolean = True
77 def has_pdf_file(self):
78 return bool(self.pdf_file)
79 has_pdf_file.short_description = 'PDF'
80 has_pdf_file.boolean = True
82 def has_odt_file(self):
83 return bool(self.odt_file)
84 has_odt_file.short_description = 'ODT'
85 has_odt_file.boolean = True
87 def has_html_file(self):
88 return bool(self.html_file)
89 has_html_file.short_description = 'HTML'
90 has_html_file.boolean = True
93 def get_absolute_url(self):
94 return ('catalogue.views.book_detail', [self.slug])
98 verbose_name = _('book')
99 verbose_name_plural = _('books')
101 def __unicode__(self):
105 # class Fragment(models.Model):
106 # id = models.IntegerField(primary_key=True)
107 # text = models.TextField(blank=True)
108 # start_paragraph = models.IntegerField(null=True, blank=True)
109 # book_id = models.IntegerField(null=True, blank=True)
111 # db_table = u'fragment'
114 # class Inflections(models.Model):
115 # word = models.CharField(max_length=120, primary_key=True)
116 # cases = models.TextField() # This field type is a guess.
118 # db_table = u'inflections'
121 # class Paragraph(models.Model):
122 # id = models.IntegerField(primary_key=True)
123 # number = models.IntegerField(null=True, blank=True)
124 # text = models.TextField(blank=True)
125 # book_id = models.IntegerField(null=True, blank=True)
127 # db_table = u'paragraph'