Skip to content

Commit

Permalink
Merge branch 'release-1.12.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
abidibo committed Oct 22, 2020
2 parents bc5bde5 + 4a9c247 commit 1da0d81
Show file tree
Hide file tree
Showing 20 changed files with 171 additions and 91 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Login with user `demo` and password `demo`

## <a name="features"></a>Features

Tested with Django >= 1.10.5
Supports Django >= 1.11

This application was written with one concept in mind: overwrite as few django templates as possible.
Everything is styled through CSS and when required, JS is used.
Expand All @@ -60,14 +60,15 @@ Everything is styled through CSS and when required, JS is used.

The following packages are required to manage the Google Analytics index:

- google-api-python-client
- oauth2client==1.5.2
- google-auth==1.22.1
- google-auth-httplib2==0.0.4
- google-api-python-client==1.5.5

At the moment __baton__ defines only 4 custom templates:

- `admin/base_site.html`, needed to inject the JS application (which includes css and images, compiled with [webpack](https://webpack.github.io/));
- `admin/change_form.html`, needed to inject the `baton_form_includes` stuff. In any case, the template extends the default one and just adds some stuff at the end of the content block, so it's still full compatible with the django one;
- `admin/delete_confirmation.html`, needed because of a bug (IMO) in the template, in particular the `extra_head` block does not contain the parent content, hence it must be overridden (FIXED IN django 1.11, remains until baton will support django 1.10);
- `admin/delete_confirmation.html`, needed to wrap contents;
- `admin/delete_selected_confirmation.html`, same as above.

Baton is based on the following frontend technologies:
Expand Down
1 change: 1 addition & 0 deletions baton/autodiscover/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class BatonAdminSite(AdminSite):
index_title = get_config('INDEX_TITLE')
index_template = 'baton/index.html' if get_config(
'ANALYTICS') else 'admin/index.html'
enable_nav_sidebar = False

def __init__(self, *args, **kwargs):
""" Registers all apps with BatonAdminSite """
Expand Down
8 changes: 4 additions & 4 deletions baton/static/baton/app/dist/baton.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion baton/static/baton/app/dist/baton.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion baton/static/baton/app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion baton/static/baton/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "baton",
"version": "1.11.0",
"version": "1.12.0",
"description": "Django Baton App",
"main": "index.js",
"scripts": {
Expand Down
25 changes: 22 additions & 3 deletions baton/static/baton/app/src/core/ChangeForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ let ChangeForm = {
this.lazyLoadImages()
}
this.activateEntryCollapsing()
this.changeFieldsetCollapseStyle()
this.fixExpandFirstErrorCollapsing()
this.initTemplates()
},
Expand Down Expand Up @@ -88,9 +89,18 @@ let ChangeForm = {
},
fixWrappedFields: function () {
this.form.find('.form-row').each(function (index, row) {
$(row).children('.fieldBox').wrapAll('<div class="wrapped-fields-container" />')
var fieldBoxes = $(row).children('.fieldBox')
fieldBoxes.each(function (index, fbox) {
if ($(fbox).hasClass('errors')) {
$(row).addClass('errors')
}
})
fieldBoxes.wrapAll('<div class="wrapped-fields-container" />')
if (fieldBoxes.length) {
$(row).addClass('with-wrapped-fields')
}
})
this.form.find('.wrapped-fields-container > .fieldBox:first-child').children().unwrap()
// this.form.find('.wrapped-fields-container > .fieldBox:first-child').children().unwrap()
},
fixNewlines: function () {
$('.form-row br').replaceWith('<span class="newline"></span>')
Expand Down Expand Up @@ -145,6 +155,16 @@ let ChangeForm = {
}
})
},
changeFieldsetCollapseStyle: function () {
$('fieldset.collapse > h2').each(function (index, title) {
let text = $(title).text()
setTimeout(function () {
$(title).html(text).on('click', function () {
$(this).parent('.collapse').toggleClass('collapsed')
})
}, 100)
})
},
initTemplates: function () {
const positionMap = {
above: 'before',
Expand All @@ -160,7 +180,6 @@ let ChangeForm = {
let el = $(template).attr('data-position') === 'right'
? $('.form-row.field-' + field + ' #id_' + field)
: $('.form-row.field-' + field)
console.log(el)
el[position]($(template).html())
} else {
console.error('Baton: wrong form include position detected')
Expand Down
7 changes: 7 additions & 0 deletions baton/static/baton/app/src/styles/_changelist.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
flex-wrap: wrap;
overflow: hidden;

.changelist-form-container { // django 3.1.1
display: flex;
flex: 0 0 100%;
flex-wrap: wrap;
overflow: hidden;
}

// no object tools
&:first-child {
margin-top: 1rem;
Expand Down
78 changes: 66 additions & 12 deletions baton/static/baton/app/src/styles/_placeholders.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,40 @@
margin-bottom: .5rem;
padding: 1rem .5rem;

&.with-wrapped-fields {
background: transparent;
}

&.errors {
background: $field-row-error-bg;

.errorlist {
@extend .pt-2;
padding-left: 1.2rem;
padding-left: 0;
width: 100%;

@include media-breakpoint-up(md) {
padding-left: 1.2rem;
}

li {
color: $danger-fg !important;
list-style-type: none;
font-weight: bold;
text-decoration: underline;

&::before {
@extend %font-awesome;
content: '\f12a';
display: inline-block;
margin-right: .5rem;
}
}
}

.wrapped-fields-container {
.errorlist {
padding-left: 0 !important;
}
}
}
Expand Down Expand Up @@ -316,7 +338,8 @@
}
}

.add-related {
.add-related,
.change-related {
vertical-align: top;
}

Expand Down Expand Up @@ -480,13 +503,6 @@

.collapse {
display: block;

h2 {
@extend .p-2;
background: $collapse-title-bg;
border: 1px solid $collapse-title-border-color;
font-size: $h2-size;
}
}

.collapsed * {
Expand Down Expand Up @@ -578,6 +594,34 @@
@extend .pt-3;
}

fieldset.collapse {
cursor: pointer;
display: block;

h2 {
align-items: center;
display: flex;
flex-direction: row;
justify-content: space-between;

&::after {
color: $collapse-entry-icon-color;
content: '\f070';
display: inline-block;
font-family: 'Font Awesome\ 5 Free';
font-size: 1.1rem;
}
}

&.collapsed {
h2 {
&::after {
content: '\f06e';
}
}
}
}

// inline
fieldset .form-row {
margin-left: 0;
Expand Down Expand Up @@ -704,7 +748,7 @@
padding: 2px 4px;

&::before {
content: '\f040';
content: '\f304';
font-family: 'Font Awesome\ 5 Free';
margin-right: 4px;
}
Expand Down Expand Up @@ -776,9 +820,10 @@

.wrapped-fields-container .fieldBox {
margin-top: 1rem;
width: 100%;

label + *:not(.datetime) {
display: inline-block;
label {
width: 100%;
}

.help {
Expand All @@ -788,6 +833,15 @@
@include media-breakpoint-up(md) {
margin-left: 1rem;
margin-top: 0;
width: auto;

label {
width: auto;
}

label + *:not(.datetime) {
display: inline-block;
}
}
}
}
2 changes: 0 additions & 2 deletions baton/static/baton/app/src/styles/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ $rl-tr-selected-color: inherit;
// changeform
$changeform-bg: #fff;
$changeform-border-color: #ccc;
$collapse-title-bg: #fafafa;
$collapse-title-border-color: #ccc;
$collapse-entry-icon-color: #666;
$state-danger-bg: #f2dede;
$field-bg: #f9f9f9;
Expand Down
21 changes: 0 additions & 21 deletions baton/templates/admin/delete_confirmation.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,6 @@
{% extends "admin/delete_confirmation.html" %}
{% load static %}

{% block extrahead %}
{{ block.super }}
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<link href="https://fonts.googleapis.com/css?family=Dosis:300,400,700" rel="stylesheet">
<script src="{% static 'baton/app/dist/baton.min.js' %}"></script>
<!-- <script src="http://localhost:8080/dist/baton.min.js"></script> -->
<script>
(function ($, undefined) {
$(window).on('load', function () {
if (!Baton.initialized) {
Baton.init({
api: {
app_list: '{% url 'baton-app-list-json' %}'
}
});
}
})
})(jQuery, undefined)
</script>
{% endblock %}

{% block content %}
<div class="delete-confirmation-content">
{{ block.super }}
Expand Down
21 changes: 0 additions & 21 deletions baton/templates/admin/delete_selected_confirmation.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,6 @@
{% extends "admin/delete_selected_confirmation.html" %}
{% load static %}

{% block extrahead %}
{{ block.super }}
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<link href="https://fonts.googleapis.com/css?family=Dosis:300,400,700" rel="stylesheet">
<script src="{% static 'baton/app/dist/baton.min.js' %}"></script>
<!-- <script src="http://localhost:8080/dist/baton.min.js"></script> -->
<script>
(function ($, undefined) {
$(window).on('load', function () {
if (!Baton.initialized) {
Baton.init({
api: {
app_list: '{% url 'baton-app-list-json' %}'
}
});
}
})
})(jQuery, undefined)
</script>
{% endblock %}

{% block content %}
<div class="delete-confirmation-content">
{{ block.super }}
Expand Down
28 changes: 15 additions & 13 deletions baton/templatetags/baton_tags.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import json
from oauth2client.client import SignedJwtAssertionCredentials

from google.auth.transport.requests import Request
from django import template
from django.core.exceptions import ImproperlyConfigured
from google.oauth2 import service_account

from ..config import get_config

Expand All @@ -20,27 +19,30 @@ def analytics(context, next=None):
analytics_settings = get_config('ANALYTICS')

if not analytics_settings['CREDENTIALS']:
raise ImproperlyConfigured('Analytics service account json path missing') # noqa
raise ImproperlyConfigured(
'Analytics service account json path missing') # noqa

if not analytics_settings['VIEW_ID']:
raise ImproperlyConfigured('Analytics view id missing')

# The scope for the OAuth2 request.
SCOPE = 'https://www.googleapis.com/auth/analytics.readonly'

SCOPES = [
'https://www.googleapis.com/auth/analytics.readonly',
]
# The location of the key file with the key data.
KEY_FILEPATH = analytics_settings['CREDENTIALS']
SERVICE_ACCOUNT_FILE = analytics_settings['CREDENTIALS']

# Load the key file's private data.
with open(KEY_FILEPATH) as key_file:
_key_data = json.load(key_file)
_credentials = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE,
scopes=SCOPES, )
_credentials.refresh(Request())

# Construct a credentials objects from the key data and OAuth2 scope.
_credentials = SignedJwtAssertionCredentials(
_key_data['client_email'], _key_data['private_key'], SCOPE)
# _credentials = SignedJwtAssertionCredentials(
# _key_data['client_email'], _key_data['private_key'], SCOPE)

return {
'token': _credentials.get_access_token().access_token,
'token': _credentials.token,
'view_id': analytics_settings['VIEW_ID']
}

Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
# built documents.
#
# The short X.Y version.
version = u'1.11.0'
version = u'1.12.0'
# The full version, including alpha/beta/rc tags.
release = u'1.11.0'
release = u'1.12.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Everything is done with css (sass and bootstrap mixins), and when the markup nee
Features
--------

- Tested with django >= 1.10.5
- Supports django >= 1.11
- Based on bootstrap 4.5.0 and FontAwesome 5.8.1
- Fully responsive
- Custom and flexible sidebar menu
Expand Down

0 comments on commit 1da0d81

Please sign in to comment.