Exemplo n.º 1
0
class Slide(Orderable):
    '''
    A slide in a slider connected to a HomePage
    '''
    homepage = models.ForeignKey(HomePage, related_name="slides")
    background = FileField(verbose_name=_("Background Image"),
                           upload_to=upload_to("theme.Slide.image", "slider"),
                           format="Image",
                           max_length=255,
                           blank=True)
    heading = models.CharField(max_length=100, blank=True)
    subheading = models.CharField(max_length=100, blank=True)
    content = models.TextField(blank=True,
                               help_text="Add <br> for line breaks")
    button_text = models.CharField(
        max_length=100,
        blank=True,
        help_text="Optional, if present a button with the link specified "
        "below will be in the slide")
    button_link = models.CharField(max_length=2000, blank=True)
    image = FileField(verbose_name=_("Image"),
                      upload_to=upload_to("theme.Slide.image", "slider"),
                      format="Image",
                      max_length=255,
                      blank=True)
    custom = models.TextField(
        blank=True,
        help_text="Create a custom slide, everything else will be overriden")
Exemplo n.º 2
0
class Slide(Orderable):
    '''
    A slide in a slider connected to a HomePage.
    '''
    homepage = models.ForeignKey(HomePage, related_name='slides')
    image = FileField(verbose_name=_('Image'),
                      upload_to=upload_to('theme.Slide.image', 'slider'),
                      format='Image',
                      max_length=255,
                      null=True,
                      blank=True)

    # Caption
    cap_header = models.CharField(max_length=200)
    cap_sub = models.CharField(max_length=200)
    cap_image1 = FileField(verbose_name=_('cap image 1'),
                           upload_to=upload_to('theme.slide.cap_image1',
                                               'slider'),
                           format='Image',
                           max_length=255,
                           null=True,
                           blank=True)
    cap_image2 = FileField(verbose_name=_('cap image 2'),
                           upload_to=upload_to('theme.slide.cap_image2',
                                               'slider'),
                           format='Image',
                           max_length=255,
                           null=True,
                           blank=True)
Exemplo n.º 3
0
class NewsPost(Displayable, RichText, AdminThumbMixin):
    featured_image = FileField(verbose_name="Featured Image",
        upload_to=upload_to("images", "images"),
        format="Image", max_length=255, null=True, blank=True)
    admin_thumb_field = "featured_image"
    featured_image_wide = FileField(verbose_name="Featured Image (Wide)",
        upload_to=upload_to("images", "images"),
        format="Image", max_length=255, null=True, blank=True,
        help_text="For front-page slider images, please make sure they are at least 785px wide and 400px tall.")
    marquee_caption = models.CharField(null=True, blank=True, max_length=255)
    login_required = models.BooleanField("Login required",
        default=False,
        help_text="If checked, only logged in users can view this page")
    parent = None # To make it compatible with the side_menu template
    children = DummyEmptyResultSet() # To make it compatible with the side_menu template
    category = ForeignKey('sfpirgapp.Category', related_name='news_posts')
    in_menus = MenusField("Show in menus", blank=True, null=True)

    @property
    def richtextpage(self):
        return self

    @models.permalink
    def get_absolute_url(self):
        return ('news-post', (), {'news': self.slug})

    def in_menu_template(self, template_name):
        if self.in_menus is not None:
            for i, l, t in settings.PAGE_MENU_TEMPLATES:
                if not unicode(i) in self.in_menus and t == template_name:
                    return False
        return True
Exemplo n.º 4
0
class SiteConfiguration(SiteRelated):
    """Singleton model for storing site-wide variables."""

    logo = FileField("Logo", upload_to="site", format="Image", blank=True)
    logo_small = FileField(_("Small Logo"),
                           upload_to="site",
                           format="Image",
                           blank=True)
    favicon = FileField(
        _("Favicon"),
        upload_to="site",
        blank=True,
        help_text=_("An image that appears in the browser tab"))
    footer_address = RichTextField(
        default=_("Our address"),
        help_text=_("Company address displayed in footer."))
    footer_subscribe_info = models.CharField(
        max_length=200,
        default=_("Pellentesque habitant morbi tristique senectus et netus \
                et malesuada fames ac turpis egestas."),
        help_text=_("Text displayed above the subscription email field."))

    def __str__(self):
        return str(self.site)

    class Meta:
        verbose_name = verbose_name_plural = _("Site Configuration")
Exemplo n.º 5
0
class HomePage(Page):
    '''
    A home page page type
    '''
    heading = models.CharField(max_length=100)
    slide_in_one_icon = models.CharField(max_length=50, blank=True)
    slide_in_one = models.CharField(max_length=200, blank=True)
    slide_in_two_icon = models.CharField(max_length=50, blank=True)
    slide_in_two = models.CharField(max_length=200, blank=True)
    slide_in_three_icon = models.CharField(max_length=50, blank=True)
    slide_in_three = models.CharField(max_length=200, blank=True)
    header_background = FileField(verbose_name=_("Header Background"),
                                  upload_to=upload_to(
                                      "theme.HomePage.header_background",
                                      "homepage"),
                                  format="Image",
                                  max_length=255,
                                  blank=True)
    header_image = FileField(verbose_name=_("Header Image (optional)"),
                             upload_to=upload_to("theme.HomePage.header_image",
                                                 "homepage"),
                             format="Image",
                             max_length=255,
                             blank=True,
                             null=True)
    welcome_heading = models.CharField(max_length=100, default="Welcome")
    content = RichTextField()
    recent_blog_heading = models.CharField(max_length=100,
                                           default="Latest blog posts")
    number_recent_posts = models.PositiveIntegerField(
        default=3, help_text="Number of recent blog posts to show")

    class Meta:
        verbose_name = _("Home page")
        verbose_name_plural = _("Home pages")
Exemplo n.º 6
0
class HomePage(Page):
    '''
    A home page page type
    '''
    MESSAGE_TYPE_CHOICES = (('warning', 'Warning'), ('information', 'Information'))
    heading = models.CharField(max_length=100)
    slide_in_one_icon = models.CharField(max_length=50, blank=True)
    slide_in_one = models.CharField(max_length=200, blank=True)
    slide_in_two_icon = models.CharField(max_length=50, blank=True)
    slide_in_two = models.CharField(max_length=200, blank=True)
    slide_in_three_icon = models.CharField(max_length=50, blank=True)
    slide_in_three = models.CharField(max_length=200, blank=True)
    header_background = FileField(verbose_name=_("Header Background"),
        upload_to=upload_to("theme.HomePage.header_background", "homepage"),
        format="Image", max_length=255, blank=True)
    header_image = FileField(verbose_name=_("Header Image (optional)"),
        upload_to=upload_to("theme.HomePage.header_image", "homepage"),
        format="Image", max_length=255, blank=True, null=True)
    welcome_heading = models.CharField(max_length=100, default="Welcome")
    content = RichTextField()
    recent_blog_heading = models.CharField(max_length=100, default="Latest blog posts")
    number_recent_posts = models.PositiveIntegerField(default=3,
        help_text="Number of recent blog posts to show")

    # The following date fields are used for duration during which the message will be displayed
    message_start_date = models.DateField(null=True, help_text="Date from which the message will "
                                                               "be displayed")
    message_end_date = models.DateField(null=True, help_text="Date on which the message will no "
                                                             "more be displayed")

    # this must be True for the message to be displayed
    show_message = models.BooleanField(default=False, help_text="Check to show message")

    # use message type to change background color of the message
    message_type = models.CharField(max_length=100, choices=MESSAGE_TYPE_CHOICES,
                                    default='Information')

    class Meta:
        verbose_name = _("Home page")
        verbose_name_plural = _("Home pages")

    @property
    def can_show_message(self):
        if not self.show_message:
            return False
        message = strip_tags(self.content).strip()
        if not message:
            return False
        today = datetime.datetime.combine(datetime.datetime.today(), datetime.time())
        today = timezone.make_aware(today)
        today = today.date()
        if self.message_start_date and self.message_end_date:
            if self.message_start_date <= today <= self.message_end_date:
                return True

        return False
