示例#1
0
class SundayHours(cms.Model, models.Model):
    """
	Model for additional Sunday hours for locations
	"""

    qa_objects = cms.QAManager()
    objects = cms.Manager()
    all_objects = models.Manager()

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(
        max_length=1,
        default=u'1',
        choices=cms.Model.ACTIVE,
        help_text=
        "Select Inactive to remove these hours from display on the site.")
    location = models.ForeignKey(Location)
    service = models.ForeignKey('services.Service',
                                related_name='location_sunday_hours')
    position = models.PositiveSmallIntegerField(
        default=1,
        help_text=
        "Enter a number to set the order for this location on display pages. Smaller numbers appear first."
    )
    hours = models.CharField(max_length=150,
                             blank=True,
                             help_text="Service hours eg 7:00 PM - 11:00 PM.")

    class Meta:
        verbose_name_plural = u'Sunday hours'

    def __unicode__(self):
        return u"%d: %s" % (self.pk, self.hours)
示例#2
0
class MBGroup(cms.Model, models.Model):
	"""
	Model for Marketing Banner Groups

	There is a many-to-many relationship:
	A single MarketingBanner may belong to zero or more MBGroups,
	and each MBGroup may hold zero or more MarketingBanners.

	Each MBGroup may individually be activated or deactivated,
	regardless of the settings of its member MarketingBanners.

	"""
	
	qa_objects = cms.QAManager()
	objects = cms.Manager()
	all_objects = models.Manager()
	
	for_update = models.PositiveSmallIntegerField(default=2, editable=False)
	active = models.CharField(max_length=1, default=u'1', choices=cms.Model.ACTIVE, help_text="Select Inactive to remove this Marketing Group from display and search on the site.")
	name = models.CharField(max_length=50, help_text="Please enter a name for this Group of Marketing Banners")
	banners = models.ManyToManyField(MarketingBanner, blank=True, null=True, verbose_name="Select a list of Marketing Banners")
	start_date = models.DateField(blank=True, null=True, help_text="You may enter an optional date on which to start display of this group.")
	end_date = models.DateField(blank=True, null=True, help_text="You may enter an option date on which to end display of this group.")
	urls = models.TextField(help_text="Enter one or more local URLs (e.g. 'service/cardiology') under which this marketing banner will be displayed. Enter one URL per line.")

	def __unicode__(self):
		return self.name

	class Meta:
		verbose_name = "Marketing Banner Group"
		verbose_name_plural = "Marketing Banner Groups"
示例#3
0
class MarketingBanner(cms.Model, models.Model):
	"""
	Model for holding Marketing Banner images

	Height and width fields are prepopulated with our standard,
	but not enforced by the model.

	Each Marketing Banner may individually be activated or deactivated,
	regardless of its group membership.

	"""
	
	qa_objects = cms.QAManager()
	objects = cms.Manager()
	all_objects = models.Manager()
	
	for_update = models.PositiveSmallIntegerField(default=2, editable=False)
	active = models.CharField(max_length=1, default=u'1', choices=cms.Model.ACTIVE, help_text="Select Inactive to remove this Marketing Banner from display on the site.")
	name = models.CharField(max_length=50, help_text="Please enter a name for this Marketing Banner.")
	image = models.ImageField(width_field='', height_field='', upload_to='db/marketing_banners/%Y/%m/%d')
	date_added = models.DateField(auto_now_add=True)
	link = models.ForeignKey(Resource, help_text="Select the resource that this banner links to.")
	
	def __unicode__(self):
		return self.name
	
	class Meta:
		verbose_name = "Marketing Banner"
		verbose_name_plural = "Marketing Banners"
示例#4
0
class URLAlias(cms.Model, models.Model):
    """
	Model for URL Aliases
	"""
    qa_objects = cms.QAManager()
    objects = cms.Manager()
    all_objects = models.Manager()

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(
        max_length=1,
        default=u'1',
        choices=cms.Model.ACTIVE,
        help_text="Select Inactive to remove this URL alias.")
    urlname = models.CharField(
        max_length=50,
        unique=True,
        help_text="Enter identifier for this alias URL (e.g. 'cardiology')")

    class Meta:
        ordering = ['urlname']
        verbose_name = "URL Alias"
        verbose_name_plural = "URL Aliases"

    def __unicode__(self):
        return u'%s' % self.urlname
示例#5
0
class Link_Body(cms.Model, models.Model):
    """
	Model for resource links associated with this service displayed in the body content
	"""

    qa_objects = cms.QAManager()
    objects = cms.Manager()
    all_objects = models.Manager()

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(
        max_length=1,
        default=u'1',
        choices=cms.Model.ACTIVE,
        help_text=
        "Select Inactive to remove this link from display and search on the site."
    )
    resource = models.ForeignKey(site.Resource,
                                 related_name='service_resource_body')
    service = models.ForeignKey(Service)
    position = models.PositiveSmallIntegerField(max_length=2)

    class Meta:
        ordering = ['position']
        verbose_name = "Link for content well display"
        verbose_name_plural = "Links for content well display"

    def __unicode__(self):
        return u'%s (%s)' % (self.service, self.resource)
示例#6
0
class Link_Nav(cms.Model, models.Model):
    """
	Model for resource links associated with this doctor
	"""

    qa_objects = cms.QAManager()
    objects = cms.Manager()
    all_objects = models.Manager()

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(
        max_length=1,
        default=u'1',
        choices=cms.Model.ACTIVE,
        help_text=
        "Select Inactive to remove this item from display and search on the site."
    )
    resource = models.ForeignKey(site.Resource,
                                 related_name='doctor_resource_nav')
    doctor = models.ForeignKey(Doctor)
    position = models.PositiveSmallIntegerField(max_length=2)

    class Meta:
        ordering = ['resource']
        verbose_name = "Link for nav display"
        verbose_name_plural = "Links for nav display"

    def __unicode__(self):
        return u'%s (%s)' % (self.doctor, self.resource)
示例#7
0
class MediaFile(cms.Model, models.Model):
    """
	Model for a media library.
		
	"""

    qa_objects = cms.QAManager()
    objects = cms.Manager()
    all_objects = models.Manager()

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(max_length=1,
                              default=u'1',
                              choices=cms.Model.ACTIVE,
                              editable=False)
    category = models.ForeignKey(MediaCategory,
                                 help_text="Select a category for this file.")
    name = models.CharField(max_length=50,
                            help_text="Enter a name for this file.")
    description = models.CharField(
        max_length=200,
        blank=True,
        help_text="Enter an optional description for this file.")
    mediafile = models.FileField(
        upload_to='db/media-library',
        help_text="File to upload to the media library.")

    def __unicode__(self):
        return u'%s' % (self.mediafile)

    def get_absolute_url(self):
        return self.get_mediafile_url()
示例#8
0
class TestModel(cms.Model, Model, models.Model):
    """
	This model tests the content management system and the search system together.
	
	>>> from smgsite.search.models import TestModel
	>>> from smgsite.cms.models import Change
	>>> from smgsite.search import interface
	>>> x = TestModel(testa=5, testb='teststring')
	>>> x.save(preview=False)
	>>> (count, results) = interface.search('prefix', 'TestModel', 'alpha', 'tes', '')
	SEARCH
	prefix
	TestModel
	alpha
	tes
    <BLANKLINE>
    <BLANKLINE>
	['0']
	>>> x.for_update = 0
	>>> x.save(preview=False)
	>>> (count, results) = interface.search('prefix', 'TestModel', 'alpha', 'tes', '')
	SEARCH
	prefix
	TestModel
	alpha
	tes
    <BLANKLINE>
    <BLANKLINE>
	['1', 'TestModel:1:none:teststring']
	>>> x.delete(preview=False)
	>>> (count, results) = interface.search('prefix', 'TestModel', 'alpha', 'tes', '')
	SEARCH
	prefix
	TestModel
	alpha
	tes
    <BLANKLINE>
    <BLANKLINE>
	['0']
	"""

    qa_objects = cms.QAManager()
    objects = cms.Manager()
    all_objects = models.Manager()

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.BooleanField(default=True)
    testa = models.IntegerField()
    testb = models.CharField(max_length=25)

    def search_index(self):
        # Return a (key, url, order, display, name, body) tuple with text for indexing
        return (self.pk, 'none', self.testb, self.testb, self.testb,
                self.testb)
示例#9
0
class Image(cms.Model, models.Model):
    """
	Model for an image library.
		
	"""

    qa_objects = cms.QAManager()
    objects = cms.Manager()
    all_objects = models.Manager()

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(max_length=1,
                              default=u'1',
                              choices=cms.Model.ACTIVE,
                              editable=False)
    name = models.CharField(max_length=50,
                            help_text="Enter a name for this image.")
    category = models.ForeignKey(MediaCategory,
                                 help_text="Select a category for this image.")
    description = models.CharField(
        max_length=200,
        blank=True,
        help_text="Enter an optional description for this image.")
    alt = models.CharField(
        max_length=75,
        help_text=
        "Enter an alt tag value for this image. The text should state the function of the image, such as: 'Welcome to SMG' - 'Greetings from Our Staff' - 'Click to Submit'."
    )
    image = models.ImageField(
        width_field='',
        height_field='',
        upload_to='db/image-library',
        help_text="Image to upload to the image library.")
    thumbnail = models.ImageField(
        blank=True,
        width_field='',
        height_field='',
        upload_to='db/image-library',
        help_text=
        "Optional thumbnail of image. Normally this is created from the image and scaled to be no larger than %sx%s"
        % (THUMBNAIL_MAX_WIDTH, THUMBNAIL_MAX_HEIGHT))

    def __unicode__(self):
        return u'%s' % (self.name)

    def get_absolute_url(self):
        return self.image.url

    def save(self, preview=True):
        if not self.thumbnail:
            image_make_thumbnail(self, 'image', 'thumbnail',
                                 'db/image-library', THUMBNAIL_MAX_WIDTH,
                                 THUMBNAIL_MAX_HEIGHT)
        super(Image, self).save(preview)
