Пример #1
0
class VersatileImageWidgetTestModel(models.Model):
    """A model for testing VersatileImageField widgets."""

    image = VersatileImageField(upload_to='./', ppoi_field='ppoi')
    image_no_ppoi = VersatileImageField(upload_to='./')
    optional_image = VersatileImageField(upload_to='./', blank=True)
    optional_image_with_ppoi = VersatileImageField(
        upload_to='./', blank=True, ppoi_field='optional_image_with_ppoi_ppoi')
    optional_image_2 = VersatileImageField(upload_to='./')
    required_text_field = models.CharField(max_length=20)
    ppoi = PPOIField()
    optional_image_with_ppoi_ppoi = PPOIField()
Пример #2
0
class VersatileImageWidgetTestModel(models.Model):
    """A model for testing VersatileImageField widgets"""
    image = VersatileImageField(
        upload_to='./',
        ppoi_field='ppoi',
    )
    image_no_ppoi = VersatileImageField(upload_to='./', )
    optional_image = VersatileImageField(upload_to='./', blank=True)
    optional_image_with_ppoi = VersatileImageField(
        upload_to='./', blank=True, ppoi_field='optional_image_with_ppoi_ppoi')
    ppoi = PPOIField()
    optional_image_with_ppoi_ppoi = PPOIField()
Пример #3
0
class TownImage(TimeStampedModel):
    towns = models.ForeignKey(Town, related_name='images')
    image = VersatileImageField('Towns Image',
                                upload_to='uploaded_files/motels/',
                                ppoi_field='image_ppoi',
                                blank=True)
    image_ppoi = PPOIField()
Пример #4
0
class BirdProfile(models.Model):
    """ Bird profile information """
    bird = models.OneToOneField(Bird,
                                on_delete=models.CASCADE,
                                primary_key=True,
                                related_name='profile')

    # Metadata
    is_extended = models.BooleanField(default=True, editable=False)

    # Details
    is_featured = models.BooleanField(default=False)
    description = models.TextField(null=True, blank=True)
    sponsor_name = models.CharField(max_length=200, null=True, blank=True)
    sponsor_website = models.URLField(max_length=200, null=True, blank=True)

    # Image
    picture = VersatileImageField(upload_to=bird_directory_path,
                                  blank=True,
                                  null=True,
                                  ppoi_field='picture_ppoi')
    picture_ppoi = PPOIField()
    picture_attribution = models.CharField(max_length=200,
                                           null=True,
                                           blank=True)

    class Meta:
        ordering = [
            'bird',
        ]

    def __str__(self):
        return str(self.bird)
Пример #5
0
class Image(models.Model):
    date_created = models.DateTimeField(_("date created"), auto_now_add=True)
    title = models.CharField(_("title"), max_length=256, null=True, blank=True)
    image = VersatileImageField(
        _("image"),
        upload_to="carousel_image",
        width_field="width",
        height_field="height",
        ppoi_field="ppoi",
    )
    height = models.PositiveIntegerField(_("image height"),
                                         blank=True,
                                         null=True)
    width = models.PositiveIntegerField(_("image width"),
                                        blank=True,
                                        null=True)
    ppoi = PPOIField(_("image PPOI"))

    def save(self, *args, **kwargs):
        super().save(*args, **kwargs)

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

    def __str__(self):
        if self.title:
            return self.title
        else:
            return os.path.basename(self.image.name)
Пример #6
0
class RoomImage(TimeStampedModel):
    motels = models.ForeignKey('rooms.Room', related_name='images')
    image = VersatileImageField('Rooms Image',
                                upload_to='uploaded_files/Rooms/',
                                ppoi_field='image_ppoi',
                                blank=True)
    image_ppoi = PPOIField()
Пример #7
0
class ImageData(SortableModel):
    name = models.CharField(
        'Name',
        max_length=80
    )
    category = models.ForeignKey(
        Category, related_name='imagedata', on_delete=models.CASCADE, blank=True, null=True)
    image = VersatileImageField(
        upload_to='medias', ppoi_field='ppoi', blank=False)
    height = models.PositiveIntegerField(
        'Image Height',
        blank=True,
        null=True
    )
    width = models.PositiveIntegerField(
        'Image Width',
        blank=True,
        null=True
    )
    ppoi = PPOIField("Image PPOI")

    class Meta:
        ordering = ('sort_order', )
        verbose_name = 'Image Example'
        verbose_name_plural = 'Image Examples'

    def get_ordering_queryset(self):
        return ImageData.objects.all()
