Ejemplo n.º 1
0
class Product(models.Model):
    name = models.CharField(max_length=100)
    img = fields.ImageField(upload_to='pics',
                            dependencies=[
                                FileDependency(attname='img=',
                                               processor=ImageProcessor(
                                                   format='JPEG',
                                                   scale={
                                                       'max_width': 500,
                                                       'max_height': 500
                                                   })),
                            ])
    img = fields.ImageField(upload_to='pics')

    max_price = models.IntegerField()
    min_price = models.IntegerField()
    Price_display = models.BooleanField(default=False)
    specification = RichTextField(blank=True, null=True)
    detail_img = fields.ImageField(upload_to='pics',
                                   dependencies=[
                                       FileDependency(attname='img=',
                                                      processor=ImageProcessor(
                                                          format='JPEG',
                                                          scale={
                                                              'max_width': 500,
                                                              'max_height': 500
                                                          })),
                                   ])
    detail_img = fields.ImageField(upload_to='pics')
Ejemplo n.º 2
0
class UserProfile(models.Model):

    user = models.OneToOneField(settings.AUTH_USER_MODEL,
                                related_name='profile',
                                on_delete=models.CASCADE)
    avatar = fields.ImageField(
        upload_to=avatar_image_upload_path,
        blank=True,
        default='static/user-bg.jpg',
        dependencies=[
            FileDependency(processor=ImageProcessor(format='JPEG',
                                                    scale={
                                                        'max_width': 150,
                                                        'max_height': 150
                                                    })),
        ])

    about = models.TextField(blank=True)
    # user_type = models.CharField(max_length=1, choices=USER_TYPES, default='b')

    last_updated = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.user.username

    def save(self, *args, **kwargs):
        if self.id and self.avatar:
            current_avatar = UserProfile.objects.get(pk=self.id).avatar
            if current_avatar != self.avatar:
                current_avatar.delete()
        super(UserProfile, self).save(*args, **kwargs)

    def get_absolute_url(self):
        target = reverse('authapp:profile', args=[self.user.username])
        return target
Ejemplo n.º 3
0
class Post(models.Model):
    title = models.CharField(max_length=100)
    date_pub = models.DateField(auto_now_add=True)
    body = models.TextField()
    created_by = models.ForeignKey(User,
                                   on_delete=models.CASCADE,
                                   related_name='create_posts')
    image = fields.ImageField(blank=True,
                              upload_to='images',
                              dependencies=[
                                  FileDependency(attname='image_jpeg',
                                                 processor=ImageProcessor(
                                                     format='JPEG',
                                                     scale={
                                                         'max_width': 600,
                                                         'max_height': 600
                                                     })),
                              ])
    tag = models.CharField(max_length=100,
                           verbose_name='Tag',
                           blank=True,
                           null=True)

    def __str__(self):
        return self.title

    def get_absolute_url(
        self
    ):  # - генерация уролов для сопостовления дополнительных элементов в урле urls.py
        return reverse('post_detail', kwargs={'pk': self.id})

    class Meta:
        verbose_name = 'Пост'
        verbose_name_plural = 'Посты'
Ejemplo n.º 4
0
class Product(models.Model):
    category = models.ForeignKey(Category,
                                 related_name='products',
                                 on_delete=models.CASCADE)
    name = models.CharField(max_length=200, db_index=True)
    slug = models.SlugField(max_length=200, db_index=True)
    image = fields.ImageField(
        upload_to='products/%Y/%m/%d',
        blank=True,
        dependencies=[
            FileDependency(processor=ImageProcessor(format='JPEG',
                                                    scale={
                                                        'max_width': 300,
                                                        'max_height': 300
                                                    }))
        ])
    price = models.DecimalField(max_digits=10, decimal_places=2)
    description = models.TextField(blank=True)
    available = models.BooleanField(default=True)
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    class Meta:
        ordering = ('name', )
        index_together = (('id', 'slug'), )

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return reverse('shop:product_detail', args=[self.id, self.slug])
class UserProfile(models.Model):
    user = models.OneToOneField(settings.AUTH_USER_MODEL)
    firstname = models.CharField(max_length=40, default='', blank=True)
    lastname = models.CharField(max_length=40, default='', blank=True)
    bio = models.TextField(blank=True, default='')
    avatar = fields.ImageField(blank=True,
                               null=True,
                               upload_to='avatar_photos/',
                               dependencies=[
                                   FileDependency(attname='avatar_png',
                                                  processor=ImageProcessor(
                                                      format='PNG',
                                                      scale={
                                                          'max_width': 150,
                                                          'max_height': 150
                                                      })),
                               ])
    skills = models.ManyToManyField('projects.Skill',
                                    blank=True,
                                    default='',
                                    related_name='skills')

    def get_absolute_url(self):
        return reverse("accounts:profile", {'username': self.user.username})

    def __str__(self):
        return '{} {}'.format(self.firstname, self.lastname)