示例#10
0
class Resource(cms.Model, models.Model):
    """
	Model for on-site and off-site resource links.
		
	"""

    qa_objects = cms.QAManager()
    objects = cms.Manager()
    all_objects = models.Manager()

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(
        max_length=1,
        default=u'1',
        choices=cms.Model.ACTIVE,
        help_text=
        "Select Inactive to remove this article from display and search on the site."
    )
    name = models.CharField(
        max_length=50,
        unique=True,
        help_text="Enter a display name for this resource.")
    description = models.CharField(
        max_length=200,
        blank=True,
        help_text="Enter an optional description for this resource.")
    remote = models.BooleanField(
        editable=False,
        default=False,
        help_text="Check this box if the URL below is outsite the SMG site.")
    url = models.CharField(
        max_length=200,
        unique=True,
        help_text=
        "Enter a URL for this resource (e.g. '/service/cardiology/' or 'http://www.webmd.com/')."
    )

    class Meta:
        ordering = ['name']

    def __unicode__(self):
        return u'%s - %s' % (self.name, self.url)

    def save(self, preview=True):
        self.remote = False
        if host_re.match(self.url):
            self.url = 'http://%s/' % self.url
        elif site_re.match(self.url):
            self.url = 'http://%s' % self.url
        if self.url.startswith('http://'):
            self.remote = True
        super(Resource, self).save(preview)
示例#11
0
class EventBanner(cms.Model, models.Model):
    """
	Model for holding Event Banner images

	Height and width fields are prepopulated with our standard,
	but not enforced by the model.
	"""

    qa_objects = cms.QAManager()
    objects = cms.Manager()
    all_objects = models.Manager()

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(
        max_length=1,
        default=u'1',
        choices=cms.Model.ACTIVE,
        help_text=
        "Only one Event Banner can be active. If you set this Event Banner to be active, it will deactivate any other event currently set to active."
    )
    name = models.CharField(
        max_length=50, help_text="Please enter a name for this Event Banner.")
    image = models.ImageField(width_field='',
                              height_field='',
                              upload_to='db/event_banners/%Y/%m/%d')
    date_added = models.DateField(auto_now_add=True)
    link = models.ForeignKey(
        Event,
        blank=True,
        null=True,
        help_text="Select the event that this banner links to.")

    def __unicode__(self):
        return self.name

    class Meta:
        verbose_name = "Event Banner"
        verbose_name_plural = "Event Banners"

    def save(self, preview=True, recurse=False):
        if self.active == u'1' and not preview and not recurse:
            for e in EventBanner.objects.all():
                e.active = u'0'
                e.save(preview=False, recurse=True)
            self.active = u'1'
        super(EventBanner, self).save(preview=preview)

    def get_url(self):
        try:
            return self.link.get_absolute_url()
        except Event.DoesNotExist:
            return '/events/'
示例#12
0
class VideoTemplate(cms.Model, models.Model):
    """
	Model for magnify.net video template code
	"""

    qa_objects = cms.QAManager()
    objects = cms.Manager()
    all_objects = models.Manager()

    # Each place can have a maximum number of videos
    # which are radomly rotated.
    PLACES = (('H', 'Homepage'), )
    LIMITS = (('H', 1), )

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(max_length=1,
                              default=u'1',
                              choices=cms.Model.ACTIVE,
                              editable=False)
    location = models.CharField(
        max_length=1,
        choices=PLACES,
        help_text="Select the location for this video.")
    template = models.TextField(
        help_text="Paste the video template generated at magnify.net here.")
    description = models.CharField(verbose_name="Title",
                                   max_length=100,
                                   blank=True,
                                   help_text="Enter a title.")
    summary = models.TextField(blank=True,
                               help_text="Enter a summary paragraph")

    class Meta:
        verbose_name = "Video Template"
        verbose_name_plural = "Video Templates"

    def location_count(self):
        count = [val for key, val in self.LIMITS if key == self.location][0]
        return count

    def __unicode__(self):
        return u'Video template for %s' % (self.get_location_display())

    def save(self, preview=True):
        from django import forms
        current = VideoTemplate.all_objects.filter(location=self.location)
        if len(current) >= self.location_count() and self not in current:
            raise forms.ValidationError(
                'A limit of %d is set for templates for the location %s. Please remove one or more existing templates before attempting to add a new one.'
                % (self.location_count(), self.get_location_display()))
        super(VideoTemplate, self).save(preview=preview)
示例#13
0
class Location(cms.Model, models.Model):
    """
	Model for Service locations
	"""

    qa_objects = cms.QAManager()
    objects = cms.Manager()
    all_objects = models.Manager()

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(
        max_length=1,
        default=u'1',
        choices=cms.Model.ACTIVE,
        help_text=
        "Select Inactive to remove this item from display and search on the site."
    )
    service = models.ForeignKey(Service)
    location = models.ForeignKey(site.Location,
                                 related_name="services_location")
    position = models.PositiveSmallIntegerField(
        default=10,
        help_text=
        "Enter a number to set the order for this location on display pages. Smaller numbers appear first."
    )
    extra1 = models.CharField(
        "First extra info",
        max_length=300,
        blank=True,
        help_text=
        "First extra location information, displayed with the address, e.g. South Building."
    )
    extra2 = models.CharField(
        "Second extra info",
        max_length=300,
        blank=True,
        help_text=
        "Second extra location information, displayed with the address, e.g. Suite 200."
    )
    extra3 = models.CharField(
        "Third extra info",
        max_length=300,
        blank=True,
        help_text=
        "Third extra location information, displayed after the address, e.g. Use rear entrance and left elevator bank."
    )

    def __unicode__(self):
        return u"%d: %s -- %s -- %s" % (self.pk, self.extra1, self.extra2,
                                        self.extra3)
示例#14
0
class TrendingTopic(cms.Model, models.Model):

    qa_objects = cms.QAManager()
    objects = cms.Manager()
    all_objects = models.Manager()

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(
        max_length=1,
        default=u'1',
        choices=cms.Model.ACTIVE,
        help_text=
        "Select Inactive to remove this media result from display and search on the site."
    )
    headline = models.CharField(
        max_length=200, help_text="Enter the headline of this trending topic.")
    content = models.TextField(
        help_text="Enter the content of this trending topic.")
    experts = models.ManyToManyField(
        Doctor,
        blank=True,
        help_text="Select the SMG professionals who are experts for this topic."
    )
    image = models.ImageField(
        blank=True,
        null=True,
        width_field='',
        height_field='',
        upload_to='db/trending-images',
        help_text="Upload an image for this trending topic.")
    sort_order = models.PositiveSmallIntegerField(
        default=None,
        null=True,
        help_text=
        "Select the sort order position for this trending topic. Set to 0 to remove from ordering."
    )

    class Meta:
        ordering = ['-sort_order']
        verbose_name = "SMG Trending Topics"
        verbose_name_plural = "SMG Trending Topics"

    def __unicode__(self):
        return u'%s' % (self.headline)

    def save(self, preview=True, post=True):
        if self.sort_order == 0:
            self.sort_order = None
        super(TrendingTopic, self).save(preview=preview, post=post)
示例#15
0
class ImageSlide(cms.Model, models.Model):
    """
		Model for homepage image slider
	"""

    qa_objects = cms.QAManager()
    objects = ImageSlideManager()
    all_objects = models.Manager()

    URL_TARGET = (
        ('_self', 'Same Window'),
        ('_blank', 'New Window'),
    )

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(max_length=1,
                              default=u'1',
                              choices=cms.Model.ACTIVE)

    name = models.CharField(max_length=100,
                            help_text="Enter a reference name for this slide.")
    display_time = models.DateTimeField(
        blank=True,
        default=datetime.now(),
        help_text='Choose a time when the image should be displayed from.')
    image = models.ImageField(upload_to='db/images/slider/',
                              help_text="Image to use on the slider.")
    url = models.CharField(
        max_length=255,
        help_text="URL for this slide, either relative or absolute.")
    target = models.CharField(
        max_length=10,
        choices=URL_TARGET,
        default="_self",
        help_text="Select the target location for the URL.")
    order = models.PositiveIntegerField(default=0, help_text="Rotation order.")

    class Meta:
        verbose_name = "Image Slide"
        verbose_name_plural = "Image Slides"
        ordering = ['order']

    def __unicode__(self):
        return self.name
示例#16
0
class Degree(cms.Model, models.Model):
    """
	Model for Doctor degrees
	
	Examples include:
	BS: Fairleigh Dickinson University, New Jersey; 1990
	DO: New York College of Osteopathic Medicine, New York
	DPM: Cum Laude, New York College of Podiatric Medicine, New York, NY. June 2004
	
	Has a one-to-many relationship to doctors:
	each doctor can have zero or more degrees.
	"""

    qa_objects = cms.QAManager()
    objects = cms.Manager()
    all_objects = models.Manager()
    qa = False  # Secret QA flag

    parent = 'doctor'

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(
        max_length=1,
        default=u'1',
        choices=cms.Model.ACTIVE,
        help_text=
        "Select Inactive to remove this item from display and search on the site."
    )
    doctor = models.ForeignKey(Doctor)
    letters = models.ForeignKey(Degree_letters)
    description = models.CharField(
        max_length=300,
        help_text=
        "Enter description (e.g. 'University of Pennsylvania, Pennsylvania; 1973')."
    )

    def __unicode__(self):
        return u"%s %s" % (self.letters, self.description)

    class Meta:
        pass
示例#17
0
class Specialty(cms.Model, search.Model, models.Model):
    """
	Model for doctor specialties
	"""

    qa_objects = cms.QAManager()
    objects = cms.Manager()
    all_objects = models.Manager()
    item_url = 'specialty'
    search_order = 3
    search_limit = 10

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(
        max_length=1,
        default=u'1',
        choices=cms.Model.ACTIVE,
        help_text=
        "Select Inactive to remove this specialty from display and search on the site."
    )
    specialty = models.CharField(max_length=100,
                                 unique=True,
                                 help_text="Enter the name of the specialty.")

    class Meta:
        ordering = ['specialty']
        verbose_name_plural = "Specialties"

    def __unicode__(self):
        return u'%s' % self.specialty

    def get_absolute_url(self):
        return "/doctor-specialty?search-input=%s" % self.specialty

    def search_index(self):
        # Return a (key, url, order, display, name, body) tuple with text for indexing
        return SearchKey(self.pk, self.get_absolute_url(), self.specialty,
                         self.specialty, self.specialty, self.specialty)

    def name(self):
        return self.specialty