Пример #8
0
class Machine(models.Model):
    '''
    机器

    + ppoi字段没有实际意义,只是为了配合图片插件使用
    '''

    MACHINE_TYPES = ((0, 'TYPE 0'), (1, 'TYPE 1'), (2, 'TYPE 2'))

    no = models.CharField(null=True,
                          blank=True,
                          max_length=50,
                          verbose_name='编号')
    type = models.SmallIntegerField(null=True,
                                    blank=True,
                                    choices=MACHINE_TYPES,
                                    verbose_name='型号')
    ppoi = PPOIField(null=True, blank=True, verbose_name='关键点')
    qr = VersatileImageField(null=True,
                             blank=True,
                             upload_to='qr',
                             ppoi_field='ppoi',
                             verbose_name='二维码')

    class Meta:
        db_table = 'machine'
        verbose_name = '机器'
        verbose_name_plural = '机器'

    def __str__(self):
        return self.no
Пример #9
0
class MotelImage(TimeStampedModel):
    motels = models.ForeignKey('motels.Motel', related_name='images')
    image = VersatileImageField('Motels Image',
                                upload_to='uploaded_files/motels/',
                                ppoi_field='image_ppoi',
                                blank=True)
    image_ppoi = PPOIField()
Пример #10
0
class Object(models.Model):
    name = models.CharField(max_length=60, null=False, default="aaa")
    title = models.CharField(max_length=160, unique=True)
    slug = models.CharField(max_length=160, unique=True)
    description = models.TextField(default=None, null=True)
    category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name='category', blank=True)
    pub_date = models.DateField(auto_now=True)
    image = VersatileImageField('Path', upload_to=path_and_rename, ppoi_field='path_ppoi', blank=True)

    path_ppoi = PPOIField()

    def delete(self, *args, **kwargs):
        # You have to prepare what you need before delete the model
        storage, path = self.image.storage, self.image.path
        # Delete the model before the file
        super(Object, self).delete(*args, **kwargs)
        # Delete the file after the model
        storage.delete(path)

    def __str__(self):
        return self.name

    def facts(self):
        return Fact.objects.filter(object=self)

    def fact(self):
        return Fact.objects.filter(object=self).first()

    def get_absolute_url(self):
        return reverse('fact:object_show', kwargs={'slug': self.slug})
Пример #11
0
class PersonModel(AbsTime):
    SEX = ((
        '0',
        _('ქალი'),
    ), (
        '1',
        _('კაცი'),
    ))
    name = models.CharField(verbose_name=_('სახელი'),
                            max_length=40,
                            null=True,
                            blank=True)
    lastname = models.CharField(verbose_name=_('გვარი'),
                                max_length=40,
                                null=True,
                                blank=True)
    sex = models.CharField(verbose_name=_('სქესი'), max_length=1, choices=SEX)
    born_date = models.DateTimeField(_('დაბადების თარიღი'),
                                     null=True,
                                     blank=True)
    death_date = models.DateTimeField(_('გარდაცვალების თარიღი'),
                                      null=True,
                                      blank=True)
    wife = models.ForeignKey("PersonModel",
                             verbose_name=_('მეუღლე'),
                             blank=True,
                             null=True,
                             related_name='wife_set')
    parent = models.ForeignKey("PersonModel",
                               verbose_name=_('მშობელი'),
                               blank=True,
                               null=True,
                               related_name='children_set')
    dossier = RichTextUploadingField(verbose_name='დოსიე',
                                     blank=True,
                                     null=True)
    image = VersatileImageField(verbose_name='სურათი',
                                blank=True,
                                null=True,
                                upload_to='prof_imgs/',
                                ppoi_field='ppoi')
    ppoi = PPOIField('სურათი')

    def get_full_name(self):
        return self.name + ' ' + self.lastname

    def __str__(self):
        if self.parent:
            return self.parent.get_full_name() + '>' + self.get_full_name()
        return self.get_full_name()

    def have_children(self):
        return self.children_set.count() > 0 and self.sex == '1'

    def get_children(self):
        return self.children_set.all()

    class Meta:
        verbose_name = 'პიროვნება'
        verbose_name_plural = 'პიროვნებები'
