123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- from django.db import models
- from django.contrib.contenttypes.models import ContentType
- from django.contrib.contenttypes.generic import GenericForeignKey
- from django.db import models, IntegrityError, transaction
- from django.template.defaultfilters import slugify
- from django.utils.translation import ugettext_lazy as _, ugettext
- from directory.models import Place
- from taggit.managers import TaggableManager
- from django_extensions.db.models import TimeStampedModel
- from documents.managers import PublishedManager
- class Document(TimeStampedModel):
- ACCESS_CHOICES = (
- ("public", "Public"),
- ("private", "Private"),
- ("organization", "Organization"),
- )
- title = models.CharField(verbose_name=_("Title"), max_length=255)
- slug = models.SlugField(verbose_name=_("Slug"), unique=True, max_length=200)
- description = models.TextField(_("Description"), blank=True, null=True)
- source = models.CharField(_("Source"), max_length=100)
- access = models.CharField(
- _("Access"), max_length=12, choices=ACCESS_CHOICES, default="public"
- )
- published = models.BooleanField(_("published"), default=False)
- published_on = models.DateTimeField(_("published on"))
- preview = models.ImageField(
- _("preview"), upload_to="documents/previews", blank=True, null=True
- )
- doc_cloud_id = models.SlugField(
- max_length=80, editable=False, null=True, blank=True
- )
- tags = TaggableManager()
- objects = models.Manager()
- published_objects = PublishedManager()
- def __unicode__(self):
- return self.title
- class Meta:
- verbose_name = _("Document")
- verbose_name_plural = _("Documents")
- @models.permalink
- def get_absolute_url(self):
- return (
- "dc-document-detail",
- (),
- {
- "year": self.published_on.year,
- "month": self.published_on.strftime("%b").lower(),
- "day": self.published_on.day,
- "slug": self.slug,
- },
- )
- @property
- def display(self):
- return True
- class TextDocument(Document):
- content = models.TextField(
- _("content"),
- blank=True,
- null=True,
- help_text="If document is plaintext, insert it here.",
- )
- class Meta:
- verbose_name = _("Text Document")
- verbose_name_plural = _("Text Documents")
- @models.permalink
- def get_absolute_url(self):
- return (
- "dc-text-document-detail",
- (),
- {
- "year": self.published_on.year,
- "month": self.published_on.strftime("%b").lower(),
- "day": self.published_on.day,
- "slug": self.slug,
- },
- )
- class PDFDocument(Document):
- file = models.FileField(_("file"), upload_to="documents/pdf/%Y/%b/%d")
- class Meta:
- verbose_name = _("PDF Document")
- verbose_name_plural = _("PDF Documents")
- @models.permalink
- def get_absolute_url(self):
- return (
- "dc-pdf-document-detail",
- (),
- {
- "year": self.published_on.year,
- "month": self.published_on.strftime("%b").lower(),
- "day": self.published_on.day,
- "slug": self.slug,
- },
- )
- class ExcelDocument(Document):
- file = models.FileField(_("file"), upload_to="documents/excel/%Y/%b/%d")
- class Meta:
- verbose_name = _("Excel Document")
- verbose_name_plural = _("Excel Documents")
- @models.permalink
- def get_absolute_url(self):
- return (
- "dc-xcl-document-detail",
- (),
- {
- "year": self.published_on.year,
- "month": self.published_on.strftime("%b").lower(),
- "day": self.published_on.day,
- "slug": self.slug,
- },
- )
- class WordDocument(Document):
- file = models.FileField(_("file"), upload_to="documents/word/%Y/%b/%d")
- class Meta:
- verbose_name = _("Word Document")
- verbose_name_plural = _("Word Documents")
- @models.permalink
- def get_absolute_url(self):
- return (
- "dc-word-document-detail",
- (),
- {
- "year": self.published_on.year,
- "month": self.published_on.strftime("%b").lower(),
- "day": self.published_on.day,
- "slug": self.slug,
- },
- )
|