示例#18
0
class Accreditation(cms.Model, models.Model):
    """
	Model for Doctor accreditations, including residencies, fellowships, and board certifications.
	
	Examples include:
	Residency: Internal Medicine/Primary Care, Columbia Presbyterian Medical Center, New York, NY, 1997-2000
	Board Certification: Licensed Psychologist; Cognitive Therapist, American Academy of Cognitive Therapy
	
	Has a one-to-many relationship to doctors:
	each doctor can have zero or more accreditation entries.
	"""

    qa_objects = cms.QAManager()
    objects = cms.Manager()
    all_objects = models.Manager()
    parent = 'doctor'

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(
        max_length=1,
        default=u'1',
        choices=cms.Model.ACTIVE,
        help_text=
        "Select Inactive to remove this item from display and search on the site."
    )
    doctor = models.ForeignKey(Doctor)
    name = models.ForeignKey(Accreditation_name)
    description = models.CharField(
        max_length=300,
        help_text=
        "Enter description (e.g. 'Licensed Psychologist; Cognitive Therapist, American Academy of Cognitive Therapy')."
    )

    class Meta:
        pass

    def __unicode__(self):
        return u"%s %s" % (self.name, self.description)
示例#19
0
class HomepageImage(cms.Model, models.Model):
    """
	Model for changing specific images on the homepage
	"""

    qa_objects = cms.QAManager()
    objects = cms.Manager()
    all_objects = models.Manager()

    PLACES = (
        ('N', 'Our News'),
        ('H', 'Health'),
        ('E', 'Events'),
    )

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(max_length=1,
                              default=u'1',
                              choices=cms.Model.ACTIVE,
                              editable=False)
    location = models.CharField(
        max_length=1,
        unique=True,
        choices=PLACES,
        help_text="Select the location for this homepage image.")
    image = models.ForeignKey(
        Image, help_text="Select the image to appear in the selecte location.")
    link = models.URLField(blank=True,
                           help_text="Enter an optional link for this image.")

    class Meta:
        verbose_name = "Homepage Image"
        verbose_name_plural = "Homepage Images"

    def __unicode__(self):
        return u'Homepage image for %s' % (self.get_location_display())
示例#20
0
class Page(cms.Model, search.Model, models.Model):
    """
	Model for CMS controlled custom pages on the site.
	"""
    qa_objects = cms.QAManager()
    objects = cms.Manager()
    all_objects = models.Manager()
    search_order = 8
    search_limit = 10

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(
        max_length=1,
        default=u'1',
        choices=cms.Model.ACTIVE,
        help_text=
        "Select Inactive to remove this page from display and search on the site."
    )
    directory = models.ForeignKey(Directory, blank=True, null=True)
    urlname = models.CharField(
        max_length=50,
        blank=True,
        help_text=
        "Enter end of URL (e.g. enter 'aboutus' to have this Service load at '/aboutus/'). This Urlname is appended to the Directory above to create the complete path. It is not necessary to enter / characters."
    )
    keywords = models.CharField(
        max_length=500,
        blank=True,
        help_text="Enter optional Top Match keywords separated by spaces.")
    meta_description = models.TextField(
        blank=True, help_text="Enter an optional meta description for SEO.")
    title = models.CharField(max_length=100,
                             help_text="Enter the title of this page.")
    content = models.TextField(blank=True)
    marketing_banner = models.ForeignKey(
        MarketingBanner,
        related_name="pages_marketing_banner",
        blank=True,
        null=True,
        help_text=
        "Enter an additional marketing banner to be associated with this page."
    )

    url = models.CharField(
        'URL',
        blank=True,
        max_length=100,
        help_text="Enter URL path for this page. Example: /help/faq/")
    template_name = models.CharField(
        'Template',
        max_length=70,
        blank=True,
        help_text=
        "Select a template. If this isn't provided, the system will use 'default.html'."
    )

    class Meta:
        verbose_name = 'Summit Medical Group Pages'
        verbose_name_plural = 'Summit Medical Group Pages'

    def __unicode__(self):
        return self.title

    def get_absolute_url(self):
        if self.urlname:
            return "/%s/%s/" % (self.directory, self.urlname)
        else:
            return iri_to_uri(get_script_prefix().rstrip('/') + self.url)

    def cms_directory_id_display(self, directory_id):
        if self.directory:
            try:
                return Directory.objects.get(pk=directory_id).directory
            except:
                return '(none)'
        else:
            return '(none)'

    def search_index(self):
        # Return a (key, url, order, display, name, body) tuple with text for indexing
        body = "%s %s" % (self.title, self.content)
        return SearchKey(self.pk, self.get_absolute_url(), self.title,
                         self.title, self.title, body)

    def keyword_index(self):
        # Return a (key, url, order, display, name, body) tuple with text for keyword indexing
        return SearchKey(self.pk, self.get_absolute_url(), self.title,
                         self.title, self.keywords, self.keywords)
示例#21
0
class Service(cms.Model, search.Model, models.Model):
    """
	Model for Services and Specialties
	
	This is a list of all the specialties and services at SMG.
	"""

    qa_objects = cms.QAManager()
    objects = cms.Manager()
    all_objects = models.Manager()
    item_url = 'service'
    template_path = 'services'
    search_order = 2
    search_limit = 10

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(
        max_length=1,
        default=u'1',
        choices=cms.Model.ACTIVE,
        help_text=
        "Select Inactive to remove this service from display and search on the site."
    )
    urlname = models.CharField(
        max_length=50,
        unique=True,
        help_text=
        "Enter identifier for URL (e.g. enter 'cardiology' to have this Service load at '/service/cardiology/')."
    )
    template = models.ForeignKey(
        Template,
        blank=True,
        null=True,
        help_text=
        "Select the template to be used to render this service for display.")
    aliases = models.ManyToManyField(URLAlias,
                                     blank=True,
                                     null=True,
                                     help_text="URL Aliases")
    keywords = models.CharField(
        max_length=500,
        blank=True,
        help_text="Enter optional Top Match keywords separated by spaces.")
    meta_description = models.TextField(
        blank=True, help_text="Enter an optional meta description for SEO.")
    seo_keywords = models.TextField(
        blank=True,
        help_text=
        "Enter optional keywords for SEO. These are not used for site search.")
    name = models.CharField(
        max_length=100,
        unique=True,
        help_text="Enter the full name of this service (e.g. Cardiology).")
    practitioner_name = models.CharField(
        max_length=100,
        blank=True,
        help_text=
        "Enter the name of a practitoner of this service (e.g. Cardiologist).")
    practitioner_group = models.CharField(
        max_length=100,
        blank=True,
        help_text=
        "Enter the group name for practitioners of this service (e.g. Our Cardiologists)."
    )
    description_short = models.CharField(
        max_length=200,
        blank=True,
        help_text=
        "A short description for this service (e.g. Heart and Blood Vessel Disorders)."
    )
    phone = models.CharField(max_length=19,
                             blank=True,
                             help_text="Enter phone number.")
    #location = models.ForeignKey(site.Location, blank=True, null=True, help_text="Select a location for this service.")
    related_services = models.ManyToManyField(
        'Service',
        blank=True,
        null=True,
        symmetrical=False,
        help_text="Select optional related services to display in the nav.")
    content = models.TextField(blank=True)
    offerings = models.TextField(blank=True)
    learn_more = models.TextField(blank=True)
    patient_tools = models.TextField(blank=True)
    #location = models.TextField(blank=True)
    #original_image = models.ImageField(blank=True, null=True, width_field='', height_field='', upload_to='db/service-images', help_text="Upload an image for this service. This image will automatically be scaled to no greater than %sx%s for display on the site." % (IMAGE_MAX_WIDTH, IMAGE_MAX_HEIGHT))
    #image = models.ImageField(blank=True, null=True, width_field='', height_field='', upload_to='db/service-images')
    date_added = models.DateField(auto_now_add=True)
    blog = models.ForeignKey(Blog, blank=True, null=True)
    marketing_banner = models.ForeignKey(
        MarketingBanner,
        related_name="services_marketing_banner",
        blank=True,
        null=True,
        help_text=
        "Enter an additional marketing banner to be associated with this page."
    )
    large_image = models.ImageField(
        blank=True,
        upload_to='db/images/service',
        help_text="Add a large image for this service.")
    small_image = models.ImageField(
        blank=True,
        upload_to='db/images/service',
        help_text="Add a small image for this service.")

    class Meta:
        ordering = ['name']

    def __unicode__(self):
        return self.name

    def save(self, preview=True):
        super(Service, self).save(preview)
        cache.delete('finder-services-list')
        cache.delete('finder-specialty')

    def get_nav_links(self):
        if hasattr(self, "qa") and self.qa:
            links = self.link_nav_set.select_related().order_by(
                'services_link_nav.position')
        else:
            links = self.link_nav_set.model.objects.filter(
                service=self).select_related().order_by(
                    'services_link_nav.position')
        return [x.resource for x in links]

    def get_body_links(self):
        if hasattr(self, "qa") and self.qa:
            links = self.link_body_set.select_related().order_by(
                'services_link_body.position')
        else:
            links = self.link_body_set.model.objects.filter(
                service=self).select_related().order_by(
                    'services_link_body.position')
        return [x.resource for x in links]

    """
	The distinction between local and remote nav links has been removed from the presentation layer.
	def get_local_nav_links(self):
		if hasattr(self, "qa") and self.qa:
			links = self.link_nav_set.select_related().filter(resource__remote=False).order_by('services_link_nav.position')
		else:
			links = self.link_nav_set.model.objects.filter(service=self).select_related().filter(resource__remote=False).order_by('services_link_nav.position')
		return [x.resource for x in links]
		
	def get_remote_nav_links(self):
		if hasattr(self, "qa") and self.qa:
			links = self.link_nav_set.select_related().filter(resource__remote=True).order_by('services_link_nav.position')
		else:
			links = self.link_nav_set.model.objects.filter(service=self).select_related().filter(resource__remote=True).order_by('services_link_nav.position')
		return [x.resource for x in links]
	"""

    def get_absolute_url(self):
        return "/%s/%s/" % (self.item_url, self.urlname)

    def blog_list(self):
        return self.blog.blogentry_set.all()[:5]

    def cms_template_id_display(self, template_id):
        try:
            name = Template.objects.get(pk=template_id).name
        except Template.DoesNotExist:
            name = 'None'
        return name

    def letter_key(self):
        return self.name[0]

    def pkstr(self):
        return u'%s' % self.pk

    def location_plural(self):
        return len(self.location_set.filter(active='1', for_update__lte=1)) > 1

    def locations(self):
        return self.location_set.filter(active='1',
                                        for_update__lte=1).order_by('position')

    def search_index(self):
        # Return a (key, url, order, display, name, body) tuple with text for indexing
        body = "%s %s %s %s" % (self.name, self.practitioner_name,
                                self.practitioner_group, self.content)
        return SearchKey(self.pk, self.get_absolute_url(), self.name,
                         self.name, self.name, body)

    def keyword_index(self):
        # Return a (key, url, order, display, name, body) tuple with text for keyword indexing
        return SearchKey(self.pk, self.get_absolute_url(), self.name,
                         self.name, self.keywords, self.keywords)

    @property
    def display_large_image(self):
        if self.large_image:
            return self.large_image
        else:
            return site.MissingImage(
                name='db/image-library/service_default.jpg')

    @property
    def display_small_image(self):
        if self.small_image:
            return self.small_image
        else:
            return site.MissingImage(
                name='db/image-library/service_default.jpg')