Пример #12
0
class Scene(models.Model):
    name = models.CharField(max_length=128, )
    image = VersatileImageField(
        upload_to='scenes',
        ppoi_field='ppoi',
        blank=False,
    )
    ppoi = PPOIField()
    alt = models.CharField(
        max_length=128,
        blank=True,
    )
    is_active = models.BooleanField(default=False, )
    active_on = models.DateField(
        blank=True,
        null=True,
    )
    active_until = models.DateField(
        blank=True,
        null=True,
    )

    class Meta:
        ordering = ('name', )
        permissions = ((
            'manage_scenes',
            pgettext_lazy('Permission description', 'Manage scenes.'),
        ), )

    def __str__(self):
        return self.name
Пример #13
0
class ImageMixin(models.Model):
    image_file = VersatileImageField(
        _('image'),
        upload_to=UPLOAD_TO,
        width_field='image_width',
        height_field='image_height',
        ppoi_field='image_ppoi',
        blank=True,
    )
    image_width = models.PositiveIntegerField(
        _('image width'),
        blank=True,
        null=True,
        editable=False,
    )
    image_height = models.PositiveIntegerField(
        _('image height'),
        blank=True,
        null=True,
        editable=False,
    )
    image_ppoi = PPOIField(_('primary point of interest'))
    image_alt_text = models.CharField(
        _('alternative text'),
        max_length=1000,
        blank=True,
    )

    class Meta:
        abstract = True

    def accept_file(self, value):
        if not upload_is_image(value):
            raise InvalidFileError()
        self.image_file = value
Пример #14
0
class ProductImage(models.Model):
    product = models.ForeignKey(Product, related_name='images')
    image = VersatileImageField(upload_to='products',
                                ppoi_field='ppoi',
                                blank=False)
    ppoi = PPOIField()
    alt = models.CharField(pgettext_lazy('Product image field',
                                         'short description'),
                           max_length=128,
                           blank=True)
    order = models.PositiveIntegerField(editable=False)

    objects = ImageManager()

    class Meta:
        ordering = ['order']
        app_label = 'product'

    def get_ordering_queryset(self):
        return self.product.images.all()

    def save(self, *args, **kwargs):
        if self.order is None:
            qs = self.get_ordering_queryset()
            existing_max = qs.aggregate(Max('order'))
            existing_max = existing_max.get('order__max')
            self.order = 0 if existing_max is None else existing_max + 1
        super(ProductImage, self).save(*args, **kwargs)

    def delete(self, *args, **kwargs):
        qs = self.get_ordering_queryset()
        qs.filter(order__gt=self.order).update(order=F('order') - 1)
        super(ProductImage, self).delete(*args, **kwargs)
Пример #15
0
class Page(models.Model):
    PAGE_STATUS_CHOICE = (
        ('1', 'Published'),
        ('0', 'UnPublished'),
    )
    page_name = models.CharField(max_length=255)
    page_body = MartorField(default='')
    page_author = models.ForeignKey(User, on_delete=models.CASCADE)
    page_date = models.DateTimeField('page date')
    page_status = models.CharField(max_length=1, choices=PAGE_STATUS_CHOICE, default='1')
    page_header = VersatileImageField(
        'Header',
        upload_to='page',
        default='',
        blank=True,
        width_field='page_header_image_width',
        height_field='page_header_image_height',
        ppoi_field='page_header_ppoi'
    )
    page_header_image_height = models.PositiveIntegerField(
        'Image Height',
        blank=True,
        null=True
    )
    page_header_image_width = models.PositiveIntegerField(
        'Image Width',
        blank=True,
        null=True
    )
    page_header_ppoi = PPOIField(
        'Image PPOI'
    )

    def __str__(self):
        return self.page_name
