From 34b970cf5d3b07ecbe90d97bc068d3206441978d Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Thu, 5 Dec 2019 11:36:24 +0100 Subject: [PATCH] New AppConfig settings APPLICATION_NAME and EXTRA_HEAD_HTML --- CHANGELOG.rst | 5 +++++ Pipfile | 2 ++ Pipfile.lock | 13 +++++++++--- client/scss/components/_header.scss | 2 +- client/scss/dpaste.scss | 3 +-- dpaste/apps.py | 31 ++++++++++++++++++++++++++++ dpaste/settings/tests.py | 1 + dpaste/templates/dpaste/about.html | 6 ++++-- dpaste/templates/dpaste/base.html | 3 ++- dpaste/templates/dpaste/details.html | 2 +- dpaste/templates/dpaste/new.html | 2 +- dpaste/tests/test_snippet.py | 2 +- dpaste/urls/__init__.py | 2 +- dpaste/urls/dpaste.py | 7 ++++++- dpaste/views.py | 12 +++++++++++ 15 files changed, 79 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f3393e8..61c1aee 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,6 +8,11 @@ Changelog - Django 3.0 support and tests. - Python 3.8 support and tests. - Testsuite now uses pytest. +- New AppConfig setting "APPLICATION_NAME" that can be used to replace the term + "dpaste" throughout the UI. +- New AppConfig setting "EXTRA_HEAD_HTML" that can be used to add custom HTML + to each template, specifically used for custom CSS styles, to easily override + the stock UI of dpaste. 3.3.1 (2019-08-04): ------------------- diff --git a/Pipfile b/Pipfile index e2d5064..188a9de 100644 --- a/Pipfile +++ b/Pipfile @@ -7,8 +7,10 @@ name = "pypi" dpaste = {editable = true,extras = ["dev"],path = "."} [scripts] +runserver = "sh -c \"./manage.py migrate && ./manage.py runserver 0:8000\"" test = "pytest dpaste" cleanup = "sh -c \"isort -rc dpaste && black --skip-string-normalization --line-length=80 --exclude='/(migrations)/' dpaste\"" +docs = "sphinx-build docs docs/_build/html" [pipenv] allow_prereleases = true diff --git a/Pipfile.lock b/Pipfile.lock index c5265a0..733ff31 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -292,10 +292,10 @@ }, "jsx-lexer": { "hashes": [ - "sha256:80a107c08e5eb18188fc43b222859702bc83d5ed534bf63e1df6f2f77cc66e19", - "sha256:b1245cc02870376822fe8cc8e910810337ab6211425cf0089de504bf9da2afc6" + "sha256:1cb35102b78525aa3f587dc327f3208c0e1c76d5cdea64d4f9c3ced05d10c017", + "sha256:b879c7fafe974440a1dd9f9544dfb8629fa22078ada7f769c8fbb06149eac5d1" ], - "version": "==0.0.7" + "version": "==0.0.8" }, "livereload": { "hashes": [ @@ -459,6 +459,13 @@ ], "version": "==2.8.1" }, + "pytest-django": { + "hashes": [ + "sha256:17592f06d51c2ef4b7a0fb24aa32c8b6998506a03c8439606cb96db160106659", + "sha256:ef3d15b35ed7e46293475e6f282e71a53bcd8c6f87bdc5d5e7ad0f4d49352127" + ], + "version": "==3.7.0" + }, "pytz": { "hashes": [ "sha256:1c557d7d0e871de1f5ccd5833f60fb2550652da6be2693c1e02300743d21500d", diff --git a/client/scss/components/_header.scss b/client/scss/components/_header.scss index 8da269b..d387699 100644 --- a/client/scss/components/_header.scss +++ b/client/scss/components/_header.scss @@ -7,7 +7,7 @@ header { align-items: center; color: $headerTextColor; - background: linear-gradient(to right, $headerBgColor1, $headerBgColor2); + background-color: $headerBgColor; // Subheadline e.g. Reply Bar &.sub { diff --git a/client/scss/dpaste.scss b/client/scss/dpaste.scss index 1031b8e..85cdf97 100755 --- a/client/scss/dpaste.scss +++ b/client/scss/dpaste.scss @@ -13,8 +13,7 @@ $borderColor: #EDEDED; // Used for separators, select borders, etc. // Header $headerTextColor: white; // Header text color -$headerBgColor1: #4A90E2; // Header gradient background left -$headerBgColor2: #72B4E4; // Header gradient background right +$headerBgColor: #4A90E2; // Header background $btnBgColor: #4A90E2; // Buttons (Header, Meta) $btnBorderColor: #33639C; diff --git a/dpaste/apps.py b/dpaste/apps.py index cbdd113..c5a4a0c 100644 --- a/dpaste/apps.py +++ b/dpaste/apps.py @@ -1,4 +1,5 @@ from django.apps import AppConfig, apps +from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _ @@ -6,6 +7,25 @@ class dpasteAppConfig(AppConfig): name = 'dpaste' verbose_name = 'dpaste' + # The application title used throughout the user interface. + APPLICATION_NAME = 'dpaste' + + # This content is loaded in the section of each template. + # You can use it to add any HTML tags, specifically custom CSS styles. + # This may can give you an easier way to adjust the UI to your needs + # than having to add a template folder, plus custom template, plus + # css static file etc. + # + # Example: + # + # EXTRA_HEAD_HTML = """ + # + # """ + EXTRA_HEAD_HTML = '' + # Integer. Length of the random slug for each new snippet. In the rare # case an existing slug is generated again, the length will increase by # one more character. @@ -599,3 +619,14 @@ class dpasteAppConfig(AppConfig): if site: return 'https://{0}'.format(site.domain) return 'https://dpaste.de' + + @property + def extra_template_context(self): + """ + Returns a dictionary with context variables which are passed to + all Template Views. + """ + return { + 'dpaste_application_name': self.APPLICATION_NAME, + 'dpaste_extra_head_html': mark_safe(self.EXTRA_HEAD_HTML), + } diff --git a/dpaste/settings/tests.py b/dpaste/settings/tests.py index 6386cf7..6ec3d7e 100644 --- a/dpaste/settings/tests.py +++ b/dpaste/settings/tests.py @@ -2,6 +2,7 @@ Settings for the test suite """ import django + from .base import * SECRET_KEY = 'test-key' diff --git a/dpaste/templates/dpaste/about.html b/dpaste/templates/dpaste/about.html index 3c3c3e1..60e5fe6 100644 --- a/dpaste/templates/dpaste/about.html +++ b/dpaste/templates/dpaste/about.html @@ -2,14 +2,16 @@ {% load i18n %} -{% block title %}{% trans "About" %}{% endblock %} +{% block title %}{% blocktrans with name=dpaste_application_name %}About {{ name }}{% endblocktrans %}{% endblock %} {% block body_type %}text-page{%endblock %} {% block page %}
-

{% trans "About dpaste" %}

+

+ {% blocktrans with name=dpaste_application_name %}About {{ name }}{% endblocktrans %} +

This site is powered by dpaste, an open source diff --git a/dpaste/templates/dpaste/base.html b/dpaste/templates/dpaste/base.html index a9deb8c..52b2b8a 100644 --- a/dpaste/templates/dpaste/base.html +++ b/dpaste/templates/dpaste/base.html @@ -8,11 +8,12 @@ {% block meta %}{% endblock %} + {{ dpaste_extra_head_html }}

-

{% block headline %}dpaste{% endblock %}

+

{% block headline %}{{ dpaste_application_name }}{% endblock %}