示例#22
0
class Recipe(cms.Model, search.Model, models.Model):

    qa_objects = cms.QAManager()
    objects = Manager()
    all_objects = models.Manager()
    item_url = 'recipe'
    search_order = 7
    search_limit = 10

    TYPES = (
        ('B', 'Breakfast'),
        ('L', 'Lunch'),
        ('D', 'Dinner'),
        ('S', 'Snack'),
        ('E', 'Entertaining'),
        ('B', 'Beverage'),
        ('K', 'Kids'),
    )

    FEATURED = (
        (u'1', 'Featured'),
        (u'0', 'Not Featured'),
    )

    content_default = '<br/>[Type story here]<br/><br/><br/><b>More Information</b><br/><br/>For more information on [enter topic] visit [enter link text and create link].'

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(
        max_length=1,
        default=u'1',
        choices=cms.Model.ACTIVE,
        help_text=
        "Select Inactive to remove this feature from display and search on the site."
    )
    urlname = models.CharField(
        max_length=50,
        unique=True,
        help_text=
        "Enter folder for URL (e.g. enter 'Health-At-SMG' to have this Event load at '/feature/Health-At-SMG/'). This is normally created for you from the title."
    )
    aliases = models.ManyToManyField(URLAlias,
                                     blank=True,
                                     null=True,
                                     help_text="URL Aliases")
    keywords = models.CharField(
        max_length=500,
        blank=True,
        help_text="Enter optional Top Match keywords separated by spaces.")
    meta_description = models.TextField(
        blank=True, help_text="Enter an optional meta description for SEO.")
    posting_time = models.DateTimeField(
        help_text=
        "Set the posting time to when this feature will appear live on the site. This date and time will also be used for sort order in lists. This should not be changed after the feature is created."
    )
    display_time = models.DateTimeField(
        help_text=
        "The display time is used for the feature display, and can be changed to reflect updates."
    )
    title = models.CharField(max_length=200,
                             help_text="Enter the title of this feature.")
    byline = models.CharField(
        max_length=100,
        blank=True,
        help_text="Optionally enter a byline for this feature.")
    byline_link = models.CharField(
        max_length=100,
        blank=True,
        help_text=
        "Optionally enter a byline link for this article. This can be relative, like '/services/' or fully qualified, like 'http://www.sumitmedicalgroup.com'. Be sure to test."
    )
    recipe_type = models.CharField(max_length=1,
                                   blank=False,
                                   null=False,
                                   choices=TYPES)
    featured = models.CharField(
        max_length=1,
        default=u'0',
        choices=FEATURED,
        help_text=
        "Select Featured to chose this as the featured recipe. Only one recipe can be featured at a time."
    )
    original_image = models.ImageField(
        blank=True,
        null=True,
        width_field='',
        height_field='',
        upload_to='db/recipe-images',
        help_text=
        "Upload an image for this recipe. This image will automatically be scaled."
    )
    image = models.ImageField(blank=True,
                              null=True,
                              width_field='',
                              height_field='',
                              upload_to='db/recipe-images')
    description = models.TextField(
        default='Description',
        blank=True,
        help_text="Enter the description of this recipe.")
    ingredients = models.TextField(
        default='Ingredients',
        help_text="Enter the ingredients for this recipe, one per line.")
    directions = models.TextField(
        default='Directions',
        help_text="Enter the directions for this recipe, one step per line.")
    notes = models.TextField(
        default='Notes',
        blank=True,
        help_text="Enter any additional notes for this recipe.")
    reviewed_by = models.CharField(
        max_length=100,
        blank=True,
        help_text="Optionally enter a reviewed by notation.")
    reviewed_by_link = models.CharField(
        max_length=200,
        blank=True,
        help_text="Optionally enter a a link for the reviewed by notation")

    serving_size = models.CharField(max_length=10,
                                    blank=True,
                                    help_text="Serving size")
    num_servings = models.CharField(max_length=5,
                                    blank=True,
                                    help_text="Number of servings")
    calories = models.CharField(max_length=5, blank=True, help_text="Calories")
    fat_cals = models.CharField(max_length=5,
                                blank=True,
                                help_text="Calories from fat")
    total_fat = models.CharField(max_length=5,
                                 blank=True,
                                 help_text="Grams Total fat")
    saturated_fat = models.CharField(max_length=5,
                                     blank=True,
                                     help_text="Grams Saturated fat")
    trans_fat = models.CharField(max_length=5,
                                 blank=True,
                                 help_text="Grams Trans fat")
    cholesterol = models.CharField(max_length=5,
                                   blank=True,
                                   help_text="mg Cholesterol")
    sodium = models.CharField(max_length=5, blank=True, help_text="mg Sodium")
    total_carbs = models.CharField(max_length=5,
                                   blank=True,
                                   help_text="Grams Total Carbohydrates")
    dietary_fiber = models.CharField(max_length=5,
                                     blank=True,
                                     help_text="Grams Dietary Fiber")
    sugars = models.CharField(max_length=5,
                              blank=True,
                              help_text="Grams Sugars")
    protein = models.CharField(max_length=5,
                               blank=True,
                               help_text="Grams Protein")
    vit_a = models.CharField(max_length=5, blank=True, help_text="% Vitamin A")
    vit_c = models.CharField(max_length=5, blank=True, help_text="% Vitamin C")
    calcium = models.CharField(max_length=5, blank=True, help_text="% Calcium")
    iron = models.CharField(max_length=5, blank=True, help_text="% Iron")

    class Meta:
        ordering = ['-posting_time']
        verbose_name = "SMG Recipe"
        verbose_name_plural = "SMG Recipes"

    def __unicode__(self):
        return u'%s' % (self.title)

    def get_absolute_url(self):
        return "/%s/%s/" % (self.item_url, self.urlname)

    def display_time_for_display(self):
        return u'%s' % self.display_time.strftime('%m-%d-%Y')

    def relative_age(self):
        return common_relative_age(self)

    def ingredient_list(self):
        return self.ingredients.split('\n')

    def direction_list(self):
        return self.directions.split('\n')

    def pct_total_fat(self):
        if not self.total_fat:
            return None
        return '%d%%' % (float(self.total_fat) / 65 * 100)

    def pct_saturated_fat(self):
        if not self.saturated_fat:
            return None
        return '%d%%' % (float(self.saturated_fat) / 20 * 100)

    def pct_cholesterol(self):
        if not self.cholesterol:
            return None
        return '%d%%' % (float(self.cholesterol) / 300 * 100)

    def pct_sodium(self):
        if not self.sodium:
            return None
        return '%d%%' % (float(self.sodium) / 2300 * 100)

    def pct_total_carbs(self):
        if not self.total_carbs:
            return None
        return '%d%%' % (float(self.total_carbs) / 300 * 100)

    def pct_dietary_fiber(self):
        if not self.dietary_fiber:
            return None
        return '%d%%' % (float(self.dietary_fiber) / 25 * 100)

    def pct_protein(self):
        if not self.protein:
            return None
        return '%d%%' % (float(self.protein) / 50 * 100)

    def save(self, preview=True):
        if self.original_image:
            image_make_thumbnail(self, 'original_image', 'image',
                                 'db/recipe-images', IMAGE_MAX_WIDTH,
                                 IMAGE_MAX_HEIGHT)
        super(Recipe, self).save(preview)

    def search_index(self):
        # Return a (key, url, order, display, name, body) tuple with text for indexing
        if self.posting_time.__class__ == unicode:
            posting_time = datetime(
                *time.strptime(self.posting_time, "%Y-%m-%d %H:%M:%S")[0:5])
        else:
            posting_time = self.posting_time
        body = "%s %s %s" % (self.title, self.description, self.ingredients)
        return SearchKey(self.pk, self.get_absolute_url(),
                         posting_time.isoformat(), self.title, self.title,
                         body)
示例#23
0
class ServiceGroup(cms.Model, models.Model):
    """
	Model for Service groups
	"""
    qa_objects = cms.QAManager()
    objects = cms.Manager()
    all_objects = models.Manager()

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)

    active = models.CharField(
        max_length=1,
        default=u'1',
        choices=cms.Model.ACTIVE,
        help_text=
        "Select Inactive to remove this service from display and search on the site."
    )
    name = models.CharField(max_length=100)
    description = models.TextField()
    meta_description = models.TextField(
        blank=True, help_text="Enter an optional meta description for SEO.")
    seo_keywords = models.TextField(
        blank=True,
        help_text=
        "Enter optional keywords for SEO. These are not used for site search.")
    urlname = models.CharField(
        max_length=50,
        unique=True,
        help_text="Enter identifier for URL (e.g. enter 'family_health').")
    large_image = models.ImageField(
        upload_to='db/images/service_group',
        help_text="Add a large image for this group.")
    small_image = models.ImageField(
        upload_to='db/images/service_group',
        help_text="Add a small image for this group.")
    marketing_banner = models.ForeignKey(
        MarketingBanner,
        related_name="service_group_marketing_banner",
        blank=True,
        null=True,
        help_text=
        "Enter an additional marketing banner to be associated with this page."
    )
    order = models.PositiveIntegerField(default=0)
    services = models.ManyToManyField(Service, through='ServiceGroupDetail')

    def __str__(self):
        return self.name

    class Meta:
        ordering = ['order']

    def get_absolute_url(self):
        return '/service/group/%s/' % self.urlname
        # reverse is too fragile here because we are not using a slugfield with validation
        #return reverse('service-group', kwargs={'urlname':self.urlname})

    def list_services(self):
        services = ServiceGroupDetail.objects.filter(servicegroup=self)
        s = [
            '<a href="%s">%s</a>' %
            (s.service.get_absolute_url(), s.service.name) for s in services
        ]
        return ', '.join(s)
示例#24
0
class PDF(cms.Model, models.Model):

    qa_objects = cms.QAManager()
    objects = Manager()
    all_objects = models.Manager()
    item_url = 'pdf'
    search_order = 6
    search_limit = 10

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(
        max_length=1,
        default=u'1',
        choices=cms.Model.ACTIVE,
        help_text=
        "Select Inactive to remove this pdf from display and search on the site."
    )
    keywords = models.CharField(
        max_length=500,
        blank=True,
        help_text="Enter optional Top Match keywords separated by spaces.")
    posting_time = models.DateTimeField(
        help_text=
        "Set the posting time to when this pdf will appear live on the site. This date and time will also be used for sort order in lists. This should not be changed after the pdf is created."
    )
    display_time = models.DateTimeField(
        help_text=
        "The display time is used for the pdf display, and can be changed to reflect updates."
    )
    title = models.CharField(max_length=200,
                             help_text="Enter the title of this pdf.")
    description = models.TextField(
        blank=True, help_text="Enter an optional description for this PDF.")
    pdf = models.FileField(blank=True,
                           null=True,
                           upload_to='db/pdf-files',
                           help_text="Upload the PDF.")
    thumbnail = models.ImageField(
        blank=True,
        null=True,
        width_field='',
        height_field='',
        upload_to='db/pdf-files',
        help_text="Upload an image thumbnail for this recipe.")

    class Meta:
        ordering = ['-posting_time']
        verbose_name = "SMG PDF"
        verbose_name_plural = "SMG PDFs"

    def __unicode__(self):
        return u'%s' % (self.title)

    def display_time_for_display(self):
        return u'%s' % self.display_time.strftime('%m-%d-%Y')

    def relative_age(self):
        return common_relative_age(self)

    @staticmethod
    def is_live(key):
        try:
            posting_time = Feature.all_objects.get(id=key).posting_time
            return posting_time <= datetime.now()
        except:
            return False

    def is_archive(self):
        return self.posting_time < datetime.today() - timedelta(
            days=ARCHIVE_AGE)
示例#25
0
class Article(cms.Model, search.Model, models.Model):

    qa_objects = cms.QAManager()
    objects = Manager()
    all_objects = models.Manager()
    item_url = 'article'
    search_order = 8
    search_limit = 10

    PROMO = (
        (0, 'Off'),
        (1, 'Position 1'),
        (2, 'Position 2'),
        (3, 'Position 3'),
        (4, 'Position 4'),
        (5, 'Position 5'),
        (6, 'Position 6'),
    )

    content_default = '<br/>[Type story here]<br/><br/><br/><b>More Information</b><br/><br/>For more information on [enter topic] visit [enter link text and create link].'

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(
        max_length=1,
        default=u'1',
        choices=cms.Model.ACTIVE,
        help_text=
        "Select Inactive to remove this article from display and search on the site."
    )
    urlname = models.CharField(
        max_length=50,
        unique=True,
        help_text=
        "Enter folder for URL (e.g. enter 'Health-At-SMG' to have this Event load at '/article/Health-At-SMG/'). This is normally created for you from the headline."
    )
    aliases = models.ManyToManyField(URLAlias,
                                     blank=True,
                                     null=True,
                                     help_text="URL Aliases")
    keywords = models.CharField(
        max_length=500,
        blank=True,
        help_text="Enter optional Top Match keywords separated by spaces.")
    meta_description = models.TextField(
        blank=True, help_text="Enter an optional meta description for SEO.")
    posting_time = models.DateTimeField(
        help_text=
        "Set the posting time to when this article will appear live on the site. This date and time will also be used for sort order in lists. This should not be changed after the article is created."
    )
    display_time = models.DateTimeField(
        help_text=
        "The display time is used for the article display, and can be changed to reflect updates."
    )
    headline = models.CharField(
        max_length=200, help_text="Enter the headline of this article.")
    byline = models.CharField(
        max_length=100,
        blank=True,
        help_text="Optionally enter a byline for this article.")
    byline_link = models.CharField(
        max_length=100,
        blank=True,
        help_text=
        "Optionally enter a byline link for this article. This can be relative, like '/services/' or fully qualified, like 'http://www.sumitmedicalgroup.com'. Be sure to test."
    )
    content = models.TextField(
        default=content_default,
        help_text=
        "Enter the article body and more information line above. To create the link, 1) replace the placeholder with the display text for the link, e.g. American Academy of Pediacrics; 2) select the display text so that it is highlighted; 3) choose the link button from the toolbar to insert the link."
    )
    original_image = models.ImageField(
        blank=True,
        null=True,
        width_field='',
        height_field='',
        upload_to='db/article-images',
        help_text=
        "Upload an image for this article. For homepage leaders, this image will be used as the preview and next/previous button image. This image will automatically be scaled."
    )
    image = models.ImageField(blank=True,
                              null=True,
                              width_field='',
                              height_field='',
                              upload_to='db/article-images')
    service = models.ForeignKey(
        Service,
        blank=True,
        null=True,
        help_text=
        "Enter service page for this artice (e.g. select Cardiolgy to have this article only display on the Cardiology service page). Do not select a service if this article should appear on the home page."
    )
    leader_promo = models.PositiveSmallIntegerField(
        default=0,
        choices=PROMO,
        help_text=
        "Select Off for normal articles, or select the position for rotation of this article on the homepage leader."
    )
    headline_promo = models.PositiveSmallIntegerField(
        default=0,
        choices=PROMO,
        help_text=
        "Select Off for normal articles, or select the position for this headline under \"Our News\" on the home page."
    )
    reviewed_by = models.CharField(
        max_length=100,
        blank=True,
        help_text="Optionally enter a reviewed by notation.")
    reviewed_by_link = models.CharField(
        max_length=200,
        blank=True,
        help_text="Optionally enter a a link for the reviewed by notation")
    marketing_banner = models.ForeignKey(
        MarketingBanner,
        related_name="articles_marketing_banner",
        blank=True,
        null=True,
        help_text=
        "Enter an additional marketing banner to be associated with this page."
    )
    blurb = models.TextField(
        blank=True,
        help_text=
        'Blurb text should be a short summary of the article, it will display on preview lists'
    )

    class Meta:
        ordering = ['-posting_time']
        verbose_name = "SMG Article"
        verbose_name_plural = "SMG Articles"

    def __unicode__(self):
        return u'%s' % (self.headline)

    def get_absolute_url(self):
        return "/%s/%s/" % (self.item_url, self.urlname)

    def display_time_for_display(self):
        return u'%s' % self.display_time.strftime('%m-%d-%Y')

    def relative_age(self):
        return common_relative_age(self)

    @staticmethod
    def is_live(key):
        try:
            posting_time = Article.all_objects.get(id=key).posting_time
            return posting_time <= datetime.now()
        except:
            return False

    def is_archive(self):
        return self.posting_time < datetime.today() - timedelta(
            days=ARCHIVE_AGE)

    def clearcache(self):
        for i in range(len(self.PROMO)):
            path = reverse('smgsite.articles.views.leader',
                           kwargs={'position': i + 1})
            key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
            args = hashlib.md5(path)
            path = args.hexdigest()
            header_key = 'views.decorators.cache.cache_header.%s.%s' % (
                key_prefix, path)
            headers = cache.get(header_key)
            ctx = hashlib.md5()
            if headers:
                for header in headers:
                    ctx.update(header)

            cache.delete(header_key)

            page_key = 'views.decorators.cache.cache_page.%s.%s.%s' % (
                key_prefix, path, ctx.hexdigest())
            cache.delete(page_key)

    def save(self, preview=True, post=True):
        super(Article, self).save(preview=preview, post=post)
        self.clearcache()

    def delete(self, preview=True):
        from django import forms
        if self.leader_promo == 0:
            leaders = Article.objects.filter(leader_promo__gt=0)
            if len(leaders) <= 1:
                raise forms.ValidationError(
                    'This is the last Homepage Leader news story. It cannot be deleted or reset as a non-leader story until there is another Leader news story. There must always be at least one Leader for the Homepage.'
                )
        super(Article, self).delete(preview)
        self.clearcache()

    def search_index(self):
        # Return a (key, url, order, display, name, body) tuple with text for indexing
        if self.posting_time.__class__ == unicode:
            posting_time = datetime(
                *time.strptime(self.posting_time, "%Y-%m-%d %H:%M:%S")[0:5])
        else:
            posting_time = self.posting_time
        body = "%s %s" % (self.headline, self.content)
        return SearchKey(self.pk, self.get_absolute_url(),
                         posting_time.isoformat(), self.headline,
                         self.headline, body)

    def display_image(self):
        if self.original_image:
            return self.original_image
        else:
            return None

    @property
    def image(self):
        if self.original_image:
            return self.original_image
        else:
            return None
示例#26
0
class MediaResult(cms.Model, search.Model, models.Model):

    qa_objects = cms.QAManager()
    objects = cms.Manager()
    all_objects = models.Manager()
    item_url = 'recentcoverage'
    search_order = 8
    search_limit = 10

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(
        max_length=1,
        default=u'1',
        choices=cms.Model.ACTIVE,
        help_text=
        "Select Inactive to remove this media result from display and search on the site."
    )
    urlname = models.CharField(
        max_length=50,
        unique=True,
        help_text=
        "Enter folder for URL (e.g. enter 'Health-At-SMG' to have this media result load at '/recentcoverage/Health-At-SMG/'). This is normally created for you from the headline."
    )
    aliases = models.ManyToManyField(URLAlias,
                                     blank=True,
                                     null=True,
                                     help_text="URL Aliases")
    keywords = models.CharField(
        max_length=500,
        blank=True,
        help_text="Enter optional Top Match keywords separated by spaces.")
    meta_description = models.TextField(
        blank=True, help_text="Enter an optional meta description for SEO.")
    posting_time = models.DateTimeField(
        help_text=
        "Set the posting time to when this feature will appear live on the site. This date and time will also be used for sort order in lists. This should not be changed after the feature is created."
    )
    display_time = models.DateTimeField(
        help_text=
        "The display time is used for the feature display, and can be changed to reflect updates."
    )
    headline = models.CharField(
        max_length=200, help_text="Enter the headline of this feature.")
    byline = models.CharField(
        max_length=100,
        blank=True,
        help_text="Optionally enter a byline for this Media Result.")
    byline_link = models.CharField(
        max_length=100,
        blank=True,
        help_text=
        "Optionally enter a byline link for this Media Result. This can be relative, like '/services/' or fully qualified, like 'http://www.sumitmedicalgroup.com'. Be sure to test."
    )
    image = models.ImageField(
        blank=True,
        null=True,
        width_field='',
        height_field='',
        upload_to='db/mediaresult-images',
        help_text="Upload an image for this media result.")
    content = models.TextField(help_text="Enter the media result body above.")
    marketing_banner = models.ForeignKey(
        MarketingBanner,
        related_name="mediaresult_marketing_banner",
        blank=True,
        null=True,
        help_text=
        "Enter an additional marketing banner to be associated with this page."
    )
    sort_order = models.PositiveSmallIntegerField(
        default=None,
        null=True,
        help_text=
        "Select the sort order position for this trending topic. Set to 0 to remove from ordering."
    )
    blurb = models.TextField(
        blank=True,
        help_text=
        'Blurb text should be a short summary of the article, it will display on preview lists'
    )

    class Meta:
        ordering = ['-posting_time']
        verbose_name = "SMG Media Result"
        verbose_name_plural = "SMG Media Results"

    def __unicode__(self):
        return u'%s' % (self.headline)

    def get_absolute_url(self):
        return "/%s/%s/" % (self.item_url, self.urlname)

    def display_time_for_display(self):
        return u'%s' % self.display_time.strftime('%m-%d-%Y')

    def relative_age(self):
        return common_relative_age(self)

    @staticmethod
    def is_live(key):
        try:
            posting_time = Feature.all_objects.get(id=key).posting_time
            return posting_time <= datetime.now()
        except:
            return False

    def is_archive(self):
        return self.posting_time < datetime.today() - timedelta(
            days=ARCHIVE_AGE)

    def search_index(self):
        # Return a (key, url, order, display, name, body) tuple with text for indexing
        if self.posting_time.__class__ == unicode:
            posting_time = datetime(
                *time.strptime(self.posting_time, "%Y-%m-%d %H:%M:%S")[0:5])
        else:
            posting_time = self.posting_time
        body = "%s %s" % (self.headline, self.content)
        return SearchKey(self.pk, self.get_absolute_url(),
                         posting_time.isoformat(), self.headline,
                         self.headline, body)

    def keyword_index(self):
        # Return a (key, url, order, display, name, body) tuple with text for indexing
        if self.posting_time.__class__ == unicode:
            posting_time = datetime(
                *time.strptime(self.posting_time, "%Y-%m-%d %H:%M:%S")[0:5])
        else:
            posting_time = self.posting_time
        return SearchKey(self.pk, self.get_absolute_url(),
                         posting_time.isoformat(), self.headline,
                         self.keywords, self.keywords)

    def save(self, preview=True, post=True):
        if self.sort_order == 0:
            self.sort_order = None
        super(MediaResult, self).save(preview=preview, post=post)
示例#27
0
class Class(cms.Model, search.Model, models.Model, cms.ClonableMixin):
    """
	Model for Classes

	This is a model for the classes entered and displayed on the website.
	"""

    qa_objects = cms.QAManager()
    objects = ClassManager()
    all_objects = models.Manager()
    display_objects = EventDisplayManager()
    item_url = 'class'
    search_order = 4
    search_limit = 10

    ONDAY = (
        (u'1', 'Held this day'),
        (u'0', 'Not held'),
    )

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(
        max_length=1,
        default=u'1',
        choices=cms.Model.ACTIVE,
        help_text=
        "Select Inactive to remove this class from display and search on the site."
    )
    keywords = models.CharField(
        max_length=500,
        blank=True,
        help_text="Enter optional Top Match keywords separated by spaces.")
    urlname = models.CharField(
        max_length=50,
        unique=True,
        help_text=
        "Enter folder for URL (e.g. enter 'Aerobics-Class' to have this Class load at '/class/Aerobics-Class/'). This is normally created for you from the title."
    )
    startdate = models.DateField(
        help_text="Enter a requied date for when this class starts.")
    starttime = models.TimeField(
        blank=True,
        null=True,
        help_text="Enter an optional 24-hour time for when this class starts.")
    enddate = models.DateField(
        blank=True,
        null=True,
        help_text="Enter a date for when this event ends.")
    endtime = models.TimeField(
        blank=True,
        null=True,
        help_text="Enter an optional 24-hour time for when this class ends.")
    cancellations = models.TextField(
        blank=True,
        help_text=
        "Enter cancellation dates or other urgent information about this class."
    )
    days = models.CharField(
        max_length=7, help_text="Select the days when the class takes place.")
    monday = models.CharField(max_length=1, default=u'0', choices=ONDAY)
    tuesday = models.CharField(max_length=1, default=u'0', choices=ONDAY)
    wednesday = models.CharField(max_length=1, default=u'0', choices=ONDAY)
    thursday = models.CharField(max_length=1, default=u'0', choices=ONDAY)
    friday = models.CharField(max_length=1, default=u'0', choices=ONDAY)
    saturday = models.CharField(max_length=1, default=u'0', choices=ONDAY)
    sunday = models.CharField(max_length=1, default=u'0', choices=ONDAY)
    title = models.CharField(
        max_length=200,
        help_text="Enter the title for this class (e.g. Aerobics Class).")
    short_description = models.CharField(
        max_length=300, help_text="Enter a short description for this class.")
    description = models.TextField(
        help_text="Enter a description for this class.")
    meta_description = models.TextField(
        blank=True, help_text="Enter an optional meta description for SEO.")
    service = models.ForeignKey(
        Service,
        blank=True,
        null=True,
        help_text=
        "Select the Specialty or Service associated with this class, if any.")
    related_services = models.ManyToManyField(
        Service,
        blank=True,
        null=True,
        related_name='class_s_related',
        help_text="Select optional related services for this class.")
    local_presenters = models.ManyToManyField(
        Doctor,
        blank=True,
        help_text="Select the SMG professionals presenting this class, if any."
    )
    other_presenter = models.CharField(
        max_length=200,
        blank=True,
        help_text="Enter another presenter nome for this class.")
    presenter_url = models.URLField(
        max_length=500,
        blank=True,
        help_text=
        "Enter a URL reference for the other presenter above, if applicable.")
    sponsored_by = models.CharField(
        max_length=200,
        blank=True,
        help_text="Enter on optional sponsored-by line.")
    sponsor_url = models.URLField(
        max_length=500,
        blank=True,
        help_text="Enter a URL reference for the sponsor, if applicable.")
    location = models.ForeignKey(Location,
                                 blank=True,
                                 null=True,
                                 default=18,
                                 help_text="Select a location at SMG.")
    room = models.CharField(max_length=100,
                            blank=True,
                            default="Conference Center",
                            help_text="Enter a room at this location.")
    other_location = models.TextField(
        blank=True,
        help_text=
        "If this class is not at SMG, leave the above information blank and enter an address and parking information here."
    )
    original_image = models.ImageField(
        blank=True,
        null=True,
        width_field='',
        height_field='',
        upload_to='db/class-images',
        help_text=
        "Upload an image for this class. This image will automatically be scaled to no greater than %sx%s for display on the site."
        % (IMAGE_MAX_WIDTH, IMAGE_MAX_HEIGHT))
    image = models.ImageField(blank=True,
                              null=True,
                              width_field='',
                              height_field='',
                              upload_to='db/class-images')
    icon = models.ImageField(
        blank=True,
        null=True,
        width_field='',
        height_field='',
        upload_to='db/class-images',
        help_text=
        "Upload an icon for this class. This icon will be displayed next to the class on the homepage. This image will automatically be scaled to %sx%s for display on the site."
        % (ICON_MAX_WIDTH, ICON_MAX_HEIGHT))
    date_added = models.DateField(auto_now_add=True)

    class Meta:
        verbose_name = 'Class'
        verbose_name_plural = 'Classes'
        ordering = ['-startdate', '-starttime']

    def __unicode__(self):
        return self.title

    def get_absolute_url(self):
        return "/%s/%s/" % (self.item_url, self.urlname)

    def days_held(self):
        days = []
        if self.monday == '1': days.append('Mondays')
        if self.tuesday == '1': days.append('Tuesdays')
        if self.wednesday == '1': days.append('Wednesdays')
        if self.thursday == '1': days.append('Thursdays')
        if self.friday == '1': days.append('Fridays')
        if self.saturday == '1': days.append('Saturdays')
        if self.sunday == '1': days.append('Sundays')
        return days

    def starttime_display(self):
        return self.starttime.strftime('%I:%M %p')

    def timelong(self):
        if self.startdate == self.enddate:
            if not self.starttime and not self.endtime:
                val = u'%s' % (self.startdate.strftime('%A, %B %d, %Y'))
            elif not self.starttime:
                val = u'%s, - %s' % (self.startdate.strftime('%A, %B %d, %Y'),
                                     self.endtime.strftime('%I:%M %p'))
            else:
                val = u'%s, %s - %s' % (self.startdate.strftime(
                    '%A, %B %d, %Y'), self.starttime.strftime('%I:%M %p'),
                                        self.endtime.strftime('%I:%M %p'))
        elif not self.endtime or not self.enddate:
            val = u'%s, %s' % (self.startdate.strftime('%A, %B %d, %Y'),
                               self.starttime.strftime('%I:%M %p'))
        else:
            val = u'%s - %s' % (self.startdate.strftime('%A, %B %d, %Y'),
                                self.enddate.strftime('%A, %B %d, %Y'))
        return zero_re.sub(' \\1', val)

    def timeshort(self):
        if self.startdate == self.enddate:
            if not self.starttime:
                val = u'%s' % (self.startdate.strftime('%a., %b. %d'))
            else:
                val = u'%s, %s' % (self.startdate.strftime('%a., %b. %d'),
                                   self.starttime.strftime('%I:%M %p'))
        elif not self.endtime or not self.enddate:
            val = u'%s, %s' % (self.startdate.strftime('%a., %b. %d'),
                               self.starttime.strftime('%I:%M %p'))
        else:
            val = u'%s - %s' % (self.startdate.strftime('%a., %b. %d'),
                                self.enddate.strftime('%a., %b. %d'))
        return zero_re.sub(' \\1', val)

    def expired(self):
        if self.enddate < date.today():
            return True
        return False

    def presenter(self):
        presenter = False
        if self.local_presenters.count() > 0 or self.other_presenter:
            presenter = True
        return presenter

    def multiple_sponsers(self):
        multiple = False
        if self.local_presenters.count() > 1 or (
                self.local_presenters.count() == 1 and self.other_presenter):
            multiple = True
        return multiple

    def search_index(self):
        # Return a (key, url, order, display, name, body) tuple with text for indexing
        body = "%s %s %s %s" % (self.title, self.description,
                                self.local_presenters, self.other_presenter)
        return SearchKey(self.pk, self.get_absolute_url(), self.startdate,
                         self.title, self.title, body)

    def keyword_index(self):
        # Return a (key, url, order, display, name, body) tuple with text for keyword indexing
        return SearchKey(self.pk, self.get_absolute_url(), self.startdate,
                         self.title, self.keywords, self.keywords)
