models.py 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. from datetime import *
  2. from dateutil import relativedelta
  3. from django.db import models
  4. from django.db.models import permalink
  5. from django.utils.translation import ugettext_lazy as _
  6. from django.core.urlresolvers import reverse
  7. from django.contrib.auth.models import User
  8. from django.contrib.localflavor.us.models import PhoneNumberField, USStateField
  9. from django_extensions.db.fields import AutoSlugField
  10. from django_extensions.db.models import TimeStampedModel, TitleSlugDescriptionModel
  11. from directory.models import Point, Person, Town, Place
  12. from marketplace.models import Business, Guide
  13. from newsroom.models import Story
  14. from darkroom.models import Photo, Gallery, Slideshow, Movie
  15. from documents.models import PDFDocument
  16. class Category(TitleSlugDescriptionModel):
  17. """Categories model."""
  18. graphic=models.ImageField(_('Graphic'), upload_to='visitors/category/')
  19. brief_description=models.CharField(_('Brief description'), max_length=255,
  20. blank=True, null=True)
  21. teaser_name=models.CharField(_('Teaser name'), max_length=100,
  22. blank=True, null=True)
  23. template_name = models.CharField(_('template name'), max_length=70,
  24. blank=True,
  25. help_text=_("Example: 'visitors/categories/shopping.html'. If this isn't provided, the system will use 'visitors/categories/default.html'."))
  26. class Meta:
  27. verbose_name = _('Category')
  28. verbose_name_plural = _('Categories')
  29. ordering=('title',)
  30. def __unicode__(self):
  31. return u'%s' % self.title
  32. def get_absolute_url(self):
  33. return reverse ('vs-category-index', args=[self.slug])
  34. class Feature(TimeStampedModel):
  35. name=models.CharField(_('name'), max_length=200)
  36. slug=models.SlugField(_('slug'), unique=True)
  37. description=models.CharField(_('description'), max_length=255, blank=True, null=True)
  38. class Meta:
  39. verbose_name=_('feature')
  40. verbose_name_plural=_('features')
  41. ordering=('name',)
  42. def __unicode__(self):
  43. return u'%s' % self.name
  44. class Attraction(TimeStampedModel):
  45. '''
  46. Base class for attractions
  47. '''
  48. name=models.CharField(_('name'), max_length=255)
  49. slug=AutoSlugField(_('slug'), editable=True,
  50. populate_from='name')
  51. published=models.BooleanField(_('Published'), default=False)
  52. pub_date=models.DateField(_('Publish date'))
  53. point=models.ForeignKey(Point, blank=True, null=True)
  54. town=models.ForeignKey(Town, blank=True, null=True,
  55. help_text="Point above will override this if attraction given a point.")
  56. place=models.ForeignKey(Place, blank=True, null=True,
  57. help_text='Use EITHER this or town or point fields.')
  58. owner=models.ForeignKey(Person, blank=True, null=True)
  59. brief_hours=models.CharField(_('brief hours'), blank=True, null=True,
  60. max_length=255)
  61. logo=models.ImageField(_('logo or photo'), upload_to="portal/logos/",
  62. blank=True)
  63. phone=PhoneNumberField(_('primary phone'), blank=True, null=True)
  64. url=models.URLField(_('url'), blank=True, verify_exists=False)
  65. brief_hours=models.CharField(_('brief hours'), blank=True, null=True,
  66. max_length=255)
  67. directions=models.CharField(_('directions'), blank=True, null=True,
  68. max_length=255)
  69. admission=models.CharField(_('Admission'), blank=True, null=True,
  70. max_length=100)
  71. description=models.TextField(_('description'), blank=True, null=True)
  72. features=models.ManyToManyField(Feature, blank=True, null=True)
  73. categories=models.ManyToManyField(Category)
  74. related_business=models.ForeignKey(Business, blank=True, null=True)
  75. class Meta:
  76. verbose_name=_('Attraction')
  77. verbose_name_plural=_('Attractions')
  78. ordering=('point__town', 'town', 'name')
  79. get_latest_by='created'
  80. def __unicode__(self):
  81. return u'%s' % self.name
  82. def get_absolute_url(self):
  83. return reverse('vs-attraction-detail', args=[self.slug])
  84. class Section(TimeStampedModel):
  85. '''
  86. Section model.
  87. A collection of attractions with a specific name that maps to a printed
  88. publication.
  89. Businesses may be selected using either whole categories of businesses, or
  90. by specifically specifying businesses to include, or a mix of both.
  91. '''
  92. title = models.CharField(_('Title'), max_length=255)
  93. slug=AutoSlugField(_('Slug'), editable=True,
  94. populate_from='title')
  95. published=models.BooleanField(_('Published'), default=False)
  96. pub_date=models.DateField(_('Publish date'))
  97. featured=models.BooleanField(_('Featured'), default=False)
  98. featured_on=models.DateTimeField(_('Featured on'), default=datetime.now(),
  99. blank=True, null=True)
  100. featured_until=models.DateTimeField(_('Featured until'),
  101. blank=True, null=True)
  102. logo=models.ImageField(_('Logo'), upload_to="marketplace/section/logos/",
  103. blank=True)
  104. logo_thumbnail=models.ImageField(_('Thumbnail of logo (optionl)'),
  105. upload_to="marketplace/section/logos/thumbnails/",
  106. blank=True, null=True,
  107. help_text='An optional thumbnail of the logo. If not used, a thumbnail will be generated from the logo.')
  108. tag_line=models.CharField(_('Tag line'), max_length=255,
  109. blank=True, null=True)
  110. brief_description=models.CharField(_('Brief description'), max_length=255,
  111. blank=True, null=True)
  112. description=models.TextField(_('Description'),blank=True,null=True)
  113. categories=models.ManyToManyField(Category, blank=True, null=True)
  114. businesses=models.ManyToManyField(Business, blank=True, null=True)
  115. attractions=models.ManyToManyField(Attraction, blank=True, null=True)
  116. template_name = models.CharField(_('template name'), max_length=70,
  117. blank=True,
  118. help_text=_("Example: 'visitors/sections/outdoor_handbook.html'. If this isn't provided, the system will use 'visitors/sections/default.html'."))
  119. class Meta:
  120. verbose_name=_('Section')
  121. verbose_name_plural=_('Sections')
  122. get_latest_by='featured_on'
  123. def __unicode__(self):
  124. return u'%s' % (self.title)
  125. def get_absolute_url(self):
  126. args=[self.slug]
  127. return reverse('vs-section-detail', args=args)
  128. class VisitorsEdition(TimeStampedModel):
  129. '''
  130. Visitors portal edition model.
  131. Similar to editions in the Newsroom application.
  132. '''
  133. title=models.CharField(_('Title'), max_length=100)
  134. brief_description=models.CharField(_('Brief description'), blank=True,
  135. null=True, max_length=255)
  136. featured_story=models.ForeignKey(Story, related_name='ve_featured_story', blank=True, null=True)
  137. featured_photo=models.ForeignKey(Photo, related_name='ve_featured_photo', blank=True, null=True)
  138. published_on=models.DateField(_('publish on'))
  139. published=models.BooleanField(_('published'), default=False)
  140. stories=models.ManyToManyField(Story, blank=True, null=True, help_text="Include the featured story in this list of all stories in this edition.")
  141. photos=models.ManyToManyField(Photo, blank=True, null=True, related_name="ve_photos")
  142. galleries=models.ManyToManyField(Gallery, blank=True, null=True, related_name="ve_galleries")
  143. movies=models.ManyToManyField(Movie, blank=True, null=True, related_name="ve_movies")
  144. slideshows=models.ManyToManyField(Slideshow, blank=True, null=True, related_name="ve_slideshows")
  145. pdfdocuments=models.ManyToManyField(PDFDocument, blank=True, null=True, related_name="ve_pdfdocs")
  146. guides=models.ManyToManyField(Guide, blank=True, null=True, related_name="ve_guides")
  147. sections=models.ManyToManyField(Section, blank=True, null=True, related_name="ve_sections")
  148. class Meta:
  149. verbose_name=_('Visitors edition')
  150. verbose_name_plural=_('Visitors editions')
  151. get_latest_by='published_on'
  152. def __unicode__(self):
  153. return u'Visitors edition - %s' % (self.published_on)
  154. def get_absolute_url(self):
  155. args=[self.slug]
  156. return reverse('vs-visitors-edition-detail', args=args)