示例#1
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")
示例#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)
示例#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
示例#4
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")
示例#5
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
示例#6
0
class Profile(models.Model, AdminThumbMixin):
    organization = ForeignKey(
        'Organization',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
    )
    user = models.OneToOneField(User)
    date_of_birth = models.DateField(null=True, blank=True)
    title = models.CharField(null=True, blank=True, max_length=255)
    bio = RichTextField(null=True, blank=True)
    photo = MyImageField(verbose_name="Photo",
                         upload_to=upload_to("sfpirgapp.Profile.photo",
                                             "uploads/profile-photos"),
                         format="Image",
                         max_length=255,
                         null=True,
                         blank=True,
                         help_text='User photo')
    admin_thumb_field = "photo"
    on_mailing_list = models.BooleanField(
        default=True,
        verbose_name='Would you like to be added to our mailing list?',
        help_text=
        'Would you like to be added to our mailing list to receive periodic information about social and environmental justice happenings on and off campus?'
    )
示例#7
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')
示例#8
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)
示例#9
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)
示例#10
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=upload_to("blog.BlogPost.featured_image", "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):
        try:
            return self._keywords
        except AttributeError:
            keywords = [k.keyword for k in self.keywords.all()]
            setattr(self, "_keywords", keywords)
            return self._keywords
示例#11
0
文件: models.py 项目: davit-gh/flaunt
class PortfolioItemImage(Orderable):
    portfolioitem = models.ForeignKey(PortfolioItem, related_name="images")
    file = FileField(_("File"), max_length=200, format="Image",\
	    upload_to=upload_to("flaunt.PortfolioItemImage.file", "portfolio items"))
    class Meta:
	verbose_name="Portfolio Item Image"
	verbose_name_plural="Portfolio Item Images"
示例#12
0
class Category(Displayable, AdminThumbMixin):
    image = FileField(verbose_name=_("Image"),
                      upload_to=upload_to("article.Category.image",
                                          "category"),
                      format="Image",
                      max_length=255,
                      null=False,
                      blank=False)

    admin_thumb_field = "image"

    objects = DisplayableManager()
    search_fields = {"title": 10, "description": 5}

    @models.permalink
    def get_absolute_url(self):
        return ("category-detail", (), {"slug": self.slug})

    class Meta:
        verbose_name = _("Category")
        verbose_name_plural = _("Categories")
        ordering = ("title", )
        app_label = "article"

    @property
    def get_thumbnail(self):
        return self.image
示例#13
0
class Location(Displayable):
    location = GeopositionField("Location")

    objects = DisplayableManager()
    search_fields = {"title": 10, "description": 5}

    image = FileField(verbose_name=_("Image"),
                      upload_to=upload_to("article.Location.image", "location"),
                      format="Image", max_length=255, null=True, blank=True)

    def get_as_latLng(self):
        return unicode(self.location).split(',')

    def get_articles(self):
        return self.article_set.filter(is_topic=False)[:5]

    def get_topics(self):
        return self.article_set.filter(is_topic=True)[:5]

    def __unicode__(self):
        return u"%s (%s)" % (self.title, self.location)

    @models.permalink
    def get_absolute_url(self):
        return ("location-detail", (), {"slug": unicode(self.slug)})

    class Meta:
        app_label = "article"

    @property
    def get_thumbnail(self):
        return self.image
示例#14
0
class Company(Page):
    subsidiaries = models.ManyToManyField("self",through='Subsidiary',symmetrical=False)
    illustration = FileField(verbose_name=_("illustration"),
        upload_to=upload_to("MAIN.Company.illustration", "company"),
        format="Image", max_length=255, null=False, blank=True)
    topics = models.ManyToManyField('Topic',blank=True)
    brands = models.ManyToManyField('Brand',blank=True)
    adress = models.CharField(max_length=255, null=False,blank=True)
    zipCode = models.CharField(max_length=255, null=False,blank=True)
    area = models.CharField(max_length=255, null=False,blank=True)
    city = models.CharField(max_length=255, null=False,blank=True)
    country = models.CharField(max_length=255,null=False,blank=True)
    email = models.EmailField(null=False,blank=True)
    tel = models.CharField(max_length=255, null=False,blank=True)
    fax = models.CharField(max_length=255, null=False,blank=True)
    website = models.CharField(max_length=255, null=False,blank=True)
    highlight = models.BooleanField(default=False,null=False,blank=True)

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

    class Meta:
        verbose_name='SOCIETE'
        ordering = ['title']

    def save(self, *args, **kwargs):
        self.in_menus = []
        if not self.parent:
            self.parent = Page.objects.get(title='SOCIETES')
        # if not self.area:
            # if not self.country or self.country.lower() == "france":
                # deduce area from zipCode[:2]
        super(Company, self).save(*args, **kwargs)
示例#15
0
class Person(Page):
    illustration = FileField(verbose_name=_("illustration"),
        upload_to=upload_to("MAIN.Person.illustration", "person"),
        format="Image", max_length=255, null=True, blank=True)
    firstName = models.CharField(max_length=255,null=False,blank=True)
    companies = models.ManyToManyField(Company,through='Job')
    adress = models.CharField(max_length=255, null=False,blank=True)
    zipCode = models.CharField(max_length=255, null=False,blank=True)
    area = models.CharField(max_length=255, null=False,blank=True)
    city = models.CharField(max_length=255, null=False,blank=True)
    country = models.CharField(max_length=255,null=False,blank=True)
    email = models.EmailField(null=False,blank=True)
    tel = models.CharField(max_length=255, null=False,blank=True)
    highlight = models.BooleanField(default=False,null=False,blank=True)

    def __unicode__(self):
        return '%s %s' % (self.title.upper(), self.firstName.lower())

    def save(self, *args, **kwargs):
        self.in_menus = []
        self.parent = Page.objects.get(title='MEMBRES')
        super(Person, self).save(*args,**kwargs)

    class Meta:
        verbose_name='INDIVIDU'
示例#16
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)
示例#17
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)
示例#18
0
class Gallery(Displayable):
    gallery_description = models.TextField(null=True, blank=True)
    thumbnail = FileField(verbose_name=_("Thumbnail"), upload_to=upload_to("", "gallery_thumbs"),
                          format="Image", max_length=255)

    def get_absolute_url(self):
        return reverse('gallery_detail', args=[self.slug])
