Compare commits

...

9 Commits

Author SHA1 Message Date
Fabio Caccamo d81c7fcdd8 Updated version 2017-08-24 14:28:54 +02:00
Fabio Caccamo 4d07e9fec5 Added favicon support #28 2017-08-24 14:28:36 +02:00
Fabio Caccamo 3b982a84c3 Improved coverage 2017-08-24 14:27:34 +02:00
Fabio Caccamo 072fdcdc95 Fixed duplicated admin queries #19 2017-08-24 14:27:01 +02:00
Fabio Caccamo 07c38baa83 Updated version 2017-07-13 18:01:10 +02:00
Fabio Caccamo ed669a88be Fixed django 1.7 and django 1.9 compatibility 2017-07-13 18:00:56 +02:00
Fabio Caccamo 71ad991ba7 Fixed modals closing in older django versions. 2017-07-13 15:53:00 +02:00
Fabio Caccamo 05128a997e Added version parameter to prevent css/js caching. 2017-07-13 15:50:58 +02:00
Fabio Caccamo 92a816b9ae Updated README.md [ci skip] 2017-06-13 12:57:07 +02:00
11 changed files with 125 additions and 31 deletions
+1 -1
View File
@@ -47,7 +47,7 @@ INSTALLED_APPS = (
## Optional themes ## Optional themes
This package ships with optional themes as fixtures, they can be installed using the [loaddata admin command](https://docs.djangoproject.com/en/1.11/ref/django-admin/#django-admin-loaddata). Optional themes are activated on installation. This package ships with optional themes as fixtures, they can be installed using the [loaddata admin command](https://docs.djangoproject.com/en/1.11/ref/django-admin/#django-admin-loaddata). Optional themes are activated on installation.
##### Django theme (default): ##### [Django](https://www.djangoproject.com/) theme (default):
Run ``python manage.py loaddata admin_interface_theme_django.json`` Run ``python manage.py loaddata admin_interface_theme_django.json``
##### [Bootstrap](http://getbootstrap.com/) theme: ##### [Bootstrap](http://getbootstrap.com/) theme:
+4
View File
@@ -19,6 +19,10 @@ class ThemeAdmin(admin.ModelAdmin):
'classes': ('wide', ), 'classes': ('wide', ),
'fields': ('logo', 'logo_color', 'logo_visible', ) 'fields': ('logo', 'logo_color', 'logo_visible', )
}), }),
('Favicon', {
'classes': ('wide', ),
'fields': ('favicon', )
}),
('Title', { ('Title', {
'classes': ('wide', ), 'classes': ('wide', ),
'fields': ('title', 'title_color', 'title_visible', ) 'fields': ('title', 'title_color', 'title_visible', )
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-08-24 10:49
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('admin_interface', '0006_bytes_to_str'),
]
operations = [
migrations.AddField(
model_name='theme',
name='favicon',
field=models.FileField(blank=True, help_text='(.ico|.png|.gif - 16x16|32x32 px)', upload_to='admin-interface/favicon/', verbose_name='favicon'),
),
]
+12 -8
View File
@@ -31,18 +31,20 @@ class Theme(models.Model):
def get_active_theme(): def get_active_theme():
objs_active_qs = Theme.objects.filter( active = True ) objs_active_qs = Theme.objects.filter( active = True )
objs_active_ls = list(objs_active_qs)
objs_active_count = len(objs_active_ls)
#get or create default theme and enforce default logo if deleted if objs_active_count == 0:
default_obj_active = (objs_active_qs.count() == 0) default_obj, default_obj_created = Theme.objects.get_or_create(pk = '1', defaults = { 'active':True })
default_obj, default_obj_created = Theme.objects.get_or_create(pk = '1', defaults = { 'active':default_obj_active }) if not default_obj_created:
if not default_obj_created and default_obj_active:
default_obj.set_active() default_obj.set_active()
obj = default_obj
obj = objs_active_qs.last() elif objs_active_count == 1:
objs_active_count = objs_active_qs.count() obj = objs_active_ls[0]
if objs_active_count > 1: elif objs_active_count > 1:
obj = objs_active_ls[-1]
obj.set_active() obj.set_active()
return obj return obj
@@ -58,6 +60,8 @@ class Theme(models.Model):
logo_color = ColorField( blank = True, default = '#FFFFFF', help_text = '#FFFFFF', max_length = 10, verbose_name = 'logo color' ) logo_color = ColorField( blank = True, default = '#FFFFFF', help_text = '#FFFFFF', max_length = 10, verbose_name = 'logo color' )
logo_visible = models.BooleanField( default = True, verbose_name = 'visible' ) logo_visible = models.BooleanField( default = True, verbose_name = 'visible' )
favicon = models.FileField( upload_to = 'admin-interface/favicon/', blank = True, help_text = '(.ico|.png|.gif - 16x16|32x32 px)', verbose_name = 'favicon' )
css_header_background_color = ColorField( blank = True, default = '#0C4B33', help_text = '#0C4B33', max_length = 10, verbose_name = 'background color' ) css_header_background_color = ColorField( blank = True, default = '#0C4B33', help_text = '#0C4B33', max_length = 10, verbose_name = 'background color' )
css_header_text_color = ColorField( blank = True, default = '#44B78B', help_text = '#44B78B', max_length = 10, verbose_name = 'text color' ) css_header_text_color = ColorField( blank = True, default = '#44B78B', help_text = '#44B78B', max_length = 10, verbose_name = 'text color' )
css_header_link_color = ColorField( blank = True, default = '#FFFFFF', help_text = '#FFFFFF', max_length = 10, verbose_name = 'link color' ) css_header_link_color = ColorField( blank = True, default = '#FFFFFF', help_text = '#FFFFFF', max_length = 10, verbose_name = 'link color' )
@@ -22,13 +22,23 @@
var initData = JSON.parse(document.getElementById('django-admin-popup-response-constants').dataset.popupResponse); var initData = JSON.parse(document.getElementById('django-admin-popup-response-constants').dataset.popupResponse);
switch(initData.action){ switch(initData.action){
case 'change': case 'change':
if( typeof(openerRef.dismissChangeRelatedObjectPopup) == 'function' ){
openerRef.dismissChangeRelatedObjectPopup(modalRef, initData.value, initData.obj, initData.new_value); openerRef.dismissChangeRelatedObjectPopup(modalRef, initData.value, initData.obj, initData.new_value);
}
break; break;
case 'delete': case 'delete':
if( typeof(openerRef.dismissDeleteRelatedObjectPopup) == 'function' ){
openerRef.dismissDeleteRelatedObjectPopup(modalRef, initData.value); openerRef.dismissDeleteRelatedObjectPopup(modalRef, initData.value);
}
break; break;
default: default:
if( typeof(openerRef.dismissAddRelatedObjectPopup) == 'function' ){
openerRef.dismissAddRelatedObjectPopup(modalRef, initData.value, initData.obj); openerRef.dismissAddRelatedObjectPopup(modalRef, initData.value, initData.obj);
}
else if( typeof(openerRef.dismissAddAnotherPopup) == 'function' ){
// django 1.7 compatibility
openerRef.dismissAddAnotherPopup(modalRef, initData.value, initData.obj);
}
break; break;
} }
})(); })();
@@ -7,18 +7,23 @@ if(typeof django !== 'undefined' && typeof django.jQuery !== 'undefined' )
// create the function that will close the modal // create the function that will close the modal
function dismissRelatedObjectModal() function dismissRelatedObjectModal()
{ {
// close the popup // close the popup as modal
$.magnificPopup.close(); $.magnificPopup.close();
} }
// assign the function to a global variable // assign the function to a global variable
window.dismissRelatedObjectModal = dismissRelatedObjectModal; window.dismissRelatedObjectModal = dismissRelatedObjectModal;
// listen click events on related links function presentRelatedObjectModal(e)
// (:link prevents to listen click event if href is not defined) {
$('a.related-widget-wrapper-link:link').click(function(e){ var href = ($(this).attr('href') || '');
if( href == '' ){
return;
}
// open the popup as modal
e.preventDefault(); e.preventDefault();
e.stopImmediatePropagation();
// remove focus from clicked link // remove focus from clicked link
$(this).blur(); $(this).blur();
@@ -32,7 +37,14 @@ if(typeof django !== 'undefined' && typeof django.jQuery !== 'undefined' )
// browsers stop loading nested iframes having the same src url // browsers stop loading nested iframes having the same src url
// create a random parameter and append it to the src url to prevent it // create a random parameter and append it to the src url to prevent it
var iframeSrcRandom = String(Math.round(Math.random() * 999999)); var iframeSrcRandom = String(Math.round(Math.random() * 999999));
var iframeSrc = $(this).attr('href') + '&_modal=' + iframeSrcRandom; var iframeSrc = href;
// fix for django 1.7
if( iframeSrc.indexOf('_popup=1') == -1 ){
iframeSrc += '&_popup=1';
}
iframeSrc += '&_modal=' + iframeSrcRandom;
// build the iframe html // build the iframe html
// var iframeHTML = '<iframe id="related-modal" name="' + iframeName + '" src="' + iframeSrc + '"></iframe>'; // var iframeHTML = '<iframe id="related-modal" name="' + iframeName + '" src="' + iframeSrc + '"></iframe>';
@@ -61,7 +73,16 @@ if(typeof django !== 'undefined' && typeof django.jQuery !== 'undefined' )
}); });
return false; return false;
}); }
// listen click events on related links
// django 1.7 compatibility
$('a.add-another').removeAttr('onclick');
$('a.add-another').click( presentRelatedObjectModal );
// django 1.8 and above
$('a.related-widget-wrapper-link').click( presentRelatedObjectModal );
}); });
})(django.jQuery); })(django.jQuery);
+14 -6
View File
@@ -8,8 +8,12 @@
{% block extrastyle %} {% block extrastyle %}
{% get_admin_interface_theme as theme %} {% get_admin_interface_theme as theme %}
{% get_admin_interface_version as version %}
<style type="text/css"> <style type="text/css">
/*
django-admin-interface {{ version }}
https://github.com/fabiocaccamo/django-admin-interface
*/
{% include "admin_interface/css/admin-interface.css" %} {% include "admin_interface/css/admin-interface.css" %}
{% include "admin_interface/css/admin-interface-fix.css" %} {% include "admin_interface/css/admin-interface-fix.css" %}
{% include "admin_interface/css/list-filter-dropdown.css" %} {% include "admin_interface/css/list-filter-dropdown.css" %}
@@ -29,14 +33,18 @@
{% block blockbots %} {% block blockbots %}
{{ block.super }} {{ block.super }}
{% get_admin_interface_theme as theme %}
{% get_admin_interface_version as version %}
{# https://github.com/elky/django-flat-responsive#important-note #} {# https://github.com/elky/django-flat-responsive#important-note #}
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"> <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0">
<link rel="stylesheet" type="text/css" href="{% static 'admin/css/responsive.css' %}" /> <link rel="stylesheet" type="text/css" href="{% static 'admin/css/responsive.css' %}?v={{ version }}" />
{% get_admin_interface_theme as theme %} {% if theme.favicon %}
<link rel="icon" type="image/x-icon" href="{{ theme.favicon.url }}?v={{ version }}" />
{% endif %}
{% if theme.related_modal_active %} {% if theme.related_modal_active %}
<link rel="stylesheet" type="text/css" href="{% static 'admin_interface/magnific-popup/magnific-popup.css' %}" /> <link rel="stylesheet" type="text/css" href="{% static 'admin_interface/magnific-popup/magnific-popup.css' %}?v={{ version }}" />
<script type="text/javascript" src="{% static 'admin_interface/magnific-popup/jquery.magnific-popup.js' %}"></script> <script type="text/javascript" src="{% static 'admin_interface/magnific-popup/jquery.magnific-popup.js' %}?v={{ version }}"></script>
<script type="text/javascript" src="{% static 'admin_interface/related-modal/related-modal.js' %}"></script> <script type="text/javascript" src="{% static 'admin_interface/related-modal/related-modal.js' %}?v={{ version }}"></script>
{% endif %} {% endif %}
{% endblock %} {% endblock %}
@@ -0,0 +1,15 @@
{% load i18n static %}<!DOCTYPE html>
<html>
<head><title>{% trans 'Popup closing...' %}</title></head>
<body>
<script type="text/javascript"
id="django-admin-popup-response-constants"
src="{% static "admin/js/popup_response.js" %}"
{% if popup_response_data %}
data-popup-response="{{ popup_response_data }}"
{% else %}
data-popup-response='{"action":"{{ action|escape }}","value":"{{ value|escape }}","obj":"{{ obj|escape }}","new_value":"{{ new_value|escape }}"}'
{% endif %}>
</script>
</body>
</html>
@@ -3,7 +3,7 @@
from django import template from django import template
from admin_interface.models import Theme from admin_interface.models import Theme
from admin_interface.version import __version__
register = template.Library() register = template.Library()
@@ -30,3 +30,8 @@ def get_admin_interface_theme(context):
return theme return theme
@assignment_tag(takes_context = True)
def get_admin_interface_version(context):
return __version__
+1 -1
View File
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
__version__ = '0.5.0' __version__ = '0.5.2'
+8 -1
View File
@@ -9,6 +9,7 @@ import random
import shutil import shutil
from admin_interface.models import Theme from admin_interface.models import Theme
from admin_interface.version import __version__
class AdminInterfaceTestCase(TestCase): class AdminInterfaceTestCase(TestCase):
@@ -107,6 +108,12 @@ class AdminInterfaceTestCase(TestCase):
rendered = self.__render_template('{% load admin_interface_tags %}{% get_admin_interface_theme as theme %}{{ theme.name }}', context) rendered = self.__render_template('{% load admin_interface_tags %}{% get_admin_interface_theme as theme %}{{ theme.name }}', context)
self.assertEqual(rendered, 'Django') self.assertEqual(rendered, 'Django')
def test_templatetags_version(self):
context = Context({})
rendered = self.__render_template('{% load admin_interface_tags %}{% get_admin_interface_version as version %}{{ version }}', context)
self.assertEqual(rendered, __version__)
def test_templatetags_with_request(self): def test_templatetags_with_request(self):
Theme.objects.all().delete() Theme.objects.all().delete()
@@ -118,5 +125,5 @@ class AdminInterfaceTestCase(TestCase):
def test_repr(self): def test_repr(self):
theme = Theme.get_active_theme() theme = Theme.get_active_theme()
self.assertEqual( "{0}".format(theme), 'Django' ) self.assertEqual( '{0}'.format(theme), 'Django' )