Ejemplo n.º 6
0
def image_attribute_resize(attr, width, height):
    processor = ImageProcessor(format="JPEG",
                               scale={
                                   "max_width": width,
                                   "max_height": height
                               }
                               )

    return FileDependency(attname=attr, processor=processor)
Ejemplo n.º 7
0
 def test_dimensions_checking(self):
     p = ImageProcessor()
     # ones that totally don't make sense
     self.assertRaises(AssertionError,
                       p._check_scale_params,
                       width=100,
                       min_width=50)
     self.assertRaises(AssertionError,
                       p._check_scale_params,
                       width=100,
                       max_width=50)
     self.assertRaises(AssertionError,
                       p._check_scale_params,
                       height=50,
                       min_height=50)
     self.assertRaises(AssertionError,
                       p._check_scale_params,
                       height=50,
                       max_height=50)
     self.assertRaises(AssertionError,
                       p._check_scale_params,
                       min_width=100,
                       max_width=50)
     self.assertRaises(AssertionError,
                       p._check_scale_params,
                       min_height=100,
                       max_height=50)
     # ones that make no sense with preserve=True
     self.assertRaises(AssertionError,
                       p._check_scale_params,
                       width=100,
                       height=50)
     self.assertRaises(AssertionError,
                       p._check_scale_params,
                       width=100,
                       min_height=50)
     self.assertRaises(AssertionError,
                       p._check_scale_params,
                       width=100,
                       max_height=50)
     self.assertRaises(AssertionError,
                       p._check_scale_params,
                       height=50,
                       min_width=50)
     self.assertRaises(AssertionError,
                       p._check_scale_params,
                       height=50,
                       min_height=50)
     self.assertRaises(AssertionError,
                       p._check_scale_params,
                       min_width=100,
                       max_height=50)
     self.assertRaises(AssertionError,
                       p._check_scale_params,
                       max_width=100,
                       min_height=50)
Ejemplo n.º 8
0
class Category(models.Model):
    title = models.CharField(max_length=200)
    image = fields.ImageField(upload_to='category',blank=True, dependencies=[
        FileDependency(attname='avatar_jpeg', processor=ImageProcessor(
            format='JPEG', scale={'max_width': 500, 'max_height': 600})),
    ])
    description = models.TextField(blank=True)
    typ= models.CharField(max_length=100,choices=categorychoices,default="Comedy")
    def __str__(self):
        return self.title
 def test_misc(self):
     f1 = ImageFormat('BMP', ext='dib')
     f2 = ImageFormat('BMP')
     f3 = ImageFormat('PSD')
     self.assertEqual(f1, f2)
     self.assertEqual(f1, 'BMP')
     self.assertNotEqual(f1, f3)
     self.assertTrue(f1.can_read)
     self.assertEqual(f1.get_ext(), 'dib')
     self.assertEqual(f2.get_ext(), 'bmp')
     self.assertEqual(f1.get_exts(), 'bmp,dib')
     self.assertEqual(f1.get_mode(), 'RGB')
     self.assertEqual(f1.get_mode(old_mode='non_existent'), 'RGB')
     self.assertEqual(f1.get_mode(old_mode='CMYK'), 'RGB')
     self.assertEqual(f1.get_mode(old_mode='LA'), 'P')
     p = ImageProcessor(format=f3)
     self.assertRaises(AssertionError, p.check_params)
     self.assertEqual(set(p.supported_formats.input_exts.split(',')),
                      set('sgi,pcx,xpm,tif,tiff,jpg,jpe,jpeg,jfif,xbm,gif,bmp,dib,tga,'
                      'tpic,im,psd,ppm,pgm,pbm,png'.split(',')))
     p = ImageProcessor()
     self.assertIsNone(p.get_ext())
     self.assertEquals(p.get_ext(format=ImageFormat('TIFF', ext='')), '')
Ejemplo n.º 10
0
class Vision_Mission(models.Model):
    scroll_text = models.CharField(max_length=100, blank=True)
    vision_name = models.CharField(max_length=100, blank=True)
    vision_subhead = models.CharField(max_length=300, blank=True)
    vision_parallax_img = fields.ImageField(
        upload_to='pics',
        dependencies=[
            FileDependency(attname='img',
                           processor=ImageProcessor(format='JPEG',
                                                    scale={
                                                        'max_width': 1920,
                                                        'max_height': 700
                                                    })),
        ])
    vision_parallax_img = fields.ImageField(upload_to='pics')
Ejemplo n.º 11
0
class Upload_video(models.Model):
    video_name = models.CharField(max_length=100)
    video_thumbnail = fields.ImageField(
        upload_to='pics',
        dependencies=[
            FileDependency(attname='video_thumbnail',
                           processor=ImageProcessor(format='JPEG',
                                                    scale={
                                                        'max_width': 500,
                                                        'max_height': 500
                                                    })),
        ])
    video_thumbnail = fields.ImageField(upload_to='pics')
    videofile = models.FileField(upload_to='videos', null=True)
    video_description = models.TextField()
Ejemplo n.º 12
0
class Banner(models.Model):
    img = fields.ImageField(upload_to='pics',
                            dependencies=[
                                FileDependency(attname='img',
                                               processor=ImageProcessor(
                                                   format='JPEG',
                                                   scale={
                                                       'max_width': 1920,
                                                       'max_height': 700
                                                   })),
                            ])
    img = fields.ImageField(upload_to='pics')
    name = models.CharField(max_length=100)

    head = models.CharField(max_length=400)
    subhead = models.TextField()
    button_bool = models.BooleanField(default=False)
Ejemplo n.º 13
0
class ProductPhotos(models.Model):
    image = fields.ImageField(
        upload_to=product_directory_path,
        dependencies=[
            FileDependency(processor=ImageProcessor(format='JPEG',
                                                    scale={
                                                        'max_width': 800,
                                                        'max_height': 800
                                                    }))
        ],
    )
    alt = models.CharField(
        null=True,
        blank=True,
        max_length=200,
        help_text='Θα δημιουργηθεί αυτόματα εάν δεν συμπληρωθεί')
    title = models.CharField(
        null=True,
        blank=True,
        max_length=100,
        help_text='Θα δημιουργηθεί αυτόματα εάν δεν συμπληρωθεί')
    product = models.ForeignKey(Product)
    active = models.BooleanField(default=True)
    is_primary = models.BooleanField(default=False,
                                     verbose_name='Αρχική Εικόνα')
    is_back = models.BooleanField(default=False, verbose_name='Δεύτερη Εικόνα')

    class Meta:
        verbose_name_plural = 'Gallery'

    def __str__(self):
        return self.title

    def image_tag(self):
        return mark_safe('<img width="150px" height="150px" src="%s%s" />' %
                         (MEDIAURL, self.image))

    image_tag.short_description = 'Εικονα'

    def image_tag_tiny(self):
        return mark_safe('<img width="150px" height="150px" src="%s%s" />' %
                         (MEDIAURL, self.image))

    image_tag_tiny.short_description = 'Εικόνα'
Ejemplo n.º 14
0
class SubCategory(models.Model):
    title = models.CharField(max_length=200)
    image = fields.ImageField(upload_to='subcategory',
                              blank=True,
                              dependencies=[
                                  FileDependency(attname='avatar_jpeg',
                                                 processor=ImageProcessor(
                                                     format='JPEG',
                                                     scale={
                                                         'max_width': 500,
                                                         'max_height': 600
                                                     })),
                              ])
    category = models.ForeignKey(Category, on_delete=models.CASCADE)
    description = models.TextField(blank=True)
    seasons = models.IntegerField(default=1)

    def __str__(self):
        return self.title