Пример #16
0
class Image(models.Model):
    """
    Image plugin
    """
    image = VersatileImageField(
        _('image'),
        upload_to='images/%Y/%m',
        width_field='width',
        height_field='height',
        ppoi_field='ppoi',
    )
    width = models.PositiveIntegerField(
        _('image width'),
        blank=True,
        null=True,
        editable=False,
    )
    height = models.PositiveIntegerField(
        _('image height'),
        blank=True,
        null=True,
        editable=False,
    )
    ppoi = PPOIField(_('primary point of interest'))

    class Meta:
        abstract = True
        verbose_name = _('image')
        verbose_name_plural = _('images')

    def __str__(self):
        return self.image.name
Пример #17
0
class Photo(models.Model):

    image = VersatileImageField(upload_to='photos',
                                ppoi_field='ppoi',
                                blank=False)
    ppoi = PPOIField()
    alt = models.CharField(max_length=128, blank=True)
Пример #18
0
class InPageImages(models.Model):
    page = models.ForeignKey("Page",
                             verbose_name='Страница',
                             on_delete=models.CASCADE,
                             null=True)
    ourWorks = models.ForeignKey("OurWorks",
                                 verbose_name='Наши работы',
                                 on_delete=models.CASCADE,
                                 null=True)
    imageName = models.CharField('Название',
                                 max_length=50,
                                 null=True,
                                 blank=True)
    pageImage = VersatileImageField(verbose_name='Image',
                                    ppoi_field='ppoi',
                                    blank=False,
                                    null=True)
    ppoi = PPOIField()

    def __str__(self):
        return self.imageName

    class Meta:
        verbose_name_plural = 'Изображения на странице'
        verbose_name = 'Изображение'
Пример #19
0
class Image(models.Model):
    """
    Image plugin
    """

    image = VersatileImageField(
        _("image"),
        upload_to="images/%Y/%m",
        width_field="width",
        height_field="height",
        ppoi_field="ppoi",
    )
    width = models.PositiveIntegerField(_("image width"),
                                        blank=True,
                                        null=True,
                                        editable=False)
    height = models.PositiveIntegerField(_("image height"),
                                         blank=True,
                                         null=True,
                                         editable=False)
    ppoi = PPOIField(_("primary point of interest"))

    class Meta:
        abstract = True
        verbose_name = _("image")
        verbose_name_plural = _("images")

    def __str__(self):
        return self.image.name
Пример #20
0
class Slide(SortableModel):
    slider = models.ForeignKey(
        Slider,
        related_name='slides',
        related_query_name='slide',
        on_delete=models.CASCADE,
    )

    image = VersatileImageField(
        upload_to='slides',
        ppoi_field='ppoi',
        blank=False,
    )

    ppoi = PPOIField()

    alt = models.CharField(
        max_length=128,
        blank=True,
    )

    class Meta:
        ordering = ('sort_order', )

    def __str__(self):
        return f"Slide {self.sort_order + 1}"

    def get_ordering_queryset(self):
        return self.slider.slides.all()
Пример #21
0
class ProductImage(models.Model):
    product = models.ForeignKey(Product,
                                related_name='images',
                                on_delete=models.CASCADE)
    image = VersatileImageField(upload_to='products',
                                ppoi_field='ppoi',
                                blank=False)
    ppoi = PPOIField()
    alt = models.CharField(max_length=128, blank=True)
    order = models.PositiveIntegerField(editable=False)

    class Meta:
        ordering = ('order', )
        app_label = 'product'

    @shared_task
    def create_product_thumbnails(self):
        ProductWarmer(items=[self])()

    def get_ordering_queryset(self):
        return self.product.images.all()

    def save(self, *args, **kwargs):
        if self.order is None:
            qs = self.get_ordering_queryset()
            existing_max = qs.aggregate(Max('order'))
            existing_max = existing_max.get('order__max')
            self.order = 0 if existing_max is None else existing_max + 1
        super().save(*args, **kwargs)

    def delete(self, *args, **kwargs):
        qs = self.get_ordering_queryset()
        qs.filter(order__gt=self.order).update(order=F('order') - 1)
        super().delete(*args, **kwargs)
Пример #22
0
class BirdExtended(models.Model):
    """ Extended bird information, designed to be edited on Django """
    bird = models.OneToOneField(Bird,
                                on_delete=models.CASCADE,
                                primary_key=True,
                                related_name='bird_extended')

    is_extended = models.BooleanField(default=True, editable=False)

    is_featured = models.BooleanField(default=False)
    description = models.TextField(null=True, blank=True)
    sponsor_name = models.CharField(max_length=200, null=True, blank=True)
    sponsor_website = models.URLField(max_length=200, null=True, blank=True)

    profile_picture = VersatileImageField(upload_to=bird_directory_path,
                                          blank=True,
                                          null=True,
                                          ppoi_field='profile_picture_ppoi')
    profile_picture_ppoi = PPOIField()
    profile_picture_attribution = models.CharField(max_length=200,
                                                   null=True,
                                                   blank=True)

    class Meta:
        ordering = ['bird']
        verbose_name = 'Extended Bird'

    def __str__(self):
        return str(self.bird)
Пример #23
0
class Chapas(models.Model):
    name = models.CharField("Name", max_length=50)
    diameter = models.PositiveSmallIntegerField(
        "Diameter",
        validators=[
            MaxValueValidator(816),
        ],
        help_text='value in pixel, max. 816',
    )
    image = VersatileImageField(
        upload_to="img",
        ppoi_field="ppoi",
        blank=False,
        help_text='only image with extension .jpeg o .jpg',
        validators=[
            validate_extension,
        ],
    )
    ppoi = PPOIField()

    class Meta:
        verbose_name = "Button Badge"
        verbose_name_plural = "Buttons Badges"

    def __str__(self):
        return self.name
Пример #24
0
class ProductMedia(SortableModel):
    product = models.ForeignKey(Product,
                                related_name="media",
                                on_delete=models.SET_NULL,
                                null=True,
                                blank=True)
    image = VersatileImageField(upload_to="products",
                                ppoi_field="ppoi",
                                blank=True,
                                null=True)
    ppoi = PPOIField()
    alt = models.CharField(max_length=128, blank=True)
    type = models.CharField(
        max_length=32,
        choices=ProductMediaTypes.CHOICES,
        default=ProductMediaTypes.IMAGE,
    )
    external_url = models.CharField(max_length=256, blank=True, null=True)
    oembed_data = JSONField(blank=True, default=dict)
    to_remove = models.BooleanField(default=False)

    class Meta:
        ordering = ("sort_order", "pk")
        app_label = "product"

    def get_ordering_queryset(self):
        return self.product.media.all()
Пример #25
0
class Card(TimeStampedUUIDModel):
    title = models.CharField(
        max_length=120, null=False, blank=False, default="", verbose_name="Title",
    )
    description = models.CharField(
        max_length=512, null=False, blank=True, default="", verbose_name="Description",
    )
    link = models.URLField(
        max_length=200, null=False, blank=True, default="", verbose_name="Link",
    )
    created_by = models.ForeignKey(
        settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="cards"
    )
    wishlist = models.ForeignKey(
        "wishlists.Wishlist", on_delete=models.CASCADE, related_name="cards"
    )
    photo = VersatileImageField(
        upload_to=upload_to, blank=True, null=True, ppoi_field="photo_poi", verbose_name="Photo",
    )
    photo_poi = PPOIField(verbose_name="Photo's Point of Interest")

    class Meta:
        verbose_name = "card"
        verbose_name_plural = "cards"
        ordering = ("-created_at",)
        db_table = 'card'

    def __str__(self):
        return f"{self.title}"