Exemplo n.º 7
0
class ProjectPage(Displayable):
    project_data = models.ForeignKey(Project)
    project_content = RichTextField()
    project_image = FileField(format="Image")
    override_image = FileField(format="Image", blank=True, null=True)
    def get_absolute_url(self):
        name = '/projects/' + slugify(self.project_data.project_title)
        return name

    class Meta:
        ordering = ('-project_data__project_create_update',)
Exemplo n.º 8
0
class Staffer(models.Model):
    name = models.CharField(max_length=255)
    photo = FileField(format="Image")
    profile_photo = FileField(format="Image", blank=True, null=True)
    title = models.CharField(max_length=255)
    full_title = models.CharField(max_length=255, blank=True, null=True)
    email = models.EmailField(blank=True, null=True)
    education = models.CharField(max_length=500, blank=True, null=True)
    sortorder = models.IntegerField()

    def __str__(self):
        return self.title + ': ' + self.name
Exemplo n.º 9
0
class Slide(Orderable):
    page = models.ForeignKey(Page, verbose_name='Слайдер', related_name='slide_list')
    image = FileField(verbose_name='Изображение',
                      upload_to='slider', format="Image", max_length=255)
    image_mobile = FileField(verbose_name='Изображение mobile', null=True, blank=True,
                             upload_to='slider', format="Image", max_length=255)

    link = models.URLField('Ссылка', null=True, blank=True)

    published = models.BooleanField('Опубликовано', default=True)

    class Meta:
        verbose_name = 'Слайд'
        verbose_name_plural = 'Слайды'
Exemplo n.º 10
0
class FileAttachment(models.Model):
    attached_file = FileField("Image, Document")
    display_name = models.CharField(max_length=255)
    generic_template = models.ForeignKey("stocktemplate.StockLandingPage",
                                         on_delete=models.CASCADE,
                                         blank=True,
                                         null=True)
Exemplo n.º 11
0
class PortfolioItem(Page, RichText):
    '''
    An individual portfolio item, should be nested under a Portfolio
    '''
    layout = models.PositiveIntegerField(choices=PORTFOLIO_ITEM_LAYOUT_CHOICES,
        default=1)
    description_heading = models.CharField(max_length=200,
                                           default="Project description")
    featured_image = FileField(verbose_name=_("Featured Image"),
        upload_to=upload_to("theme.PortfolioItem.featured_image", "portfolio"),
        format="Image", max_length=255, null=True, blank=True)
    featured_video = models.TextField(blank=True,
        help_text= "Optional, putting video embed code (iframe) here, will "
                   "override a Featured image specified above.  This has "
                   "been tested to work with Youtube and Vimeo, but may "
                   "work with other iframes as well.")
    details_heading = models.CharField(max_length=200, default="Project details")
    categories = models.ManyToManyField("PortfolioItemCategory",
                                        verbose_name=_("Categories"),
                                        blank=True,
                                        related_name="portfolioitems")
    website = models.CharField(max_length=2000, blank=True,
        help_text="A link to the finished project or clients website "
                  " (optional)")
    related_items = models.ManyToManyField("self", blank=True)

    class Meta:
        verbose_name = _("Portfolio item")
        verbose_name_plural = _("Portfolio items")
Exemplo n.º 12
0
class PortfolioItem(Page, RichText):
    '''
    An individual portfolio item, should be nested under a Portfolio
    '''
    featured = models.BooleanField(help_text='Show image of home page'
                                   ' when this portfolio is selected.')

    featured_image = FileField(verbose_name=_('Featured Image'),
                               upload_to=upload_to(
                                   'theme.PortfolioItem.featured_image',
                                   'portfolio'),
                               format='Image',
                               max_length=255,
                               null=True,
                               blank=True)
    short_description = RichTextField(blank=True)
    categories = models.ManyToManyField('PortfolioItemCategory',
                                        verbose_name=_('Categories'),
                                        blank=True,
                                        related_name='portfolioitems')
    href = models.CharField(
        max_length=2000,
        blank=True,
        help_text='A link to the finished project (optional)')

    class Meta:
        verbose_name = _('Portfolio item')
        verbose_name_plural = _('Portfolio items')
Exemplo n.º 13
0
class GalleryImage(models.Model):
    gallery = models.ForeignKey(Gallery, on_delete=models.CASCADE)
    featured = models.BooleanField(default=False)
    image = FileField(verbose_name=_("Image"), upload_to=upload_to("", "gallery"), format="Image", max_length=255)

    def __unicode__(self):
        return self.gallery.title