示例#28
0
class Event(cms.Model, search.Model, models.Model, cms.ClonableMixin):
    """
	Model for Events
	
	This is a model for the events entered and displayed on the website.
	"""

    qa_objects = cms.QAManager()
    objects = models.Manager()
    all_objects = models.Manager()
    display_objects = EventDisplayManager()
    item_url = 'event'
    search_order = 4
    search_limit = 10

    TYPES = (
        ('P', 'Program'),
        ('L', 'Lecture'),
        ('E', 'Exhibit'),
        ('S', 'Support Group'),
        ('W', 'Workshop'),
        ('F', 'Festival'),
    )

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(
        max_length=1,
        default=u'1',
        choices=cms.Model.ACTIVE,
        help_text=
        "Select Inactive to remove this event from display and search on the site. Registration reminders will not be sent for an inactive event. However, a cancellation message must be provided manually with the Notfication field below."
    )
    keywords = models.CharField(
        max_length=500,
        blank=True,
        help_text="Enter optional Top Match keywords separated by spaces.")
    urlname = models.CharField(
        max_length=50,
        unique=True,
        help_text=
        "Enter folder for URL (e.g. enter 'Diabetes-Lecture' to have this Event load at '/event/Diabetes-Lecture/'). This is normally created for you from the title."
    )
    #startdate = models.DateField(help_text="Enter a requied date for when this event starts.")
    #starttime = models.TimeField(blank=True, null=True, help_text="Enter an option 24-hour time for when this event starts.")
    #enddate = models.DateField(help_text="Enter a requied date for when this event ends.")
    #endtime = models.TimeField(blank=True, null=True, help_text="Enter an option 24-hour time for when this event ends.")
    event_type = models.CharField(max_length=1,
                                  blank=False,
                                  null=False,
                                  choices=TYPES)
    title = models.CharField(
        max_length=200,
        help_text="Enter the title for this event (e.g. Diabetes Lecture).")
    short_description = models.CharField(
        max_length=300, help_text="Enter a short description for this event.")
    description = models.TextField(
        help_text="Enter a description for this event.")
    meta_description = models.TextField(
        blank=True, help_text="Enter an optional meta description for SEO.")
    service = models.ForeignKey(
        Service,
        blank=True,
        null=True,
        help_text=
        "Select the Specialty or Service associated with this event, if any.")
    related_services = models.ManyToManyField(
        Service,
        blank=True,
        null=True,
        related_name='s_related',
        help_text="Select optional related services for this event.")
    local_presenters = models.ManyToManyField(
        Doctor,
        blank=True,
        help_text="Select the SMG professionals presenting this event, if any."
    )
    other_presenter = models.CharField(
        max_length=200,
        blank=True,
        help_text="Enter another presenter nome for this event.")
    presenter_url = models.URLField(
        max_length=500,
        blank=True,
        help_text=
        "Enter a URL reference for the other presenter above, if applicable.")
    sponsored_by = models.CharField(
        max_length=200,
        blank=True,
        help_text="Enter on optional sponsored-by line.")
    sponsor_url = models.URLField(
        max_length=500,
        blank=True,
        help_text="Enter a URL reference for the sponsor, if applicable.")
    location = models.ForeignKey(Location,
                                 blank=True,
                                 null=True,
                                 default=18,
                                 help_text="Select a location at SMG.")
    room = models.CharField(max_length=100,
                            blank=True,
                            default="Conference Center",
                            help_text="Enter a room at this location.")
    other_location = models.TextField(
        blank=True,
        help_text=
        "If this event is not at SMG, leave the above information blank and enter an address and parking information here."
    )
    original_image = models.ImageField(
        blank=True,
        null=True,
        width_field='',
        height_field='',
        upload_to='db/event-images',
        help_text=
        "Upload an image for this event. This image will automatically be scaled to no greater than %sx%s for display on the site."
        % (IMAGE_MAX_WIDTH, IMAGE_MAX_HEIGHT))
    image = models.ImageField(blank=True,
                              null=True,
                              width_field='',
                              height_field='',
                              upload_to='db/event-images')
    icon = models.ImageField(
        blank=True,
        null=True,
        width_field='',
        height_field='',
        upload_to='db/event-images',
        help_text=
        "Upload an icon for this event. This icon will be displayed next to the event on the homepage. This image will automatically be scaled to %sx%s for display on the site."
        % (ICON_MAX_WIDTH, ICON_MAX_HEIGHT))
    date_added = models.DateField(auto_now_add=True)
    exclude_from_registration = models.CharField(
        max_length=1,
        default=u'0',
        choices=cms.Model.EXCLUDE,
        help_text="Select Exclude to exclude this event from registration.")
    notification = models.TextField(
        blank=True,
        help_text=
        "Enter a notification to be emailed to all registered users of this event. Emails are sent whenever changes to this field are confirmed in the CMS."
    )

    class Meta:
        ordering = ['title']

    def __unicode__(self):
        return self.title

    def save(self, preview=True):
        if not preview and whitespace_re.match(
                self.notification
        ) and self.notification != Event.all_objects.get(
                id=self.id).notification:
            self.notify()
        super(Event, self).save(preview)

    def notify(self):
        import smtplib
        import os, sys
        accounts = Registration.objects.filter(eventtimes__event=self)
        for account in accounts:
            toaddrs = (account.email, )
            fromaddr = '*****@*****.**'
            msg = 'From: \'Summit Medical Group Event Hotline\' <*****@*****.**>\r\n'
            msg = 'Reply-To: \'Summit Medical Group Event Hotline\' <*****@*****.**>\r\n'
            msg += 'To: %s\r\n' % account.email
            msg += 'Subject: Important Update re: your Summit Medical Group event registration\r\n\r\n'
            msg += 'Dear %s %s: \r\n\r\n' % (account.first_name,
                                             account.last_name)
            msg += self.notification
            msg += '\r\n\r\nThank you,\r\n'
            msg += 'Summit Medical Group\r\n\r\n'

            try:
                server = smtplib.SMTP('localhost')
                server.set_debuglevel(1)
                server.sendmail(fromaddr, toaddrs, msg)
                server.quit()
                account.status = 'C'
                account.save()
            except:
                print 'Unable to send messages to %s because %s' % (
                    toaddrs, sys.exc_info()[0])

    def get_absolute_url(self):
        return "/%s/%s/" % (self.item_url, self.urlname)

    def expired(self):
        if self.enddate < date.today():
            return True
        return False

    def presenter(self):
        presenter = False
        if self.local_presenters.count() > 0 or self.other_presenter:
            presenter = True
        return presenter

    def multiple_sponsers(self):
        multiple = False
        if self.local_presenters.count() > 1 or (
                self.local_presenters.count() == 1 and self.other_presenter):
            multiple = True
        return multiple

    def firstdate(self):
        eventtimes = self.eventtime_set.order_by('startdate', 'starttime')
        if eventtimes:
            return eventtimes[0].startdate
        return None

    def registered(self):
        count = 0
        for eventtime in self.eventtime_set.all():
            count += len(eventtime.registration_set.all())
        return count

    def eventtimes(self):
        eventtimes = Eventtime.objects.filter(
            event=self,
            startdate__gte=date.today()).order_by('startdate', 'starttime')
        finallist = []
        for eventtime in eventtimes:
            if eventtime.event.active == u'1' and eventtime.event.for_update <= 1:
                finallist.append(eventtime)
        return finallist

    def most_recent(self):
        eventtimes = Eventtime.objects.filter(
            event=self,
            startdate__gte=date.today()).order_by('startdate', 'starttime')
        if eventtimes:
            return eventtimes[0]
            return eventtimes[0].event.timelong()
        return "None or before today"

    def search_index(self):
        # Return a (key, url, order, display, name, body) tuple with text for indexing
        body = "%s %s %s %s" % (self.title, self.description,
                                self.local_presenters, self.other_presenter)
        return SearchKey(self.pk, self.get_absolute_url(), self.firstdate(),
                         self.title, self.title, body)

    def keyword_index(self):
        # Return a (key, url, order, display, name, body) tuple with text for keyword indexing
        return SearchKey(self.pk, self.get_absolute_url(), self.firstdate(),
                         self.title, self.keywords, self.keywords)
示例#29
0
class Eventtime(cms.Model, models.Model):
    """
	Model for Event times
	"""

    qa_objects = cms.QAManager()
    objects = cms.Manager()
    all_objects = models.Manager()

    CANCELLED = (('A', 'Active'), ('C', 'Cancelled'))

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(
        max_length=1,
        default=u'1',
        choices=cms.Model.ACTIVE,
        help_text=
        "Select Inactive to remove this item from display and search on the site."
    )
    event = models.ForeignKey(Event)
    startdate = models.DateField(
        help_text="Enter a requied date for when this event starts.")
    starttime = models.TimeField(
        blank=True,
        null=True,
        help_text="Enter an option 24-hour time for when this event starts.")
    enddate = models.DateField(
        help_text="Enter a requied date for when this event ends.")
    endtime = models.TimeField(
        blank=True,
        null=True,
        help_text="Enter an option 24-hour time for when this event ends.")
    cancelled = models.CharField(max_length=1,
                                 choices=CANCELLED,
                                 default='A',
                                 help_text="Cancel this event?")

    def __unicode__(self):
        return u"%s: %s -- %s to %s -- %s" % (self.event.title, self.startdate,
                                              self.starttime, self.enddate,
                                              self.endtime)

    def timelong(self):
        if self.startdate == self.enddate:
            if not self.starttime and not self.endtime:
                val = u'%s' % (self.startdate.strftime('%A, %B %d, %Y'))
            elif not self.starttime:
                val = u'%s, - %s' % (self.startdate.strftime('%A, %B %d, %Y'),
                                     self.endtime.strftime('%I:%M %p'))
            elif not self.endtime:
                val = u'%s, %s' % (self.startdate.strftime('%A, %B %d, %Y'),
                                   self.starttime.strftime('%I:%M %p'))
            else:
                val = u'%s, %s - %s' % (self.startdate.strftime(
                    '%A, %B %d, %Y'), self.starttime.strftime('%I:%M %p'),
                                        self.endtime.strftime('%I:%M %p'))
        else:
            val = u'%s - %s' % (self.startdate.strftime('%A, %B %d, %Y'),
                                self.enddate.strftime('%A, %B %d, %Y'))
        return zero_re.sub(' \\1', val)

    def timeshort(self):
        if self.startdate == self.enddate:
            if not self.starttime:
                val = u'%s' % (self.startdate.strftime('%a., %b. %d'))
            else:
                val = u'%s, %s' % (self.startdate.strftime('%a., %b. %d'),
                                   self.starttime.strftime('%I:%M %p'))
        else:
            val = u'%s - %s' % (self.startdate.strftime('%a., %b. %d'),
                                self.enddate.strftime('%a., %b. %d'))
        return zero_re.sub(' \\1', val)

    def expired(self):
        if self.enddate < date.today():
            return True
        return False
