123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847 |
- from datetime import datetime, timedelta
- from taggit.managers import TaggableManager
- from taggit.models import Tag
- from django.db import models
- from django.utils.translation import ugettext_lazy as _
- from django.core.urlresolvers import reverse
- from django.contrib.contenttypes import generic
- from django.contrib.contenttypes.models import ContentType
- from django.contrib.sites.models import Site
- from django.contrib.sites.managers import CurrentSiteManager
- from django.contrib.auth.models import User, Group
- from django.conf import settings
- from newsroom.managers import *
- from django.utils.safestring import mark_safe
- from django.contrib.markup.templatetags import markup
- from django_inlines import inlines
- from darkroom.inlines import PhotoInline, GraphicInline
- inlines.registry.register('photo', PhotoInline)
- inlines.registry.register('graphic', GraphicInline)
- from darkroom.models import Gallery, Photo, Graphic, Movie, Slideshow
- from adzone.models import BannerAd, AdCategory
- from directory.models import Town, Place, Person
- from documents.models import Document, PDFDocument
- from remember.models import Announcement, InMemoriam, Service, Remembrance
- #from historical.models import HistoricArticle
- from django_extensions.db.models import TimeStampedModel
- from django_extensions.db.fields import AutoSlugField
- # Get relative media path
- try:
- NEWSROOM_DIR = getattr(settings, 'NEWSROOM_DIR', 'newsroom/')
- except:
- NEWSROOM_DIR = 'newsroom/'
- MARKUP_HTML = 'h'
- MARKUP_MARKDOWN = 'm'
- MARKUP_REST = 'r'
- MARKUP_TEXTILE = 't'
- MARKUP_OPTIONS = getattr(settings, 'ARTICLE_MARKUP_OPTIONS', (
- (MARKUP_MARKDOWN, _('Markdown')),
- (MARKUP_HTML, _('HTML/Plain Text')),
- (MARKUP_REST, _('ReStructured Text')),
- (MARKUP_TEXTILE, _('Textile'))
- ))
- MARKUP_DEFAULT = getattr(settings, 'COPY_MARKUP_DEFAULT', MARKUP_MARKDOWN)
- AUTO_TAG=getattr(settings, 'NEWSROOM_AUTO_TAG', True)
- class Paper(TimeStampedModel):
- name=models.CharField(_('name'), max_length=100)
- towns=models.ManyToManyField(Town)
- slug=AutoSlugField(_('slug'), populate_from='name', editable=True)
- description=models.TextField(_('description'), blank=True, null=True)
-
- class Meta:
- verbose_name = _('paper')
- verbose_name_plural = _('papers')
- ordering = ('name',)
-
- def __unicode__(self):
- return self.name
- class Link(TimeStampedModel):
- url = models.URLField('URL')
- title = models.CharField(_('title'), max_length=255)
- description=models.CharField(_('description'), max_length=200, blank=True, null=True)
- published=models.BooleanField(_('published'), default=False)
- published_on=models.DateTimeField(_('published on'))
- class Meta:
- verbose_name=_('link')
- verbose_name_plural=_('links')
- ordering=('created',)
- get_latest_by='published_on'
- def __unicode__(self):
- return self.title
-
- @models.permalink
- def get_absolute_url(self):
- return ('link_detail', (), {'slug': self.slug})
- class AuthorType(models.Model):
- title=models.CharField(_('name'), max_length=100)
- slug=AutoSlugField(_('slug'), populate_from='title', editable=True)
- description=models.TextField(_('description'), blank=True, null=True)
-
- class Meta:
- ordering=('title',)
- def __unicode__(self):
- return self.title
-
- @models.permalink
- def get_absolute_url(self):
- return ('author_type_detail', (), {'slug': self.slug})
- class Author(TimeStampedModel):
- '''Author model.'''
- name=models.CharField(_('name'), max_length=100)
- slug=AutoSlugField(_('slug'), populate_from='name', editable=True)
- fixed_initials=models.CharField(_('initials'), blank=True, null=True, max_length=5)
- type=models.ForeignKey(AuthorType)
- title=models.CharField(_('Title'), blank=True, null=True, max_length=100)
- organization=models.ForeignKey(Place, blank=True, null=True)
- about=models.TextField(_('about'), blank=True, null=True)
- user=models.ForeignKey(User, blank=True, null=True)
-
- def initials(self):
- if self.fixed_initials:
- return self.fixed_initials
- else:
- initials=''
- for i in self.name.split(" "):
- initials += i[0]
- return initials
- def __unicode__(self):
- return self.name
-
- @models.permalink
- def get_absolute_url(self):
- return ('nr-author-detail', (), {'type_slug': self.type.slug, 'slug': self.slug})
- class Meta:
- verbose_name=_('author')
- verbose_name_plural=_('authors')
- ordering=('name',)
- get_latest_by='created'
- class AttachedLink(models.Model):
- content_type = models.ForeignKey(ContentType)
- object_id = models.IntegerField(db_index=True)
- content_object = generic.GenericForeignKey()
- link=models.ForeignKey(Link)
-
- def __unicode__(self):
- return self.link.title
- class AttachedGraphic(models.Model):
- content_type = models.ForeignKey(ContentType)
- object_id = models.IntegerField(db_index=True)
- content_object = generic.GenericForeignKey()
- graphic = models.ForeignKey(Graphic)
-
- def __unicode__(self):
- return self.graphic.title
- class AttachedMovie(models.Model):
- content_type = models.ForeignKey(ContentType)
- object_id = models.IntegerField(db_index=True)
- content_object = generic.GenericForeignKey()
- movie=models.ForeignKey(Movie)
-
- def __unicode__(self):
- return self.movie.title
- class AttachedSlideshow(models.Model):
- content_type = models.ForeignKey(ContentType)
- object_id = models.IntegerField(db_index=True)
- content_object = generic.GenericForeignKey()
- slideshow=models.ForeignKey(Slideshow)
-
- def __unicode__(self):
- return self.slideshow.title
- class AttachedDocument(TimeStampedModel):
- content_type = models.ForeignKey(ContentType)
- object_id = models.IntegerField(db_index=True)
- content_object = generic.GenericForeignKey()
- document=models.ForeignKey(Document)
-
- class Meta:
- ordering = ['-created']
- get_latest_by = 'created'
-
- def __unicode__(self):
- return self.document.title
-
- def get_absolute_url(self):
- return self.document.get_absolute_url()
-
- def doc_dir(self):
- return os.path.dirname(self.get_file_filename())
-
- def remove_dirs(self):
- if os.path.isdir(self.doc_dir()):
- if os.listdir(self.doc_dir()) == []:
- os.removedirs(self.doc_dir())
-
- def delete(self):
- super(Document, self).delete()
- self.remove_dirs()
- class AttachedGallery(models.Model):
- content_type = models.ForeignKey(ContentType)
- object_id = models.IntegerField(db_index=True)
- content_object = generic.GenericForeignKey()
- gallery = models.ForeignKey(Gallery)
-
- def __unicode__(self):
- return self.gallery.title
- class Dateline(TimeStampedModel):
- '''Dateline model.
- A dateline specifies where a story's action takes place.
- The reason for the separate model is so that the string displayed
- can be custom, while the towns the dateline refers to are predetermined
- in the database. Thus a date line of: One Town and Anotehr Town or
- Our Community, can have specific locations related to them, while
- being able to be displayed per editorial spec.
- '''
- title=models.CharField(_('title'), max_length=100)
- slug=AutoSlugField(_('slug'), populate_from='title', editable=True)
- towns=models.ManyToManyField(Town)
- class Meta:
- ordering=('title',)
- def __unicode__(self):
- return self.title
- @models.permalink
- def get_absolute_url(self):
- return ('dateline_detail', (), {'slug':self.slug})
-
- MARKUP_HELP = _("""Select the type of markup you are using in this article.
- <ul>
- <li><a href="http://daringfireball.net/projects/markdown/basics" target="_blank">Markdown Guide</a></li>
- <li><a href="http://docutils.sourceforge.net/docs/user/rst/quickref.html" target="_blank">ReStructured Text Guide</a></li>
- <li><a href="http://thresholdstate.com/articles/4312/the-textile-reference-manual" target="_blank">Textile Guide</a></li>
- </ul>""")
- class StandingHed(TimeStampedModel):
- '''Standing Hed model.
- In lieu of a proper column or blog application, this is a hack to get some
- stories to always be associated with one author or column.
- '''
- title=models.CharField(_('Title'), max_length=100)
- slug=AutoSlugField(_('Slug'), populate_from='title', editable=True)
- def __unicode__(self):
- return self.title
-
- class Copy(TimeStampedModel):
- '''Copy model.
- An abstract model for anything that can be copy.
- By default, we have two choices for heds.
- If a different web_hed isn't specified, we use the one from print.
- '''
-
- print_hed=models.CharField(_('print headline'), max_length=255)
- web_hed=models.CharField(_('web headline'), max_length=255)
- standing_hed=models.ForeignKey(StandingHed, blank=True, null=True)
- slug=AutoSlugField(_('slug'), populate_from='web_hed', editable=True)
- kicker=models.CharField(_('kicker'), max_length=255, blank=True, null=True)
- subhed=models.CharField(_('sub-headline'), max_length=255, blank=True, null=True)
- body=models.TextField(_('body'))
- summary=models.TextField(_('summary'), blank=True)
- markup = models.CharField(max_length=1, choices=MARKUP_OPTIONS, default=MARKUP_DEFAULT, help_text=MARKUP_HELP)
- published=models.BooleanField(_('publish'), default=False)
- published_on=models.DateTimeField(_('publish date'), default=datetime.now())
- paper_editions = models.ManyToManyField('PaperEdition', blank=True, null=True)
- sites=models.ManyToManyField(Site)
- view_count = models.PositiveIntegerField(default=0, editable=False)
- created_by=models.ForeignKey(User, editable=False)
- auto_tag=models.BooleanField(_('auto-tag'), default=True)
- tags = TaggableManager(blank=True)
- class Meta:
- abstract=True
- ordering=('-published_on', 'print_hed')
- get_latest_by='published_on'
- @property
- def hed(self):
- if self.web_hed:
- return self.web_hed
- else:
- return self.print_hed
- @property
- def paragraphs(self):
- """
- Return the paragraphs as a list
- """
- import re
- if self.markup=='m':
- import markdown
- html=markdown.markdown(self.body)
- elif self.markup=='t':
- import textile
- html=textile.textile(self.body)
- elif self.markup=='r':
- html='Cant figure out how to implement RST yet...'
- else:
- html= self.body
- return re.findall("(<p.+?>.+?</p>)", html, re.I | re.S)
- def do_auto_tag(self):
- """
- Performs the auto-tagging work if necessary.
-
- Returns True if an additional save is required, False otherwise.
- """
- found = False
- if self.auto_tag:
- import re
- # don't clobber any existing tags!
- existing_ids = [t.id for t in self.tags.all()]
- unused = Tag.objects.all()
- unused = unused.exclude(id__in=existing_ids)
- for tag in unused:
- regex = re.compile(r'\b%s\b' % tag.name, re.I)
- if regex.search(self.body) or regex.search(self.web_hed) or regex.search(self.print_hed)\
- or regex.search(self.subhed) or regex.search(self.kicker):
- self.tags.add(tag)
- found = True
- return found
- def do_scrub_rich_text(self):
- scrubbed=False
- if self.markup == 'h':
- import re
- from django.template.defaultfilters import removetags
- self.body = re.sub('\n', ' ', re.sub('style=".*?"', '', re.sub('align=".*?"', '', removetags(self.body, "font br"))))
- scrubbed=True
- return scrubbed
- def do_set_summary(self):
- summarized=False
- if (len(self.paragraphs[0].split(' ')) > 100) or (len(self.paragraphs) == 1):
- self.summary = self.paragraphs[0]
- summarized=True
- elif len(self.paragraphs)==0:
- summarized=False
- else:
- self.summary = self.paragraphs[0] + self.paragraphs[1]
- summarized=True
- return summarized
-
- def save(self, *args, **kwargs):
-
- self.do_set_summary()
- super(TimeStampedModel, self).save(*args, **kwargs)
-
- self.do_auto_tag()
- self.do_scrub_rich_text()
-
- super(TimeStampedModel, self).save(*args, **kwargs)
- class Story(Copy):
- '''Story model.
-
- A story is one of our primary types of content.
-
- '''
- STATUS_CHOICES=( (0, 'None'), (1, 'Primary'), (2, 'Secondary'), )
- dateline=models.ForeignKey(Dateline)
- authors=models.ManyToManyField(Author, blank=True, null=True)
- lead_photo=models.ForeignKey(Photo, blank=True, null=True)
- cropped_photo=models.ImageField(_('cropped photo'), blank=True, null=True,upload_to='newsroom/cropped_photos/')
- status=models.IntegerField(_('status'), choices=STATUS_CHOICES, default=0)
- towns=models.ManyToManyField(Town)
- weight=models.IntegerField(_('Weight'), null=True, blank=True, default=0,
- help_text='Stories weighted higher appear before those with lower weights.')
- press_release=models.BooleanField(_('press release'), default=False)
- source=models.ForeignKey(Place, blank=True, null=True, help_text="Source of original copy if is a press release.")
- attached_documents=generic.GenericRelation(AttachedDocument)
- attached_gallery=generic.GenericRelation(AttachedGallery)
- attached_graphic=generic.GenericRelation(AttachedGraphic)
- attached_movie=generic.GenericRelation(AttachedMovie)
- attached_slideshow=generic.GenericRelation(AttachedSlideshow)
- # Custom story manager (see manager.py)
- objects = StoryManager()
- on_site = CurrentSiteManager('sites')
- class Meta:
- verbose_name_plural=('stories')
- ordering=('-published_on', 'web_hed', 'print_hed')
- get_latest_by='published_on'
- def prod_slug(self):
- authors=''
- for a in self.authors.all():
- authors = a.initials()
- if authors:
- return u'%s-%s' % (authors, self.slug)
- else:
- return u'PR-%s' % (self.slug)
-
- def __unicode__(self):
- return self.hed
-
- def editions(self):
- list = ""
- for e in self.edition_set.all():
- list += e.paper.name +" " + e.published_on.strftime("%m-%d-%y") + "; "
- return list
- @property
- def author(self):
- #link='<a href="%s" title="%s">%s</a>'
- string='%s'
- #authors=[link % (a.get_absolute_url(), a, a.name) for a in self.authors.all()]
- authors = [string % (a.name) for a in self.authors.all()]
- if len(authors) > 1:
- author_string="%s and %s" % (", ".join(authors[:-1]), authors[-1])
- if len(authors) == 1:
- author_string=authors[0]
- else:
- author_string = ''
- return mark_safe(author_string)
- @models.permalink
- def get_absolute_url(self, site=''):
- return ('nr-story-detail', (), {
- 'year': self.published_on.year,
- 'month': self.published_on.strftime('%b').lower(),
- 'day': self.published_on.day,
- 'slug': self.slug})
- def get_admin_url(self):
- return u'admin/newsroom/story/%s/' % (str(self.id))
- def get_relative_url(self):
- return u'news/%s/%s/%s/%s' % (self.published_on.year, self.published_on.strftime('%b').lower(), self.published_on.day, self.slug)
-
- class EditorialType(models.Model):
- '''Editorial Type model.
- A type of editorial...
- '''
- name= models.CharField(_('name'), max_length=100)
- slug=AutoSlugField(_('slug'), populate_from='name', editable=True)
- description=models.TextField(_('description'), blank=True, null=True)
- def __unicode__(self):
- return self.name
- @models.permalink
- def get_absolute_url(self):
- return ('editorial_type_detail', (), {'slug':self.slug})
- class Editorial(Copy):
- '''Editorial model.
-
- Manages editorial content: letter to the editor, editor's notes, corrections.
- '''
- dateline=models.ForeignKey(Dateline, blank=True, null=True)
- type = models.ForeignKey(EditorialType)
- author=models.ForeignKey(Author, blank=True, null=True)
- citizen_authors=models.ManyToManyField(Person, blank=True, null=True)
- towns=models.ManyToManyField(Town)
- # Custom story manager (see manager.py)
- objects = EditorialManager()
- on_site = CurrentSiteManager('sites')
- class Meta:
- verbose_name_plural=('editorials')
- ordering=('-published_on', 'web_hed', 'print_hed')
- get_latest_by='published_on'
- def __unicode__(self):
- return self.web_hed
- def editions(self):
- list = ""
- for e in self.edition_set.all():
- list += e.paper.name +" " + e.published_on.strftime("%m-%d-%y") + "; "
- return list
-
- @models.permalink
- def get_absolute_url(self, site=''):
- return ('nr-editorial-detail', (), {
- 'year': self.published_on.year,
- 'month': self.published_on.strftime('%b').lower(),
- 'day': self.published_on.day,
- 'slug': self.slug})
- def get_relative_url(self):
- return u'%s/%s/%s/%s' % (self.published_on.year, self.published_on.strftime('%b').lower(), self.published_on.day, self.slug)
- class PaperEdition(TimeStampedModel):
- paper=models.ForeignKey(Paper)
- published_on=models.DateField(_('publish on'))
- published=models.BooleanField(_('published'), default=False)
- site=models.ManyToManyField(Site)
- class Meta:
- verbose_name=_('Paper edition')
- verbose_name_plural=_('Paper editions')
- ordering=('-published_on', 'paper')
- get_latest_by='published_on'
-
- def __unicode__(self):
- return u'%s published %s' % (self.paper, self.published_on)
- class WebEdition(TimeStampedModel):
- paper = models.ForeignKey(Paper)
- published_on = models.DateField(_('publish on'))
- published = models.BooleanField(_('published'), default=False)
- site = models.ForeignKey(Site)
- featured_photo = models.ForeignKey(Photo, null=True, blank=True, related_name="featured_photo")
- featured_story = models.ForeignKey(Story, related_name="featured_story", null=True, blank=True)
- stories = models.ManyToManyField(
- Story,
- blank=True,
- null=True,
- help_text="Include the featured story in this list of all stories in this edition.",
- limit_choices_to={'published_on__gte': datetime.today()-timedelta(days = 45)},
- )
- photos = models.ManyToManyField(
- Photo,
- blank=True,
- null=True,
- related_name="photos",
- limit_choices_to={'published_on__gte': datetime.today()-timedelta(days = 45)},
- )
- galleries = models.ManyToManyField(
- Gallery,
- blank=True,
- null=True,
- limit_choices_to={'published_on__gte': datetime.today()-timedelta(days = 45)},
- )
- movies = models.ManyToManyField(Movie, blank=True, null=True)
- slideshows = models.ManyToManyField(Slideshow, blank=True, null=True)
- editorials = models.ManyToManyField(Editorial, blank=True, null=True)
- pdfdocuments = models.ManyToManyField(PDFDocument, blank=True, null=True)
- remembrances = models.ManyToManyField(
- Remembrance,
- blank=True,
- null=True,
- limit_choices_to={'published_on__gte': datetime.today()-timedelta(days = 45)},
- )
- death_announcements = models.ManyToManyField(
- Announcement,
- blank=True,
- null=True,
- limit_choices_to={'published_on__gte': datetime.today()-timedelta(days = 45)},
- )
- memorial_servicesl = models.ManyToManyField(
- Service,
- blank=True,
- null=True,
- limit_choices_to={'published_on__gte': datetime.today()-timedelta(days = 45)},
- )
- inmemoriams = models.ManyToManyField(
- InMemoriam,
- blank=True,
- null=True,
- limit_choices_to={'published_on__gte': datetime.today()-timedelta(days = 45)},
- )
- objects=EditionManager()
- on_site = CurrentSiteManager('site')
-
- # per-paper managers
- patriot=PatriotEditionManager()
- advantages=AdvantagesEditionManager()
- packet=PacketEditionManager()
- compass=CompassEditionManager()
-
- class Meta:
- verbose_name=_('Web edition')
- verbose_name_plural=_('Web editions')
- ordering=('-published_on', 'paper')
- get_latest_by='published_on'
-
- def __unicode__(self):
- return u'Web edition of %s published on %s' % (self.paper, self.published_on)
- '''
- def save(self):
- if not self.id:
- super(Edition, self).save(*args, **kwargs)
- if self.published==True:
- self.stories.all().update(published=True)
- self.galleries.all().update(published=True)
- self.slideshows.all().update(published=True)
- self.movies.all().update(published=True)
- self.editorials.all().update(published=True)
- for p in self.photos.all():
- p.published=True
- p.save()
- for s in self.stories.all():
- if s.lead_photo:
- s.lead_photo.published=True
- s.lead_photo.save()
- s.photos.all().update(published=True)
- for g in s.galleries.all():
- for p in g.photos.all():
- p.published=True
- p.save()
- for g in self.galleries.all():
- for p in g.photos.all():
- p.published=True
- p.save()
- for a in self.death_announcements.all():
- a.published=True
- a.save()
- for s in self.memorial_services.all():
- s.published=True
- s.save()
- for i in self.inmemoriams.all():
- i.published=True
- i.save()
- for r in self.remembrances.all():
- r.published=True
- r.save()
- else:
- self.stories.all().update(published=False)
- self.galleries.all().update(published=False)
- self.photos.all().update(published=False)
- self.slideshows.all().update(published=False)
- self.movies.all().update(published=False)
- self.editorials.all().update(published=False)
- for s in self.stories.all():
- if s.lead_photo:
- s.lead_photo.published=False
- s.lead_photo.save()
- for g in self.galleries.all():
- for p in g.photos.all():
- p.published=False
- p.save()
- for a in self.death_announcements.all():
- a.published=False
- a.save()
- for s in self.memorial_services.all():
- s.published=False
- s.save()
- for i in self.inmemoriams.all():
- i.published=False
- i.save()
- for r in self.remembrances.all():
- r.published=False
- r.save()
- super(WebEdition, self).save(*args, **kwargs)
- '''
- class ArchiveItem(TimeStampedModel):
- '''Archive item model.
- A base class inherited by whatever content class we want to stuff in the archive.
- Items are associated with a particular paper, can expire and belong to "groups"
- The groups allow for very basic access control, so we could sell access to certain
- archive items.
- '''
- archived_on=models.DateTimeField(_('Archived on'), default=datetime.now())
- expires_on=models.DateTimeField(_('Expires on'), blank=True, null=True)
- groups=models.ManyToManyField(Group, blank=True, null=True)
- paper=models.ForeignKey(Paper)
- class ArchiveSection(ArchiveItem):
- '''Archive section model.
- This model is used to collect editioral content into a produced section
- The group can then be displayed on as an archive on a particular subject.
- It actually duplicates a lot of what's in a story because section objects
- don't exist in and of their own like stories or documents.
- '''
- GROUP_BY_CHOICES = (
- ('type', _('Type')),
- ('dline', _('Dateline')),
- ('both', _('Both')),
- )
- title=models.CharField(_('title'), max_length=200)
- slug=AutoSlugField(_('slug'), populate_from='title', editable=True)
- description=models.TextField(_('body'))
- published=models.BooleanField(_('published'), default=False)
- published_on=models.DateTimeField(_('published on'))
- thumbnail=models.ImageField(_('Thumbnail'), blank=True, null=True, upload_to="newsroom/archives/thumbnails/")
- lead_image=models.ImageField(_('Lead image'), blank=True, null=True, upload_to="newsroom/archives/lead_images/")
- dateline=models.ForeignKey(Dateline, blank=True, null=True)
- stories=models.ManyToManyField(Story, blank=True, null=True)
- editorials=models.ManyToManyField(Editorial, blank=True, null=True)
- pdf_documents=models.ManyToManyField(PDFDocument, blank=True, null=True)
- photos=models.ManyToManyField(Photo, blank=True, null=True)
- galleries=models.ManyToManyField(Gallery, blank=True, null=True)
- movies=models.ManyToManyField(Movie, blank=True, null=True)
- slideshows=models.ManyToManyField(Slideshow, blank=True, null=True)
- group_by=models.CharField(_('Group by'), choices=GROUP_BY_CHOICES,
- default='type', max_length=10)
- class Meta:
- verbose_name=_('archive section')
- verbose_name_plural=('archive sections')
- ordering=['-modified']
- def __unicode__(self):
- return u'%s' % self.title
- @models.permalink
- def get_absolute_url(self):
- return ('nr-archive-section-detail', (), {'year':self.published_on.year, 'slug':self.slug})
- def get_relative_url(self):
- return u'%s/%s/' % (self.published_on.year, self.slug)
- class ArchiveStory(ArchiveItem):
- '''Archive story model.
- A wrapper class for putting stories into our "archive" section.
- '''
- story=models.ForeignKey(Story)
- class Meta:
- verbose_name=_('Archived story')
- verbose_name_plural=_('Archived stories')
- def __unicode__(self):
- return u'%s' % self.story.hed()
- @models.permalink
- def get_absolute_url(self):
- return self.story.get_absolute_url
- class ArchiveMovie(ArchiveItem):
- '''Archive movie model.
- A wrapper class for putting movies into our "archive" section.
- '''
- movie=models.ForeignKey(Movie)
- class Meta:
- verbose_name=_('Archived movie')
- verbose_name_plural=_('Archived movies')
- def __unicode__(self):
- return u'%s' % self.movie.title()
- @models.permalink
- def get_absolute_url(self):
- return self.movie.get_absolute_url
- class ArchiveSlideshow(ArchiveItem):
- '''Archive slideshow model.
- A wrapper class for putting slideshows into our "archive" section.
- '''
- slideshow=models.ForeignKey(Slideshow)
- class Meta:
- verbose_name=_('Archived slideshow')
- verbose_name_plural=_('Archived slideshows')
- def __unicode__(self):
- return u'%s' % self.slideshow.title()
- @models.permalink
- def get_absolute_url(self):
- return self.slideshow.get_absolute_url
- class ArchiveDocument(ArchiveItem):
- '''Archive document model.
- We need a way to stick documents in the archive...
- '''
- document=models.ForeignKey(Document)
- class Meta:
- verbose_name=_('Archived document')
- verbose_name_plural=_('Archived documents')
- def __unicode__(self):
- return u'%s' % self.document.title
- @models.permalink
- def get_absolute_url(self):
- return self.document.get_absolute_url
- '''
- class PageType(models.Model):
- name = models.CharField(_('name'), max_length=150)
- slug=AutoSlugField(_('slug'), populate_from='name', editable=True)
- description = models.TextField(_('description'), blank=True, null=True)
- class Meta:
- verbose_name=_('page type')
- verbose_name_plural=('page types')
- def __unicode__(self):
- return u'%s' % (self.name)
- class Page(models.Model):
- number=models.IntegerField(_('number'), max_length=3)
- edition=models.ForeignKey(Edition)
- copy_inches=models.IntegerField(_('inches of copy'), max_length=3, blank=True, null=True, help_text='If left blank, will be calcuated by included copy.' )
- ad_inches=models.IntegerField(_('inches of ads'), max_length=3, blank=True, null=True, help_text='If left blank, will be calcuated by included ads.' )
- ad_group=models.ForeignKey(AdCategory, null=True, blank=True, help_text='Primary ad group for page.')
- ad_notes=models.TextField(_('ad notes'), null=True, blank=True)
- ad_spec_pos=models.TextField(_('ad special position'), null=True, blank=True)
- ads = models.ManyToManyField(BannerAd, blank=True, null=True)
- copy = models.ManyToManyField(Story, blank=True, null=True )
- photos = models.ManyToManyField(Photo, blank=True, null=True )
- type = models.ForeignKey(PageType, blank=True, null=True )
- class Meta:
- verbose_name=_('page')
- verbose_name_plural=('pages')
- unique_together = (("number", "edition"),)
- def __unicode__(self):
- return u'Page %s of %s' % (self.number, self.edition)
- '''
|