Ejemplo n.º 15
0
class Misc(models.Model):
    created = models.DateTimeField(auto_now_add=True)
    name = models.CharField(max_length=100, blank=True, default='')
    orig_image = fields.ImageField(upload_to='static/',
                                   dependencies=[
                                       FileDependency(attname='image',
                                                      upload_to='static/misc/',
                                                      processor=ImageProcessor(
                                                          format='JPEG',
                                                          scale={
                                                              'max_width': 900,
                                                              'max_height': 900
                                                          })),
                                   ])
    image = models.ImageField(upload_to='static/misc/',
                              null=True,
                              blank=True,
                              editable=False)

    def __str__(self):
        return self.name
Ejemplo n.º 16
0
class Head_footer(models.Model):
    logo = models.ImageField(upload_to='pics')
    logo_name_display = models.CharField(max_length=50)
    Logo_img_display = models.BooleanField(default=False)
    prod_head = models.CharField(max_length=300, blank=True)
    video_head = models.CharField(max_length=300, blank=True)
    contact_head = models.CharField(max_length=300, blank=True)
    favicon = models.FileField(upload_to='svg')
    my_email = models.CharField(max_length=100)
    phn_number = models.CharField(max_length=50, blank=True)
    address = models.TextField()
    contact_parallax_img = fields.ImageField(
        upload_to='pics',
        dependencies=[
            FileDependency(attname='img',
                           processor=ImageProcessor(format='JPEG',
                                                    scale={
                                                        'max_width': 1920,
                                                        'max_height': 700
                                                    })),
        ])
    contact_parallax_img = fields.ImageField(upload_to='pics')
    facebook_link = models.CharField(max_length=100, blank=True)
Ejemplo n.º 17
0
class Profile(models.Model):
    user = models.OneToOneField(User,
                                related_name='user',
                                blank=False,
                                unique=True,
                                on_delete=models.CASCADE)
    first_name = models.CharField('Имя', max_length=100, blank=True)
    second_name = models.CharField('Фамилия', max_length=100, blank=True)
    middle_name = models.CharField('Отчество', max_length=100, blank=True)
    email = models.EmailField('Email', blank=True)
    phone = models.CharField('Телефон', max_length=100, blank=True)
    description = models.CharField('О себе', max_length=100, blank=True)
    avatar = fields.ImageField(
        'Фото',
        dependencies=[
            FileDependency(processor=ImageProcessor(format='JPEG',
                                                    scale={
                                                        'max_width': 200,
                                                        'max_height': 240
                                                    }))
        ],
        upload_to='',
        blank=True)
Ejemplo n.º 18
0
 def test_misc(self):
     f1 = ImageFormat('BMP', ext='dib')
     f2 = ImageFormat('BMP')
     f3 = ImageFormat('PSD')
     self.assertEqual(f1, f2)
     self.assertEqual(f1, 'BMP')
     self.assertNotEqual(f1, f3)
     self.assertTrue(f1.can_read)
     self.assertEqual(f1.get_ext(), 'dib')
     self.assertEqual(f2.get_ext(), 'bmp')
     self.assertEqual(f1.get_exts(), 'bmp,dib')
     self.assertEqual(f1.get_mode(), 'RGB')
     self.assertEqual(f1.get_mode(old_mode='non_existent'), 'RGB')
     self.assertEqual(f1.get_mode(old_mode='CMYK'), 'RGB')
     self.assertEqual(f1.get_mode(old_mode='LA'), 'P')
     p = ImageProcessor(format=f3)
     self.assertRaises(AssertionError, p.check_params)
     self.assertEqual(
         set(p.supported_formats.input_exts.split(',')),
         set('sgi,pcx,xpm,tif,tiff,jpg,jpe,jpeg,jfif,xbm,gif,bmp,dib,tga,'
             'tpic,im,psd,ppm,pgm,pbm,png'.split(',')))
     p = ImageProcessor()
     self.assertIsNone(p.get_ext())
     self.assertEquals(p.get_ext(format=ImageFormat('TIFF', ext='')), '')
Ejemplo n.º 19
0
 def test_dimensions_scaling(self):
     p = ImageProcessor()
     # scaling up: hard set dims
     self.assertEqual(p.get_dimensions(200, 100, width=100), (100, 50))
     self.assertEqual(p.get_dimensions(200, 100, height=200), (400, 200))
     # scaling up: single
     self.assertEqual(p.get_dimensions(200, 100, min_width=300), (300, 150))
     self.assertEqual(p.get_dimensions(200, 100, min_height=200), (400, 200))
     # scaling up: both
     self.assertEqual(p.get_dimensions(200, 100, min_width=300, min_height=200), (400, 200))
     self.assertEqual(p.get_dimensions(200, 100, min_width=600, min_height=200), (600, 300))
     # scaling up: mixing
     self.assertEqual(p.get_dimensions(200, 100, min_width=300, max_width=400), (300, 150))
     self.assertEqual(p.get_dimensions(200, 100, min_height=200, max_height=400), (400, 200))
     # scaling down: single
     self.assertEqual(p.get_dimensions(200, 100, max_width=50), (50, 25))
     self.assertEqual(p.get_dimensions(200, 100, max_height=25), (50, 25))
     # scaling down: both
     self.assertEqual(p.get_dimensions(200, 100, max_width=100, max_height=75), (100, 50))
     self.assertEqual(p.get_dimensions(200, 100, max_width=150, max_height=50), (100, 50))
     # scaling down: mixin
     self.assertEqual(p.get_dimensions(200, 100, min_width=50, max_width=100), (100, 50))
     self.assertEqual(p.get_dimensions(200, 100, min_height=10, max_height=50), (100, 50))
     # no scaling: single
     self.assertEqual(p.get_dimensions(200, 100, min_width=100), (200, 100))
     self.assertEqual(p.get_dimensions(200, 100, min_height=50), (200, 100))
     self.assertEqual(p.get_dimensions(200, 100, max_width=300), (200, 100))
     self.assertEqual(p.get_dimensions(200, 100, max_height=150), (200, 100))
     # no scaling: both
     self.assertEqual(p.get_dimensions(200, 100, min_width=50, min_height=50), (200, 100))
     self.assertEqual(p.get_dimensions(200, 100, max_width=400, max_height=200), (200, 100))
     # without preserving ratio
     self.assertEqual(p.get_dimensions(
         200, 100, min_width=50, max_width=100, min_height=2000, 
         max_height=2001, preserve=False), (100, 2000))
     self.assertEqual(p.get_dimensions(
         200, 100, height=500, min_width=300, max_width=400, preserve=False), (300, 500))
Ejemplo n.º 20
0
class AboutImg(models.Model):
    title = models.CharField('Titel',max_length=300)
    description = models.TextField('Beschreibung', blank=True, null=True)
    bild = fields.ImageField(upload_to='photo/%m/',blank=True, null=True , dependencies=[FileDependency(attname='bild_png', processor=ImageProcessor(format='PNG', scale={'max_width': 340, 'max_height': 260})),FileDependency(attname='bild_webp', processor=ImageProcessor(format='WEBP', scale={'max_width': 340, 'max_height': 260}))])
    bild_png = fields.ImageField(upload_to='',blank=True, null=True)
    bild_webp = fields.ImageField(upload_to='',blank=True, null=True)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name_plural = "Überschriften und Hauptfotos"
        verbose_name = "Überschrift und Hauptfoto"



    def png_image_url(self):
        if self.bild_png:
            png_image_url = self.bild_png.url
        else:
            png_image_url = settings.STATIC_URL + 'base_app/img/kein_bild_vorhanden.png'
        return png_image_url

    def webp_image_url(self):
        if self.bild_webp:
            webp_image_url = self.bild_webp.url
        else:
            webp_image_url = settings.STATIC_URL + 'base_app/img/kein_bild_vorhanden.webp'
        return webp_image_url

    def image_gesamt_tag(self):
        png_image_url = self.png_image_url()
        webp_image_url = self.webp_image_url()
        return format_html('<img src="{}" onerror="{}{}{}" alt="Über Rado-Montage" class="img-responsive" />'.format(webp_image_url,"this.src='",png_image_url,"'"))

    image_gesamt_tag.short_description = 'Bild gesamttag'

    def image_tag(self):
        if self.bild_png:
            return format_html('<img src="{}" width="150" height="150" />'.format(self.bild_png.url))
        else:
            return format_html('<img src="{}" width="150" height="150" />'.format(settings.STATIC_URL + 'base_app/img/kein_bild_vorhanden.png'))

    image_tag.short_description = 'Bild'

    def image_tag_webp(self):
        if self.bild_webp:
            return format_html('<img src="{}" width="150" height="150" />'.format(self.bild_webp.url))
        else:
            return format_html('<img src="{}" width="150" height="150" />'.format(settings.STATIC_URL + 'base_app/img/kein_bild_vorhanden.webp'))
    image_tag_webp.short_description = 'Bild in .webp Format'

    def get_absolute_url(self):
        return reverse('about_app:about_page')
Ejemplo n.º 21
0
class Mymodel(models.Model):
    resize_photo = fields.ImageField(upload_to='story1399', null=True, blank=True, dependencies=[
        FileDependency(attname='original_photo', processor=ImageProcessor(
            format='JPEG', scale={'max_width': CONSUMER_BACKGROUND_WIDTH, 'max_height': CONSUMER_BACKGROUND_HEIGHT}))
    ])
    original_photo = models.ImageField(upload_to='story1399', null=True, blank=True)
Ejemplo n.º 22
0
class Profile(models.Model):
    first_name = models.CharField('Имя', max_length=20)
    second_name = models.CharField('Фамилия', max_length=20)
    middle_name = models.CharField('Отчество', max_length=20)
    GENDER_CHOICES = (
        (u'Мужчина', u'Мужчина'),
        (u'Женчина', u'Женчина'),
    )
    gender = models.CharField('Пол', max_length=20, choices=GENDER_CHOICES)
    age = models.PositiveSmallIntegerField('Возраст',
                                           validators=[MaxValueValidator(99)])
    height = models.PositiveSmallIntegerField(
        'Рост', validators=[MaxValueValidator(220)])
    weight = models.PositiveSmallIntegerField(
        'Вес', validators=[MaxValueValidator(300)])
    Hair_Color_Choices = (
        (u'Блонд', u'Блонд'),
        (u'Шатен', u'Шатен'),
        (u'Брюнет', u'Брюнет'),
        (u'Рыжий', u'Рыжий'),
        (u'Русый', u'Русый'),
        (u'Седой', u'Седой'),
        (u'Нестандартный', u'Нестандартный'),
    )
    hair = models.CharField('Цвет волос',
                            max_length=20,
                            choices=Hair_Color_Choices)
    Eye_Color_Choices = (
        (u'Синий', u'Синий'),
        (u'Голубой', u'Голубой'),
        (u'Серый', u'Серый'),
        (u'Янтарный', u'Янтарный'),
        (u'Оливковый', u'Оливковый'),
        (u'Карий', u'Карий'),
        (u'Черный', u'Черный'),
        (u'Желтый', u'Жёлтый'),
        (u'Хамелеон', u'Хамелеон'),
    )
    eye = models.CharField('Цвет глаз',
                           max_length=40,
                           choices=Eye_Color_Choices)
    education_Choices = (
        (u'Среднее', u'Среднее'),
        (u'Среднее специальное', u'Среднее специальное'),
        (u'Неполное высшее', u'Неполное высшее'),
        (u'Высшее', u'Высшее'),
        (u'Ученая степень', u'Ученая степень'),
    )
    education = models.CharField('Образование',
                                 max_length=40,
                                 choices=education_Choices)
    Job_Cgoices = (
        (u'Работаю', u'Работаю'),
        (u'Не работаю', u'Не работаю'),
        (u'Непостоянное место работы', u'Непостоянное место работы'),
    )
    job = models.CharField('Работа', max_length=40, choices=Job_Cgoices)
    children_Choices = (
        (u'Нет', u'Нет'),
        (u'Нет, но хотелось бы', u'Нет, но хотелось бы'),
        (u'Есть, живем вместе', u'Есть, живем вместе'),
        (u'Есть, живем раздельно', u'Есть, живем раздельно'),
    )
    children = models.CharField('Дети',
                                max_length=40,
                                choices=children_Choices)
    Tatoo_p_Choices = (
        (u'Нет', u'Нет'),
        (u'Нет, но хотелось бы', u'Нет, но хотелось бы'),
        (u'Есть', u'Есть'),
    )
    Tatoo_p = models.CharField('Тату\пирсинги',
                               max_length=20,
                               choices=Tatoo_p_Choices)
    address = models.CharField('Адрес', max_length=50)
    email = models.EmailField('Email')
    phone = models.PositiveSmallIntegerField(
        'Телефон', validators=[MaxValueValidator(99999999999)])
    description = models.CharField('О себе', max_length=100)
    description_p = models.CharField('О партнере', max_length=100)
    avatar = fields.ImageField(
        'Фото',
        dependencies=[
            FileDependency(processor=ImageProcessor(format='JPEG',
                                                    scale={
                                                        'max_width': 200,
                                                        'max_height': 240
                                                    }))
        ],
        upload_to='')

    ## Конструктор возращаюший Имя и Фамилию.
    def __str__(self):
        return smart_str('%s %s' % (self.first_name, self.second_name))
Ejemplo n.º 23
0
class Profile(models.Model):
    user = models.OneToOneField(User,on_delete = models.CASCADE)
    image = fields.ImageField(default = 'default.jpg',upload_to = 'profile_pics',dependencies=[FileDependency(processor=ImageProcessor(format='JPEG', scale={'max_width': 300, 'max_height': 300}))])


    def __str__(self):
        return f'{self.user.username} Profile'
Ejemplo n.º 24
0
 def test_dimensions_scaling(self):
     p = ImageProcessor()
     # scaling up: hard set dims
     self.assertEqual(p.get_dimensions(200, 100, width=100), (100, 50))
     self.assertEqual(p.get_dimensions(200, 100, height=200), (400, 200))
     # scaling up: single
     self.assertEqual(p.get_dimensions(200, 100, min_width=300), (300, 150))
     self.assertEqual(p.get_dimensions(200, 100, min_height=200),
                      (400, 200))
     # scaling up: both
     self.assertEqual(
         p.get_dimensions(200, 100, min_width=300, min_height=200),
         (400, 200))
     self.assertEqual(
         p.get_dimensions(200, 100, min_width=600, min_height=200),
         (600, 300))
     # scaling up: mixing
     self.assertEqual(
         p.get_dimensions(200, 100, min_width=300, max_width=400),
         (300, 150))
     self.assertEqual(
         p.get_dimensions(200, 100, min_height=200, max_height=400),
         (400, 200))
     # scaling down: single
     self.assertEqual(p.get_dimensions(200, 100, max_width=50), (50, 25))
     self.assertEqual(p.get_dimensions(200, 100, max_height=25), (50, 25))
     # scaling down: both
     self.assertEqual(
         p.get_dimensions(200, 100, max_width=100, max_height=75),
         (100, 50))
     self.assertEqual(
         p.get_dimensions(200, 100, max_width=150, max_height=50),
         (100, 50))
     # scaling down: mixin
     self.assertEqual(
         p.get_dimensions(200, 100, min_width=50, max_width=100), (100, 50))
     self.assertEqual(
         p.get_dimensions(200, 100, min_height=10, max_height=50),
         (100, 50))
     # no scaling: single
     self.assertEqual(p.get_dimensions(200, 100, min_width=100), (200, 100))
     self.assertEqual(p.get_dimensions(200, 100, min_height=50), (200, 100))
     self.assertEqual(p.get_dimensions(200, 100, max_width=300), (200, 100))
     self.assertEqual(p.get_dimensions(200, 100, max_height=150),
                      (200, 100))
     # no scaling: both
     self.assertEqual(
         p.get_dimensions(200, 100, min_width=50, min_height=50),
         (200, 100))
     self.assertEqual(
         p.get_dimensions(200, 100, max_width=400, max_height=200),
         (200, 100))
     # without preserving ratio
     self.assertEqual(
         p.get_dimensions(200,
                          100,
                          min_width=50,
                          max_width=100,
                          min_height=2000,
                          max_height=2001,
                          preserve=False), (100, 2000))
     self.assertEqual(
         p.get_dimensions(200,
                          100,
                          height=500,
                          min_width=300,
                          max_width=400,
                          preserve=False), (300, 500))