Пример #26
0
class Product(models.Model):
    name = models.CharField('Название', max_length=150)
    price = models.FloatField('Цена', blank=True, null=True)
    title = models.CharField("СЕО  Заголовок",
                             max_length=165,
                             null=True,
                             blank=True,
                             default='')
    seoDescription = models.TextField(
        'СЕО описание страницы с товаром(скрытое)', blank=True, null=True)
    seoKeywords = models.TextField('СЕО ключевые фразы', blank=True, null=True)
    description = RichTextField('Описание на странице', null=True, blank=True)
    position = models.FloatField('Позиция', blank=True, null=True, default=0)
    discount = models.BooleanField('Скидка', blank=True, default=False)
    nds = models.BooleanField('НДС', blank=True, default=False)
    sertificate = models.BooleanField('Сертификат', blank=True, default=False)
    category = models.ForeignKey(Category,
                                 verbose_name="Категория",
                                 on_delete=models.CASCADE)

    def get_absolute_url(self):
        return f"/{self.category.get_absolute_url() + self.slug}"

    def seoInfo(self):
        if len(self.seoDescription) == 0 and self.title == None:
            return 'Отсутствует'
        elif len(self.seoDescription) != 0 and self.title != None:
            return 'Настроено'
        else:
            return 'Не полное'
        return 'Ошибка'

    seoInfo.short_description = 'SEO товара'

    # VersatileImageField
    productImage = VersatileImageField(
        verbose_name='Photo',
        ppoi_field='ppoi',
        blank=True,
    )
    ppoi = PPOIField()

    # UUSLUG
    slug = models.CharField(max_length=200, null=True)

    def __unicode__(self):
        return self.name

    def save(self, *args, **kwargs):
        self.slug = uuslug(self.name, instance=self)
        super(Product, self).save(*args, **kwargs)

    def __str__(self):
        return f'{self.name}'

    class Meta:
        verbose_name_plural = 'Товары'
        verbose_name = 'Товар'
        ordering = ['-position']
Пример #27
0
class Country(SoftDeletionModel):
    name = models.CharField(max_length=255)
    interest_point = PPOIField()
    flag = VersatileImageField(
        _('Flag'),
        upload_to='countries/flags/',
        ppoi_field='interest_point',
    )
Пример #28
0
class Photos(models.Model):
    product = models.ForeignKey(ProductCard,
                                on_delete=models.CASCADE,
                                null=True)
    photo = VersatileImageField(verbose_name='Photo',
                                ppoi_field='ppoi',
                                blank=False)
    ppoi = PPOIField()
Пример #29
0
class Post(PublishedModel):
    title = models.CharField(max_length=100, help_text="100 characters or fewer.")
    slug = models.SlugField(unique=True, help_text="Changing this value after initial creation will break existing "
                                                   "post URLs. Must be unique.")
    tags = TaggableManager(blank=True)

    allow_comments = models.BooleanField(default=True)

    author = models.CharField(max_length=50, help_text="50 characters or fewer.")
    created = models.DateTimeField(auto_now_add=True, verbose_name="date created")
    modified = models.DateTimeField(auto_now=True, verbose_name="date modified")

    image = VersatileImageField(upload_to='blog', blank=True, null=True, ppoi_field='image_ppoi')
    image_ppoi = PPOIField()

    description = models.TextField(max_length=140, blank=True, help_text="140 characters or fewer.")

    text = MarkdownField(rendered_field='text_rendered', validator=VALIDATOR_CLASSY)
    text_rendered = RenderedMarkdownField()

    class Meta:
        ordering = ['-created']

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse('blog:detail', kwargs={'slug': self.slug})

    @cached_property
    def structured_data(self):
        url = settings.SITE_URL + self.get_absolute_url()
        data = {
            '@type': 'BlogPosting',
            'headline': self.title,
            'description': self.description or Truncator(strip_tags(self.text_rendered)).chars(200),
            'author': {
                '@type': 'Person',
                'name': self.author
            },
            'datePublished': self.created.strftime('%Y-%m-%d'),
            'dateModified': self.modified.strftime('%Y-%m-%d'),
            'publisher': None,
            'url': url,
            'mainEntityOfPage': {
                '@type': 'WebPage',
                '@id': url
            },
        }
        if self.image:
            data['image'] = {
                '@type': 'ImageObject',
                'url': settings.SITE_URL + self.image.url,
                'height': self.image.height,
                'width': self.image.width
            }

        return data
Пример #30
0
class Image(models.Model):
    name = models.CharField(max_length=255)
    image = VersatileImageField('Image',
                                upload_to='images/',
                                ppoi_field='image_ppoi')
    image_ppoi = PPOIField()

    def __str__(self):
        return self.name