示例#19
0
文件: models.py 项目: Ryochan7/asylum
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)
示例#20
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
示例#21
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)
示例#22
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)
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)
示例#24
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 = models.ImageField(_("Image"),
                             upload_to=upload_to("shop.ProductImage.file",
                                                 "product"))
    description = CharField(_("Description"), blank=True, max_length=100)
    product = models.ForeignKey("Product", related_name="images")

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

    def __unicode__(self):
        value = self.description
        if not value:
            value = self.file.name
        if not value:
            value = ""
        return value
示例#25
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")
示例#26
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")
示例#27
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')
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=upload_to("blog.BlogPost.featured_image", "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", )

    def get_absolute_url(self):
        """
        URLs for blog posts can either be just their slug, or prefixed
        with a portion of the post's publish date, controlled by the
        setting ``BLOG_URLS_DATE_FORMAT``, which can contain the value
        ``year``, ``month``, or ``day``. Each of these maps to the name
        of the corresponding urlpattern, and if defined, we loop through
        each of these and build up the kwargs for the correct urlpattern.
        The order which we loop through them is important, since the
        order goes from least granular (just year) to most granular
        (year/month/day).
        """
        url_name = "blog_post_detail"
        kwargs = {"slug": self.slug}
        date_parts = ("year", "month", "day")
        if settings.BLOG_URLS_DATE_FORMAT in date_parts:
            url_name = "blog_post_detail_%s" % settings.BLOG_URLS_DATE_FORMAT
            for date_part in date_parts:
                date_value = str(getattr(self.publish_date, date_part))
                if len(date_value) == 1:
                    date_value = "0%s" % date_value
                kwargs[date_part] = date_value
                if date_part == settings.BLOG_URLS_DATE_FORMAT:
                    break
        return reverse(url_name, kwargs=kwargs)
示例#29
0
class BlogPost(Displayable, MultiOwnable, RichText, AdminThumbMixin):
    """
    A blog post with multiple authors. Based on
    :class:`mezzanine.blog.models.BlogPost`.
    """

    # mezzanine blogpost has comments, categoriees, and ratings; do we
    # care about any of those?
    featured_image = FileField(
        verbose_name=_("Featured Image"),
        upload_to=upload_to("blog.BlogPost.featured_image", "blog"),
        help_text="Appears on the homepage carousel when post is featured.",
        format="Image",
        max_length=255,
        null=True,
        blank=True)
    related_posts = models.ManyToManyField("self",
                                           verbose_name=_("Related posts"),
                                           blank=True)
    tags = TaggableManager(blank=True)
    attachments = models.ManyToManyField(Attachment, blank=True)
    is_featured = models.BooleanField(
        verbose_name=_("Featured"),
        default=False,
        help_text="Feature the post in the carousel on the homepage.")

    admin_thumb_field = "featured_image"

    @property
    def short_title(self):
        '''shorter title with ellipsis'''
        return Truncator(self.title).chars(65)

    @property
    def short_description(self):
        '''shorter description with ellipsis'''
        return Truncator(self.description).chars(250)

    # custom manager for additioal queryset filters
    objects = BlogPostQuerySet.as_manager()

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

    def get_absolute_url(self):
        # we don't have to worry about the various url config options
        # that mezzanine has to support; just handle the url style we
        # want to use locally
        return reverse(
            'blog:detail',
            kwargs={
                'year': self.publish_date.year,
                # force two-digit month
                'month': '%02d' % self.publish_date.month,
                'day': '%02d' % self.publish_date.day,
                'slug': self.slug
            })
示例#30
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)
示例#31
0
 def __init__(self, *args, **kwargs):
     super(BlogPostAdminForm, self).__init__(*args, **kwargs)
     self.fields['featured_image'].label = _(u"Imagem destaque")
     self.fields['featured_image'].help_text = _(u"Imagem destaque da notícia, resolução mínima 460x260px ou proporcional.")
     self.fields['image_top'].directory = upload_to("blog.BlogPost.featured_image", "blog")