Exemplo n.º 14
0
class Attachment(models.Model):
    title = models.CharField(max_length=255)
    author = models.CharField(max_length=255, blank=True)
    file = FileField('Document',
                     blank=True,
                     upload_to=upload_to("resources.documents", "documents"))
    url = models.URLField(blank=True)
    # TODO: needs validation to ensure one and only one of
    # file and url is set
    PDF = 'PDF'
    MSWORD = 'DOC'
    VIDEO = 'VIDEO'
    URL = 'URL'
    type_choices = (
        (PDF, 'PDF Document'),
        (MSWORD, 'MS Word Document'),
        (VIDEO, 'Video'),
        (URL, 'URL'),
    )
    attachment_type = models.CharField(max_length=255, choices=type_choices)

    pages = models.ManyToManyField(Page,
                                   related_name='attachments',
                                   blank=True)

    def __str__(self):
        parts = [self.title]
        if self.author:
            parts.append(', %s' % self.author)
        if self.attachment_type:
            parts.append(' (%s)' % self.attachment_type)
        return ''.join(parts)
class MediaFile(Orderable):
    """Single file to add in a library."""

    library = models.ForeignKey("MediaLibrary", related_name="files",on_delete=models.DO_NOTHING,)
    file = FileField(_("File"), max_length=200,
            upload_to=upload_to("galleries.GalleryImage.file", "galleries"))
    title = models.CharField(_("Title"), max_length=50, blank=True)
    description = models.CharField(_("Description"), max_length=1000,
                                   blank=True)

    class Meta:
        verbose_name = _("Media File")
        verbose_name_plural = _("Media Files")

    def __unicode__(self):
        return self.description

    def save(self, *args, **kwargs):
        """
        If no description is given when created, create one from the
        file name.
        """
        if not self.id and not self.description:
            name = unquote(self.file.url).split("/")[-1].rsplit(".", 1)[0]
            name = name.replace("'", "")
            name = "".join([c if c not in punctuation else " " for c in name])
            # str.title() doesn't deal with unicode very well.
            # http://bugs.python.org/issue6412
            name = "".join([s.upper() if i == 0 or name[i - 1] == " " else s
                            for i, s in enumerate(name)])
            self.description = name
        super(MediaFile, self).save(*args, **kwargs)
Exemplo n.º 16
0
class PortfolioItem(Page, RichText):
    '''
    An individual portfolio item, should be nested under a Portfolio
    '''
    # This is the featured image, but also we use PortfolioItemImage
    # to add more images that can be scrolled through (c.f. choices
    # associated with a Poll obj in django tut via Foreign key)

    # NB the related names are what you will need when grabbing these
    # objects in either view or template after dotting.
    featured = models.BooleanField()  # to be featured on homepage or not.
    highlighted = models.BooleanField()  # Is it big or small on homepage
    featured_image = FileField(verbose_name=_('Featured Image'),
                               upload_to=upload_to('theme.PortfolioItem.featured_image', 'portfolio'),
                               format='Image', max_length=255, null=True, blank=True)
    short_description = RichTextField(blank=True)
    categories = models.ManyToManyField('PortfolioItemCategory',
                                        verbose_name=_('Categories'),
                                        blank=True,
                                        related_name='portfolioitems')
    href = models.CharField(max_length=2000, blank=True,
                            help_text='A link to the finished project (optional)')

    class Meta:
        verbose_name = _('Portfolio item')
        verbose_name_plural = _('Portfolio items')