示例#30
0
class Location(cms.Model, search.Model, models.Model):
    """
	Model for SMG Locationes

	"""

    SHOW = 1
    HIDE = 0
    DISPLAY = (
        (u'1', 'Show in Lists'),
        (u'0', 'Hide from Lists'),
    )

    STATE_CHOICES = (
        ('AL', 'Alabama'),
        ('AK', 'Alaska'),
        ('AS', 'American Samoa'),
        ('AZ', 'Arizona'),
        ('AR', 'Arkansas'),
        ('CA', 'California'),
        ('CO', 'Colorado'),
        ('CT', 'Connecticut'),
        ('DE', 'Delaware'),
        ('DC', 'District of Columbia'),
        ('FM', 'Federated States of Micronesia'),
        ('FL', 'Florida'),
        ('GA', 'Georgia'),
        ('GU', 'Guam'),
        ('HI', 'Hawaii'),
        ('ID', 'Idaho'),
        ('IL', 'Illinois'),
        ('IN', 'Indiana'),
        ('IA', 'Iowa'),
        ('KS', 'Kansas'),
        ('KY', 'Kentucky'),
        ('LA', 'Louisiana'),
        ('ME', 'Maine'),
        ('MH', 'Marshall Islands'),
        ('MD', 'Maryland'),
        ('MA', 'Massachusetts'),
        ('MI', 'Michigan'),
        ('MN', 'Minnesota'),
        ('MS', 'Mississippi'),
        ('MO', 'Missouri'),
        ('MT', 'Montana'),
        ('NE', 'Nebraska'),
        ('NV', 'Nevada'),
        ('NH', 'New Hampshire'),
        ('NJ', 'New Jersey'),
        ('NM', 'New Mexico'),
        ('NY', 'New York'),
        ('NC', 'North Carolina'),
        ('ND', 'North Dakota'),
        ('MP', 'Northern Mariana Islands'),
        ('OH', 'Ohio'),
        ('OK', 'Oklahoma'),
        ('OR', 'Oregon'),
        ('PW', 'Palau'),
        ('PA', 'Pennsylvania'),
        ('PR', 'Puerto Rico'),
        ('RI', 'Rhode Island'),
        ('SC', 'South Carolina'),
        ('SD', 'South Dakota'),
        ('TN', 'Tennessee'),
        ('TX', 'Texas'),
        ('UT', 'Utah'),
        ('VT', 'Vermont'),
        ('VI', 'Virgin Islands'),
        ('VA', 'Virginia'),
        ('WA', 'Washington'),
        ('WV', 'West Virginia'),
        ('WI', 'Wisconsin'),
        ('WY', 'Wyoming'),
    )

    DAY_CHOICES = ((u'1', 'Yes'), (u'0', 'No'))

    qa_objects = cms.QAManager()
    objects = cms.Manager()
    all_objects = models.Manager()
    item_url = 'location'
    search_order = 5
    search_limit = 10

    for_update = models.PositiveSmallIntegerField(default=2, editable=False)
    active = models.CharField(
        max_length=1,
        default=u'1',
        choices=cms.Model.ACTIVE,
        help_text=
        "Select Inactive to remove this location from display and search on the site."
    )
    display = models.CharField(
        max_length=1,
        default=u'1',
        choices=DISPLAY,
        help_text=
        "Select Hide from Lists to prevent this location from displaying on the /location/ page."
    )
    urlname = models.CharField(
        max_length=50,
        unique=True,
        help_text=
        "Enter identifier for URL, e.g. enter 'berkeley_heights' to have this Doctor load at '/location/berkeley_heights/')"
    )
    keywords = models.CharField(
        max_length=500,
        blank=True,
        help_text="Enter optional Top Match keywords separated by spaces.")
    meta_description = models.TextField(
        blank=True, help_text="Enter an optional meta description for SEO.")
    name = models.CharField(
        max_length=100,
        help_text=
        "Enter the administrative name for this location, e.g. Summit Satellite."
    )
    display_name = models.CharField(
        max_length=100,
        blank=True,
        help_text=
        "Enter the web display name for this location, e.g. Overlook Hopsital-MAC Building."
    )
    description = models.CharField(
        max_length=100,
        blank=True,
        help_text=
        "(Optional) Enter a short desciption or other information, e.g. Behavioral Health Only."
    )
    address = models.CharField(
        max_length=100,
        help_text=
        "Enter the street address for this location, e.g. 85 Woodland Road. Do not use this field for any information except a valid postal street address."
    )
    address2 = models.CharField(
        max_length=100,
        blank=True,
        help_text=
        "(Optional) Continue the street address for this location, e.g. Suite 304)."
    )
    city = models.CharField(
        max_length=100,
        help_text="Enter the city name for this location, e.g. Short Hills).")
    state = models.CharField(max_length=2, choices=STATE_CHOICES, default='NJ')
    zipcode = models.CharField(
        max_length=5, help_text="Enter the zip code for this location.")
    phone = models.CharField(
        max_length=19,
        blank=True,
        help_text="Enter a phone number for this location.")
    fax = models.CharField(
        max_length=19,
        blank=True,
        help_text="Enter on optional fax number for this location.")
    original_image = models.ImageField(
        blank=True,
        null=True,
        width_field='',
        height_field='',
        upload_to='db/location-images',
        help_text=
        "Upload an image for this location. This image will automatically be scaled to and %sx%s for display on the site."
        % (IMAGE_MAX_WIDTH, IMAGE_MAX_HEIGHT))
    image = models.ImageField(
        blank=True,
        null=True,
        editable=False,
        width_field='',
        height_field='',
        upload_to='db/location-images',
    )
    parking_code = models.CharField(
        max_length=5,
        blank=True,
        help_text=
        "Enter an optional parking code for this location, e.g. B or ASC.")
    parking_name = models.CharField(
        max_length=50,
        blank=True,
        help_text=
        "Enter an optional name for the parking area, e.g. Bensley Pavilion.")
    glatitude = models.CharField(max_length=25,
                                 blank=False,
                                 help_text="Enter latitude for google maps.")
    glongitude = models.CharField(max_length=25,
                                  blank=False,
                                  help_text="Enter longitude for google maps.")
    order = models.PositiveIntegerField(
        help_text=
        "Enter a number for the order in which this location should be displayed in lists."
    )
    info = models.TextField(
        blank=True,
        help_text="Enter an optional description for this location.")
    starttime = models.TimeField(
        blank=True,
        null=True,
        help_text=
        "Enter an optional 24-hour time for this location's standard opening time."
    )
    endtime = models.TimeField(
        blank=True,
        null=True,
        help_text=
        "Enter an optional 24-hour time for this location's standard closing time."
    )
    monday = models.CharField(
        max_length=1,
        default=u'1',
        choices=DAY_CHOICES,
        help_text="Select if a standard weekday opening.")
    tuesday = models.CharField(
        max_length=1,
        default=u'1',
        choices=DAY_CHOICES,
        help_text="Select if a standard weekday opening.")
    wednesday = models.CharField(
        max_length=1,
        default=u'1',
        choices=DAY_CHOICES,
        help_text="Select if a standard weekday opening.")
    thursday = models.CharField(
        max_length=1,
        default=u'1',
        choices=DAY_CHOICES,
        help_text="Select if a standard weekday opening.")
    friday = models.CharField(
        max_length=1,
        default=u'1',
        choices=DAY_CHOICES,
        help_text="Select if a standard weekday opening.")
    hours_comments = models.TextField(
        blank=True,
        help_text="Enter optional comments for hours at this location.")

    class Meta:
        ordering = ['order', 'name']

    def __unicode__(self):
        if self.parking_name:
            return u'%s - %s' % (self.name, self.parking_name)
        else:
            return u'%s' % (self.name)

    def get_absolute_url(self):
        return "/%s/%s/" % (self.item_url, self.urlname)

    def options(self):
        weekday = self.weekdayhours_set.all()
        saturday = self.saturdayhours_set.all()
        sunday = self.sundayhours_set.all()
        if weekday or saturday or sunday:
            return True
        return False

    def save(self, preview=True):
        # We use thumbnail in templates can preserve original image here I think.
        #if self.original_image:
        #image_make_thumbnail(self, 'original_image', 'image', 'db/location-images', IMAGE_MAX_WIDTH, IMAGE_MAX_HEIGHT)
        super(Location, self).save(preview)
        cache.delete('finder-location-berkeley')
        cache.delete('finder-location-subberkeley')
        cache.delete('finder-location-notberkeley')
        snbkey = self.city.replace(' ', '_')
        cache.delete('finder-location-subnotberkeley-%s' % snbkey)
        cache.delete('finder-locations')

    def search_index(self):
        # Return a (key, url, order, display, name, body) tuple with text for indexing
        body = u'%s %s %s %s %s %s %s %s %s' % (
            self.name, self.address, self.address2, self.city, self.state,
            self.zipcode, self.phone, self.fax, self.parking_name)
        return SearchKey(self.pk, self.get_absolute_url(), self.order,
                         self.name, self.name, body)

    def keyword_index(self):
        # Return a (key, url, order, display, name, body) tuple with text for keyword indexing
        return SearchKey(self.pk, self.get_absolute_url(), self.order,
                         self.name, self.keywords, self.keywords)

    @property
    def get_display_name(self):
        # noticed that sometimes there is no display name so will return the name instead
        if self.display_name:
            return self.display_name
        else:
            return self.name

    @property
    def display_address(self):
        # address format probably needs to be refactored
        address_list = filter(
            None, (self.display_name, self.address, self.address2, self.city,
                   '%s %s' % (self.state, self.zipcode)))
        print ', '.join(address_list)
        return ', '.join(address_list)

    @property
    def display_image(self):
        if self.original_image:
            return self.original_image
        else:
            return MissingImage(name='db/image-library/location_default.jpg')