class Entry(models.Model): blog = models.ForeignKey(Blog, verbose_name=_("Blog")) is_published = models.BooleanField(_('is published')) pub_date = models.DateTimeField(_('publish at'), default=datetime.datetime.now) placeholders = M2MPlaceholderField( actions=SimpleTranslationPlaceholderActions(), placeholders=CMSPLUGIN_BLOG_PLACEHOLDERS) tags = TagField() objects = EntriesManager() published = PublishedEntriesManager() def get_absolute_url(self, language=None): if not language: language = get_language() try: url = self.entrytitle_set.get(language=language).get_absolute_url() if url[1:len(language) + 1] == language: url = url[len(language) + 1:] return url except EntryTitle.DoesNotExist: return '' def language_changer(self, language): url = self.get_absolute_url(language) if url: return url # There is no entry in the given language, we return blog's root blog_prefix = '' try: title = Title.objects.get(application_urls='BlogApphook', language=language) blog_prefix = urljoin(reverse('pages-root'), title.overwrite_url or title.slug) except Title.DoesNotExist: # Blog app hook not defined anywhere? pass return blog_prefix or reverse('pages-root') def _template(self): from simple_translation.utils import get_translated_model model = get_translated_model(self.__class__) return model.DETAIL_TEMPLATE template = property(_template) class Meta: verbose_name = _('entry') verbose_name_plural = _('entries') ordering = ('-pub_date', )
class Entry(models.Model): is_published = models.BooleanField(_('Is published')) pub_date = models.DateTimeField(_('Published'), default=datetime.datetime.now) placeholders = M2MPlaceholderField( actions=SimpleTranslationPlaceholderActions(), placeholders=CMSPLUGIN_BLOG_PLACEHOLDERS) tags = TagField() objects = EntriesManager() published = PublishedEntriesManager() class Meta: verbose_name = _('Entry') verbose_name_plural = _('Entries') ordering = ('-pub_date', )
class Document(SimpleTranslationMixin, models.Model): """ A document consists of a title and description and a number of filer-files. See ``DocumentTitle`` for the translateable fields of this model. :creation_date: DateTime when this Document object was created. :user: Optional FK to the User who created this document. :position: If you want to order the documents other than by creation date, enter numbers for positioning here. views. :is_on_front_page: If ``True`` the object will be returned by the ``get_frontpage_documents`` templatetag. :document_date: The date of the document itself. Don't confuse this with creation_date. """ category = models.ForeignKey( DocumentCategory, verbose_name=_('Category'), null=True, blank=True, ) creation_date = models.DateTimeField( auto_now_add=True, verbose_name=_('Creation date'), ) user = models.ForeignKey( 'auth.User', verbose_name=_('User'), null=True, blank=True, ) position = models.PositiveIntegerField( verbose_name=_('Position'), null=True, blank=True, ) is_on_front_page = models.BooleanField( default=False, verbose_name=('Is on front page'), ) source_url = models.URLField( verbose_name=_('Source URL'), help_text=_( 'Use this if you want to give credit for a downloadable file.'), blank=True, ) download_url = models.URLField( verbose_name=_('Download URL'), help_text=_( 'Use this if you want to link to a file instead of self-hosting' ' it'), blank=True, ) placeholders = M2MPlaceholderField( actions=SimpleTranslationPlaceholderActions(), placeholders=('content', ), ) creation_date = models.DateTimeField( auto_now_add=True, verbose_name=_('Creation date'), ) update_date = models.DateTimeField( auto_now=True, verbose_name=_('Update date'), ) document_date = models.DateTimeField( verbose_name=_('Document date'), blank=True, null=True, ) objects = DocumentManager() class Meta: ordering = ( 'position', '-creation_date', ) def __unicode__(self): return self.get_title() def get_absolute_url(self): return reverse('document_library_detail', kwargs={ 'pk': self.pk, }) def get_filetype(self): lang = get_language() title = get_preferred_translation_from_lang(self, lang) if title.filer_file: return title.filer_file.extension.upper() return None def get_title(self): lang = get_language() return get_preferred_translation_from_lang(self, lang).title