Commit d7895551527a85c8f715422b35439aa574928085

Authored by Zambom
1 parent 6ac8d813

Adding favicon to themes form

amadeus/static/js/themes.js
... ... @@ -8,6 +8,7 @@ if (window.File && window.FileList && window.FileReader) {
8 8 function Init() {
9 9 var small = $("#id_small_logo"),
10 10 large = $("#id_large_logo"),
  11 + fav = $("#id_favicon"),
11 12 filedrag = $(".filedrag"),
12 13 common = $(".common-file-input");
13 14  
... ...
amadeus/templates/base.html
... ... @@ -5,7 +5,7 @@
5 5  
6 6 <html>
7 7 <head>
8   - <title>{{ title }} | Amadeus</title>
  8 + <title>{{ title }} | {{ theme.title }}</title>
9 9  
10 10 <!-- jQuery & jQuery UI -->
11 11 <script type="text/javascript" src="{% static 'js/jquery-3.1.0.min.js' %}"></script>
... ...
themes/forms.py
... ... @@ -5,6 +5,18 @@ from .models import Themes
5 5  
6 6 class BasicElemetsForm(forms.ModelForm):
7 7  
  8 + def clean_favicon(self):
  9 + image = self.cleaned_data.get('favicon', False)
  10 +
  11 + if image:
  12 + if hasattr(image, '_size'):
  13 + if image._size > self.MAX_UPLOAD_SIZE:
  14 + self._errors['favicon'] = [_("The image is too large. It should have less than 2MB.")]
  15 +
  16 + return ValueError
  17 +
  18 + return image
  19 +
8 20 def clean_small_logo(self):
9 21 image = self.cleaned_data.get('small_logo', False)
10 22  
... ... @@ -31,7 +43,7 @@ class BasicElemetsForm(forms.ModelForm):
31 43  
32 44 class Meta:
33 45 model = Themes
34   - fields = ['title', 'small_logo', 'large_logo', 'footer_note']
  46 + fields = ['title', 'favicon', 'small_logo', 'large_logo', 'footer_note']
35 47  
36 48 class CSSStyleForm(forms.ModelForm):
37 49  
... ...
themes/migrations/0004_themes_favicon.py 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +# -*- coding: utf-8 -*-
  2 +# Generated by Django 1.10 on 2017-01-12 20:42
  3 +from __future__ import unicode_literals
  4 +
  5 +from django.db import migrations, models
  6 +import themes.models
  7 +
  8 +
  9 +class Migration(migrations.Migration):
  10 +
  11 + dependencies = [
  12 + ('themes', '0003_auto_20170112_1408'),
  13 + ]
  14 +
  15 + operations = [
  16 + migrations.AddField(
  17 + model_name='themes',
  18 + name='favicon',
  19 + field=models.ImageField(blank=True, default='favicon_amadeus.png', upload_to='themes/', validators=[themes.models.validate_img_extension], verbose_name='Favicon'),
  20 + ),
  21 + ]
... ...
themes/models.py
... ... @@ -10,6 +10,7 @@ def validate_img_extension(value):
10 10  
11 11 class Themes(models.Model):
12 12 title = models.CharField(_("Title"), max_length = 200, default = "Projeto Amadeus")
  13 + favicon = models.ImageField(verbose_name = _("Favicon"), blank = True, upload_to = 'themes/', default = 'favicon_amadeus.png', validators = [validate_img_extension])
13 14 small_logo = models.ImageField(verbose_name = _("Small Logo"), blank = True, upload_to = 'themes/', default = 'logo_pequena_amadeus.png', validators = [validate_img_extension])
14 15 large_logo = models.ImageField(verbose_name = _("Large Logo"), blank = True, upload_to = 'themes/', default = 'logo_grande_amadeus.png', validators = [validate_img_extension])
15 16 footer_note = models.TextField(_("Footer Note"), blank = True)
... ...
themes/templates/themes/basic_update.html
... ... @@ -19,7 +19,7 @@
19 19 {% csrf_token %}
20 20 {% for field in form %}
21 21 <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput">
22   - {% if field.auto_id == 'id_small_logo' or field.auto_id == 'id_large_logo' %}
  22 + {% if field.auto_id == 'id_small_logo' or field.auto_id == 'id_large_logo' or field.auto_id == 'id_favicon' %}
23 23 {% if field.field.required %}
24 24 <label for="{{ field.auto_id }}">{{ field.label }} <span>*</span></label>
25 25 {% else %}
... ... @@ -36,7 +36,20 @@
36 36 </button>
37 37 </span>
38 38 </div>
39   - <div class="filedrag">{% trans 'Click or drop files here' %}</div>
  39 + <div class="filedrag">
  40 + {% trans 'Click or drop files here' %}<br />
  41 +
  42 + {% trans 'Recommended dimensions' %}:
  43 +
  44 + {% if field.auto_id == 'id_small_logo' %}
  45 + 927px x 955px <br />
  46 + <small>{% trans 'It is recommended to be a white image' %}</small>
  47 + {% elif field.auto_id == 'id_favicon' %}
  48 + 927px x 955px
  49 + {% else %}
  50 + 1286px x 955px
  51 + {% endif %}
  52 + </div>
40 53  
41 54 {% elif field.auto_id == 'id_footer_note' %}
42 55 {% if field.field.required %}
... ...