Unverified Kaydet (Commit) 545114e0 authored tarafından Uğur Özyılmazel's avatar Uğur Özyılmazel

Django Admin site related changes

    - Now, `DJANGO_ENV` env variable is exposed to admin site
    - Fix your admin site titles from `config/urls.py`
    - Change or create admin site's base look and feel
üst e883dfc9
......@@ -78,6 +78,17 @@ $ python manage.py generate_secret_key
and fix your `~/.virtualenvs/my_projects_env/bin/postactivate`
You can fix your Django Admin titles now. Go to `config/urls.py` and fix:
```python
admin.site.index_title = _('Your admin index title')
admin.site.site_title = _('Your site title')
admin.site.site_header = _('Your site header')
```
Do not forget to compile your locale messages file.
---
## Features
......@@ -95,6 +106,8 @@ and fix your `~/.virtualenvs/my_projects_env/bin/postactivate`
- Debug Mixins for your HTML templates
- Handy utils: `console`, `console.dir()`, `numerify`, `urlify`, `save_file`
- File widget for Django Admin: `AdminImageFileWidget`
- Easy naming for your admin site!
- `DJANGO_ENV` indicator for your admin site!
---
......@@ -458,6 +471,7 @@ Here is directory/file structure:
│   ├── widgets
│   ├── __init__.py
│   ├── apps.py
│   ├── context_processors.py
│   ├── urls.py
│   └── views.py
├── config
......@@ -484,6 +498,8 @@ Here is directory/file structure:
│   └── heroku.pip
├── static
├── templates
│   └── admin
│   └── base_site.html
│   └── baseapp
│   ├── base.html
│   └── index.html
......@@ -565,15 +581,18 @@ Django Extension adds great functionalities:
- `dumpscript`
- `export_emails`
- `find_template`
- `generate_password`
- `generate_secret_key`
- `graph_models`
- `mail_debug`
- `merge_model_instances`
- `notes`
- `passwd`
- `pipchecker`
- `print_settings`
- `print_user_for_session`
- `reset_db`
- `reset_schema`
- `runjob`
- `runjobs`
- `runprofileserver`
......@@ -606,8 +625,8 @@ All the required modules are defined under `requirements/development.pip`:
```python
# requirements/development.pip
-r base.pip
ipython==6.2.1
django-extensions==1.9.8
ipython==6.3.1
django-extensions==2.0.7
Werkzeug==0.14.1
django-debug-toolbar==1.9.1
```
......@@ -632,9 +651,9 @@ All the required modules are defined under `requirements/heroku.pip`:
```python
# requirements/heroku.pip
-r base.pip
gunicorn==19.7.1
psycopg2==2.7.3.2
dj-database-url==0.4.2
gunicorn==19.8.1
psycopg2==2.7.4
dj-database-url==0.5.0
whitenoise==3.3.1
```
......@@ -1169,6 +1188,61 @@ requirements file. Show image preview, width x height if the file is image.
---
## `context_processors.py`
Currently, there is only one template variable available: `{{ DJANGO_ENVIRONMENT_NAME }}`.
This is used for indicating the current environment in django admin site. You
can customize look and feel here:
```django
<!-- templates/admin/base_site.html -->
{% extends "admin/base_site.html" %}
{% load i18n %}
{% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}
{% block branding %}
<h1 id="site-name">
<a href="{% url 'admin:index' %}">{{ site_header|default:_('Django administration') }}</a>
</h1>
{% endblock %}
{% block welcome-msg %}
{% trans 'Welcome,' %}
<strong>{{ user.get_full_name }}</strong>.
{% endblock %}
{% block extrastyle %}
<style type="text/css">
body:before {
display: block;
width: 100%;
position: fixed;
top: 0;
z-index: 9999;
line-height: 35px;
text-align: center;
font-weight: bold;
text-transform: uppercase;
color: white;
content: "{{ DJANGO_ENVIRONMENT_NAME }}";
background-color: red;
}
body {
padding-top: 35px !important;
}
</style>
{% endblock %}
```
This adds a basic HTML element via CSS to the `<body>` tag.
---
## Rakefile
If you have Ruby installed, you’ll have lots of handy tasks for the project.
......@@ -1438,6 +1512,8 @@ This project is licensed under MIT
**2018-05-02**
- Django 2.0.5 and related changes.
- Django Admin site titles are easy editable.
- Django Admin site indicator.
**2018-01-09**
......
import os
__all__ = [
'django_environment_variable',
]
def django_environment_variable(request):
return {
'DJANGO_ENVIRONMENT_NAME': os.getenv('DJANGO_ENV', 'N/A'),
}
......@@ -46,6 +46,7 @@ TEMPLATES = [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'baseapp.context_processors.django_environment_variable',
],
},
},
......
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from django.urls import (
path,
......@@ -6,6 +7,10 @@ from django.urls import (
from django.conf.urls.static import static
from django.contrib import admin
admin.site.index_title = _('Your admin index title')
admin.site.site_title = _('Your site title')
admin.site.site_header = _('Your site header')
urlpatterns = [
path('admin/', admin.site.urls),
path('__baseapp__/', include('baseapp.urls', namespace='baseapp')),
......
......@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: django-base-project\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-09-20 15:59+0300\n"
"POT-Creation-Date: 2018-05-02 14:16+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Uğur Özyılmazel <ugurozyilmazel@gmail.com>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
......@@ -18,16 +18,16 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#: applications/baseapp/admin/base.py:34
#: applications/baseapp/admin/base.py:27
msgid "1 record was"
msgstr "1 kayıt"
#: applications/baseapp/admin/base.py:36
#: applications/baseapp/admin/base.py:29
#, python-format
msgid "%(number_of_rows)s records were"
msgstr "%(number_of_rows)s kayıt"
#: applications/baseapp/admin/base.py:37
#: applications/baseapp/admin/base.py:30
#, python-format
msgid "%(message_bit)s successfully marked as active"
msgstr "%(message_bit)s aktif olarak işaretlendi."
......@@ -49,12 +49,12 @@ msgid ""
msgstr ""
#: applications/baseapp/admin/user.py:41 applications/baseapp/admin/user.py:68
#: applications/baseapp/models/user.py:81
#: applications/baseapp/models/user.py:72
msgid "first name"
msgstr ""
#: applications/baseapp/admin/user.py:42 applications/baseapp/admin/user.py:69
#: applications/baseapp/models/user.py:91
#: applications/baseapp/models/user.py:82
msgid "last name"
msgstr ""
......@@ -75,74 +75,100 @@ msgid "Permissions"
msgstr ""
#: applications/baseapp/admin/user.py:137
#: applications/baseapp/models/user.py:95
#: applications/baseapp/models/user.py:86
msgid "Profile Image"
msgstr "Profil Fotoğrafı"
#: applications/baseapp/models/base.py:26
#: applications/baseapp/models/base.py:137
msgid "Offline"
msgstr "Kapalı"
#: applications/baseapp/models/base.py:27
#: applications/baseapp/models/base.py:138
msgid "Online"
msgstr "Yayında"
#: applications/baseapp/models/base.py:28
#: applications/baseapp/models/base.py:139
msgid "Deleted"
msgstr "Silinmiş"
#: applications/baseapp/models/base.py:29
#: applications/baseapp/models/base.py:140
msgid "Draft"
msgstr "Taslak"
#: applications/baseapp/models/base.py:34
#: applications/baseapp/models/base.py:145
#: applications/baseapp/models/user.py:60
msgid "Created At"
msgstr "Oluşturma Tarihi"
#: applications/baseapp/models/base.py:38
#: applications/baseapp/models/base.py:149
#: applications/baseapp/models/user.py:64
msgid "Updated At"
msgstr "Güncelleme Tarihi"
#: applications/baseapp/models/base.py:43
#: applications/baseapp/models/base.py:154
msgid "Status"
msgstr "Durum"
#: applications/baseapp/models/base.py:76
#: applications/baseapp/models/base.py:168
msgid "Deleted At"
msgstr "Silinme Tarihi"
#: applications/baseapp/models/user.py:32
#: applications/baseapp/models/user.py:26
msgid "Users must have an email address"
msgstr ""
#: applications/baseapp/models/user.py:77
#: applications/baseapp/models/user.py:68
msgid "email address"
msgstr ""
#: applications/baseapp/models/user.py:87
#: applications/baseapp/models/user.py:78
msgid "middle name"
msgstr "göbek adı"
#: applications/baseapp/models/user.py:99
#: applications/baseapp/models/user.py:92
msgid "active"
msgstr ""
#: applications/baseapp/models/user.py:103
#: applications/baseapp/models/user.py:96
msgid "staff status"
msgstr ""
#: applications/baseapp/models/user.py:110
#: applications/baseapp/models/user.py:103
msgid "user"
msgstr ""
#: applications/baseapp/models/user.py:111
#: applications/baseapp/models/user.py:104
msgid "users"
msgstr ""
#: applications/baseapp/widgets/image_file.py:46
#: applications/baseapp/widgets/image_file.py:49
msgid "Dimensions"
msgstr "Boyutları"
#: config/urls.py:10
msgid "Your admin index title"
msgstr "Admin listesi başlığı"
#: config/urls.py:11
msgid "Your site title"
msgstr "Siteniniz başlığı"
#: config/urls.py:12
msgid "Your site header"
msgstr "Marka ya da proje başlığı"
#: templates/admin/base_site.html:5
msgid "Django site admin"
msgstr ""
#: templates/admin/base_site.html:9
msgid "Django administration"
msgstr ""
#: templates/admin/base_site.html:15
msgid "Welcome,"
msgstr ""
#: templates/baseapp/index.html:8
msgid "Welcome to Django"
msgstr ""
......
{% extends "admin/base_site.html" %}
{% load i18n %}
{% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}
{% block branding %}
<h1 id="site-name">
<a href="{% url 'admin:index' %}">{{ site_header|default:_('Django administration') }}</a>
</h1>
{% endblock %}
{% block welcome-msg %}
{% trans 'Welcome,' %}
<strong>{{ user.get_full_name }}</strong>.
{% endblock %}
{% block extrastyle %}
<style type="text/css">
body:before {
display: block;
width: 100%;
position: fixed;
top: 0;
z-index: 9999;
line-height: 35px;
text-align: center;
font-weight: bold;
text-transform: uppercase;
color: white;
content: "{{ DJANGO_ENVIRONMENT_NAME }}";
background-color: red;
}
body {
padding-top: 35px !important;
}
</style>
{% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment