models.py
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from os import path
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.contrib.staticfiles.templatetags.staticfiles import static
def validate_img_extension(value):
valid_formats = ['image/jpeg','image/x-citrix-jpeg','image/png','image/x-citrix-png','image/x-png']
if hasattr(value.file, 'content_type'):
if not value.file.content_type in valid_formats:
raise ValidationError(_('File not supported.'))
class Themes(models.Model):
title = models.CharField(_("Title"), max_length = 200, default = "Projeto Amadeus")
favicon = models.ImageField(verbose_name = _("Favicon"), blank = True, null = True, upload_to = 'themes/', validators = [validate_img_extension])
small_logo = models.ImageField(verbose_name = _("Small Logo"), blank = True, null = True, upload_to = 'themes/', validators = [validate_img_extension])
large_logo = models.ImageField(verbose_name = _("Large Logo"), blank = True, null = True, upload_to = 'themes/', validators = [validate_img_extension])
high_contrast_logo = models.ImageField(verbose_name = _("High Contrast Logo"), blank = True, null = True, upload_to = 'themes/', validators = [validate_img_extension])
footer_note = models.TextField(_("Footer Note"), blank = True)
css_style = models.CharField(_("Css Style"), max_length = 50, default = "green", choices = (("green", _('Green')),("contrast",_('Contrast')),("red", _('Red')), ("black", _('Black'))))
class Meta:
verbose_name = _("Theme")
verbose_name_plural = _("Themes")
def __str__(self):
return self.title
@property
def favicon_url(self):
if self.favicon and hasattr(self.favicon, 'url'):
if path.exists(self.favicon.path):
return self.favicon.url
return static('img/favicon_amadeus.png')
@property
def small_logo_url(self):
if self.small_logo and hasattr(self.small_logo, 'url'):
if path.exists(self.small_logo.path):
return self.small_logo.url
return static('img/logo_pequena_amadeus.png')
@property
def large_logo_url(self):
if self.large_logo and hasattr(self.large_logo, 'url'):
if path.exists(self.large_logo.path):
return self.large_logo.url
return static('img/logo_grande_amadeus.png')
@property
def high_contrast_logo_url(self):
if self.high_contrast_logo and hasattr(self.high_contrast_logo, 'url'):
if path.exists(self.high_contrast_logo.path):
return self.high_contrast_logo.url
return static('img/alto_contraste_logo_amadeus.png')