Exemplo n.º 17
0
class WorkImage(models.Model):
  
    gallery = models.ForeignKey("Work", related_name="workimage")
    file = FileField(_("File"), max_length=200, format="Image",
        upload_to=upload_to("galleries.GalleryImage.file", "gallery"))
    description = models.CharField(_("Description"), max_length=1000,
                                                           blank=True)
    #from PIL import Image
    #image = file.fieldfile
    #meta = get_exif(file.open)
  
    class Meta:
        verbose_name = _("Image")
        verbose_name_plural = _("Images")
  
    def __str__(self):
        return self.description
  
    def save(self, *args, **kwargs):
        """
        If no description is given when created, create one from the
        file name.
        """
        if not self.id and not self.description:
            name = force_text(self.file.name)
            name = name.rsplit("/", 1)[-1].rsplit(".", 1)[0]
            name = name.replace("'", "")
            name = "".join([c if c not in punctuation else " " for c in name])
            # str.title() doesn't deal with unicode very well.
            # http://bugs.python.org/issue6412
            name = "".join([s.upper() if i == 0 or name[i - 1] == " " else s
                            for i, s in enumerate(name)])
            self.description = name
        super(WorkImage, self).save(*args, **kwargs)
Exemplo n.º 18
0
class StockLandingPage(Page):
    image  = FileField("Image", format="Image", blank=True, null=True)
    content = RichTextField()

    class Meta:
        verbose_name = 'Generic Page'
        verbose_name_plural = 'Generic Pages'
Exemplo n.º 19
0
class OrganizationService(Named, URL, Orderable):
    organization = models.ForeignKey(
        Organization,
        verbose_name=_('organization'),
        related_name='services',
        blank=True,
        null=True,
        on_delete=models.SET_NULL
    )
    image = FileField(
        _("Image"),
        max_length=1024,
        format="Image",
        upload_to="images"
    )
    css_color = models.CharField(
        _('css color'),
        max_length=64,
        blank=True,
        null=True,
        choices=CSS_COLOR_CHOICES
    )
    css_banner_type = models.CharField(
        _('css banner type'),
        max_length=64,
        blank=True,
        null=True,
        choices=CSS_BANNER_CHOICES
    )
    box_size = models.IntegerField(_('box size'), default=3, choices=BOX_SIZE_CHOICES)
Exemplo n.º 20
0
class PublicationCaption(models.Model):
    master = models.ForeignKey("Press")
    title = models.CharField(max_length=255, null=False, blank=False)
    illustration = FileField(verbose_name=_("Illustration"),
        upload_to=upload_to("MAIN.PublicationCaption.illustration", "Publication"),
        format="Image", max_length=255)
    lien = models.URLField(null=False, blank=True)
Exemplo n.º 21
0
class Person(Displayable):
    POSITIONS = (
        (0, _('Тренер')),
        (10, _('Спортсмен')),
        (20, _('Президент федерации')),
        (30, _('Вице президент федерации')),
    )
    position = models.PositiveIntegerField(_('Должность'),
                                           default=0,
                                           choices=POSITIONS)
    rank = models.ForeignKey(Rank, verbose_name=_('Разряд'))
    photo = FileField(_('Фото'), format='Image', upload_to='stuff')
    phone_no = models.CharField(_('Телефон'),
                                max_length=30,
                                null=True,
                                blank=True)
    content = RichTextField(_('Тескт'))
    gallery = models.ForeignKey('media.Gallery',
                                verbose_name=_('Галлерея'),
                                null=True,
                                blank=True)

    class Meta:
        verbose_name = _('Сотрудник')
        verbose_name_plural = _('Сотрудники')

    def __str__(self):
        return self.title

    @models.permalink
    def get_absolute_url(self):
        return 'person_detail', [], {'slug': self.slug}
Exemplo n.º 22
0
Arquivo: models.py Projeto: jowolf/tlg
class Slide(Orderable):
    '''
    A slide in a slider connected to a HomePage
    '''
    homepage = models.ForeignKey(HomePage, related_name="slides")

    image = FileField(
        verbose_name=_("Image"),
        #upload_to = upload_to ("theme.Slide.image", "slider"),
        #upload_to = os.path.join (host_theme_name(), "slider"),
        upload_to=slider_path,
        format="Image",
        max_length=255,
        null=True,
        blank=True)
    title = models.CharField(max_length=200)  # Heading or H2
    description = models.TextField()  # description or p
    html = models.TextField(
        blank=True,
        help_text="Alternative to Image field - eg, Video embed, etc"
    )  # could use similar idea for FA icon
    link = models.CharField(
        max_length=2000,
        blank=True,
        help_text=
        "Optional, if provided clicking the image or blurb will go here.")
Exemplo n.º 23
0
class PortfolioItem(Page, RichText):
    '''
    An individual portfolio item, should be nested under a Portfolio
    '''
    subtitle = models.CharField(max_length=200, blank=True)
    featured_image = FileField(verbose_name=_("Featured Image"),
                               upload_to=upload_to(
                                   "theme.PortfolioItem.featured_image",
                                   "portfolio"),
                               format="Image",
                               max_length=255,
                               null=True,
                               blank=True)
    categories = models.ManyToManyField("PortfolioItemCategory",
                                        verbose_name=_("Categories"),
                                        blank=True,
                                        related_name="portfolioitems")
    href = models.CharField(
        max_length=2000,
        blank=True,
        help_text="A link to the finished project (optional)")

    class Meta:
        verbose_name = _("Portfolio item")
        verbose_name_plural = _("Portfolio items")
Exemplo n.º 24
0
class BlogPost(Displayable, Ownable, RichText, AdminThumbMixin):
    """
    A blog post.
    """

    categories = models.ManyToManyField("BlogCategory",
                                        verbose_name=_("Categories"),
                                        blank=True,
                                        related_name="blogposts")
    allow_comments = models.BooleanField(verbose_name=_("Allow comments"),
                                         default=True)
    comments = CommentsField(verbose_name=_("Comments"))
    rating = RatingField(verbose_name=_("Rating"))
    featured_image = FileField(verbose_name=_("Featured Image"),
                               upload_to="blog",
                               format="Image",
                               max_length=255,
                               null=True,
                               blank=True)
    related_posts = models.ManyToManyField("self",
                                           verbose_name=_("Related posts"),
                                           blank=True)

    admin_thumb_field = "featured_image"

    class Meta:
        verbose_name = _("Blog post")
        verbose_name_plural = _("Blog posts")
        ordering = ("-publish_date", )

    @models.permalink
    def get_absolute_url(self):
        url_name = "blog_post_detail"
        kwargs = {"slug": self.slug}
        if settings.BLOG_URLS_USE_DATE:
            url_name = "blog_post_detail_date"
            month = str(self.publish_date.month)
            if len(month) == 1:
                month = "0" + month
            day = str(self.publish_date.day)
            if len(day) == 1:
                day = "0" + day
            kwargs.update({
                "day": day,
                "month": month,
                "year": self.publish_date.year,
            })
        return (url_name, (), kwargs)

    # These methods are wrappers for keyword and category access.
    # For Django 1.3, we manually assign keywords and categories
    # in the blog_post_list view, since we can't use Django 1.4's
    # prefetch_related method. Once we drop support for Django 1.3,
    # these can probably be removed.

    def category_list(self):
        return getattr(self, "_categories", self.categories.all())

    def keyword_list(self):
        return getattr(self, "_keywords", self.keywords.all())
Exemplo n.º 25
0
class ProductImage(Orderable):
    """
    An image for a product - a relationship is also defined with the
    product's variations so that each variation can potentially have
    it own image, while the relationship between the ``Product`` and
    ``ProductImage`` models ensures there is a single set of images
    for the product.
    """

    file = FileField(_("Image"),
                     max_length=255,
                     format="Image",
                     upload_to=upload_to("shop.ProductImage.file", "product"))
    description = CharField(_("Description"), blank=True, max_length=100)
    product = models.ForeignKey("Product",
                                on_delete=models.DO_NOTHING,
                                related_name="images")

    class Meta:
        verbose_name = _("Image")
        verbose_name_plural = _("Images")
        order_with_respect_to = "product"

    def __str__(self):
        value = self.description
        if not value:
            value = self.file.name
        if not value:
            value = ""
        return value
Exemplo n.º 26
0
class Screenshot(Orderable, TimeStamped, AdminThumbMixin):
    application = models.ForeignKey(Application)
    image = FileField(verbose_name=_("Screenshot"),
                      upload_to=upload_to("gameprofiles.Screenshot.image",
                                          "uploads/gameprofiles/screenshots"),
                      format="Image",
                      max_length=255)
Exemplo n.º 27
0
class BlogPostImage(Orderable):
    '''
    An image for a BlogPost slideshow
    '''
    blog_post = models.ForeignKey(BlogPost, related_name="images")
    file = FileField(_("File"), max_length=200, format="Image",
        upload_to=upload_to("mezzanine.blog.BlogPost.file", "blog"))
    alt_text = models.CharField(max_length=200, blank=True)

    class Meta:
        verbose_name = _("Slideshow (will only display if a featured video "
                         "is not specified above).  If no featured image is "
                         "selected above the first image added will become "
                         "the featured image.")
        verbose_name_plural = _("Slideshow (will only display if a featured "
                                "video is not specified above).  If no "
                                "featured image is selected above the first "
                                "image added will become the featured image.")

    def save(self, *args, **kwargs):
        if not self.blog_post.featured_image:
            self.blog_post.featured_image = self.file
            self.blog_post.save()
            if self.id:
               self.delete()
        else:
            super(BlogPostImage, self).save(*args, **kwargs)
Exemplo n.º 28
0
class Promo(models.Model):
    CONTENT_STATUS_DRAFT = 1
    CONTENT_STATUS_PUBLISHED = 2
    CONTENT_STATUS_CHOICES = (
        (CONTENT_STATUS_DRAFT, "Draft"),
        (CONTENT_STATUS_PUBLISHED, "Published"),
    )
    title = models.CharField(
        max_length=128,
        help_text="A title for the promo.  Helps you to remember what it is.",
        blank=False)
    status = models.IntegerField(choices=CONTENT_STATUS_CHOICES,
                                 default=CONTENT_STATUS_DRAFT)
    publish_on = models.DateField(blank=False)
    publish_until = models.DateField(blank=True, null=True)
    url = models.URLField(blank=True, null=True)
    page = models.ForeignKey(Page, blank=True, null=True)
    image = FileField(max_length=100, upload_to='galleries', format='Image')

    def __unicode__(self):
        return self.title

    def save(self, *args, **kwargs):
        if self.page:
            self.url = 'http://www.krrcfs.ca' + self.page.get_absolute_url()
        super(Promo, self).save(*args, **kwargs)
Exemplo n.º 29
0
class GenericContent(models.Model):
    def get_absolute_url(self):
        pass

    basicPage_id = models.AutoField(primary_key=True)
    showDate = models.BooleanField(_("Show date"), default=False)
    author = models.CharField(max_length=500, blank=True)
    summary = RichTextField(blank=True)
    image = models.ImageField(upload_to="contentImg", blank=True)
    image = FileField(verbose_name=_("Image"),
                      upload_to=upload_to("contentImg", "genericContent"),
                      format="Image",
                      max_length=255,
                      null=True,
                      blank=True)
    image_footer = RichTextField(blank=True)
    video_footer = RichTextField(blank=True)
    hostVideo = models.SmallIntegerField(choices=(
        (VideoHost.Ninguno, "----"),
        (VideoHost.Youtube, "Youtube"),
        (VideoHost.Vimeo, "Vimeo"),
    ),
                                         default=VideoHost.Ninguno,
                                         blank=True)
    video_id = models.CharField(max_length=255,
                                null=True,
                                help_text=_("The id of the video"),
                                blank=True)
Exemplo n.º 30
0
class EventImage(Orderable):
    gallery = models.ForeignKey("calendar.Event", related_name="images")
    file = FileField(_("File"), max_length=200, format="Image",
                     upload_to=upload_to("calendar.EventImage.file", "events"))
    description = models.CharField(_("Description"), max_length=1000,
                                   blank=True)

    class Meta:
        verbose_name = _("Image")
        verbose_name_plural = _("Images")

    def __unicode__(self):
        return self.description

    def save(self, *args, **kwargs):
        """
        If no description is given when created, create one from the
        file name.
        """
        if not self.id and not self.description:
            name = unquote(self.file.url).split("/")[-1].rsplit(".", 1)[0]
            name = name.replace("'", "")
            name = "".join([c if c not in punctuation else " " for c in name])
            # str.title() doesn't deal with unicode very well.
            # http://bugs.python.org/issue6412
            name = "".join([s.upper() if i == 0 or name[i - 1] == " " else s
                            for i, s in enumerate(name)])
            self.description = name
        super(EventImage, self).save(*args, **kwargs)