Skip to content

Commit

Permalink
Added Django admin documentation templates and fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
sainipray committed May 7, 2017
1 parent 5aa12c6 commit 467d31b
Show file tree
Hide file tree
Showing 23 changed files with 825 additions and 52 deletions.
11 changes: 9 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ Djadmin is a django admin theme

Overview
========

**"NEW UPDATES"**

- Added Django Admin documentation templates

- Fixed Bugs

**"IN VERSION 1.1.5"**

- Added Sortable in admin **change list** page.

- Added Language dropdown.
Expand All @@ -28,7 +33,7 @@ Overview

- Fixed Bugs

**" VERSION 1.1.3 "**
**"FEATURES ADDED IN VERSION 1.1.3"**
- Dynamic Django Admin - Admin options like : list_display, list_display_link etc will work dynamic.

- Material Design - Djadmin is based on material design.
Expand Down Expand Up @@ -64,6 +69,8 @@ Documentation

'djadmin.middleware.DJMiddleware',

* Please make sure you already have 'django.template.context_processors.request' in context_processors of settings. If you don't have, please add it

* Add in urls.py ::

url(r'^admin/', include('djadmin.urls')),
Expand Down
2 changes: 1 addition & 1 deletion djadmin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
default_app_config = 'djadmin.apps.ActivityAppConfig'
__name__ = 'djadmin'
__author__ = 'Neeraj Kumar'
__version__ = '1.1.4'
__version__ = '1.1.6'
__author_email__ = '[email protected]'
__description__ = 'Djadmin is a django admin theme'
5 changes: 3 additions & 2 deletions djadmin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
from django.contrib import admin
from django.contrib.auth import get_user_model
from django.db.models import Q
from django.utils.translation import ugettext as _

from djadmin import settings
from .models import DjadminField, DjadminModelSetting, DjadminCard, Visitor
from .models import DjadminField, DjadminModelSetting, DjadminCard

User = get_user_model()

LIST_PAGE, FORM_PAGE, = 0, 1


class DjadminCardInline(admin.TabularInline):
model = DjadminCard


class AdminDjangoModelSettings(admin.ModelAdmin):
list_display = ('model',)
inlines = [DjadminCardInline, ]
Expand Down
13 changes: 6 additions & 7 deletions djadmin/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
class DJMiddleware(MiddlewareMixin):
def process_request(self, request):
request.user_agent = SimpleLazyObject(lambda: get_user_agent(request))
admin_color_theme = settings.ADMIN_COLOR_THEME
ADMIN_COLOR_THEME = get_admin_color_theme(admin_color_theme)
ADMIN_COLOR_THEME_CODE = get_admin_color_theme_hex_code(admin_color_theme)
ALLOW_FORGET_PASSWORD_ADMIN = settings.ALLOW_FORGET_PASSWORD_ADMIN
admin_color_theme = get_admin_color_theme(settings.ADMIN_COLOR_THEME)
admin_color_theme_code = get_admin_color_theme_hex_code(admin_color_theme)
allow_forget_password_admin = settings.ALLOW_FORGET_PASSWORD_ADMIN
AdminSite.site_header = settings.ADMIN_HEADER_TITLE
request.ADMIN_COLOR_THEME = ADMIN_COLOR_THEME
request.ALLOW_FORGET_PASSWORD_ADMIN = ALLOW_FORGET_PASSWORD_ADMIN
request.ADMIN_COLOR_THEME_CODE = ADMIN_COLOR_THEME_CODE
request.ADMIN_COLOR_THEME = admin_color_theme
request.ALLOW_FORGET_PASSWORD_ADMIN = allow_forget_password_admin
request.ADMIN_COLOR_THEME_CODE = admin_color_theme_code
if request.user.is_superuser and settings.DJADMIN_DYNAMIC_FIELD_DISPLAY:
register_model_object_list = get_register_model_with_mixin()
exist_model_object_list = DjadminModelSetting.objects.all()
Expand Down
6 changes: 3 additions & 3 deletions djadmin/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ def changelist_view(self, request, extra_context=None):

self.list_editable = self.djadmin_list_editable
if not self.list_editable:
if (len(ModelsSetting.list_editable.all())):
if len(ModelsSetting.list_editable.all()):
self.list_editable = [field for field in [field.name for field in ModelsSetting.list_editable.all()] if
field in self.list_display and field not in self.list_display_links]

self.search_fields = self.djadmin_search_fields
if not self.search_fields:
if (len(ModelsSetting.search_fields.all())):
if len(ModelsSetting.search_fields.all()):
self.search_fields = [field.name for field in ModelsSetting.search_fields.all()]
else:
self.search_fields = ()
Expand All @@ -176,7 +176,7 @@ def changelist_view(self, request, extra_context=None):
if not self.date_hierarchy:
try:
self.date_hierarchy = ModelsSetting.date_hierarchy.name
except Exception as e:
except Exception:
self.date_hierarchy = None

self.actions_on_top = self.djadmin_actions_on_top
Expand Down
4 changes: 2 additions & 2 deletions djadmin/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ def visitor(sender, user, request, **kwargs):


def get_register_model_with_mixin():
djadmiMixin_inherit_classes = DjadminMixin.__subclasses__()
djadmin_mixin_inherit_classes = DjadminMixin.__subclasses__()
djadmin_mixin_model = []
for model, model_admin in admin.site._registry.items():
if model_admin.__class__ in djadmiMixin_inherit_classes or model_admin.__class__.__name__ == DjadminMixin.__name__:
if model_admin.__class__ in djadmin_mixin_inherit_classes or model_admin.__class__.__name__ == DjadminMixin.__name__:
djadmin_mixin_model.append(model)
return djadmin_mixin_model

Expand Down
29 changes: 29 additions & 0 deletions djadmin/static/admin/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -1392,3 +1392,32 @@ select + .related-widget-wrapper-link,
.clear {
clear: both
}

h4.heading {
line-height: 2.508rem;
margin: 1.14rem 0 0.912rem 0;
font-size: 1.4rem;
font-weight: 400;
padding-top: 64px;
margin-top: -64px;
}

h4.title {
line-height: 2.508rem;
margin: 1.14rem 0 0.912rem 1rem;
font-size: 1.4rem;
font-weight: bold;
text-transform: uppercase;
}

table.docutils > thead > tr, table.docutils > tbody > tr {
border-bottom: 1px solid #d0d0d0
}

table.docutils > tbody > tr:nth-child(odd) {
background-color: #f2f2f2
}

table.docutils > tbody > tr > td {
border-radius: 0px
}
2 changes: 1 addition & 1 deletion djadmin/static/admin/css/materialize.min.css

Large diffs are not rendered by default.

182 changes: 182 additions & 0 deletions djadmin/static/admin/css/prism.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/* http://prismjs.com/download.html?themes=prism&languages=python&plugins=line-numbers */
/**
* prism.js default theme for JavaScript, CSS and HTML
* Based on dabblet (http://dabblet.com)
* @author Lea Verou
*/
tt[class*="language-"],
code[class*="language-"],
pre[class*="language-"] {
color: black;
background: none;
text-shadow: 0 1px white;
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: normal;
word-wrap: normal;
line-height: 1.5;

-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;

-webkit-hyphens: none;
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none;
}

pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection,
tt[class*="language-"]::-moz-selection, tt[class*="language-"] ::-moz-selection,
code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection {
text-shadow: none;
background: #b3d4fc;
}

tt[class*="language-"]::selection, tt[class*="language-"] ::selection,
pre[class*="language-"]::selection, pre[class*="language-"] ::selection,
code[class*="language-"]::selection, code[class*="language-"] ::selection {
text-shadow: none;
background: #b3d4fc;
}

@media print {
tt[class*="language-"],
code[class*="language-"],
pre[class*="language-"] {
text-shadow: none;
}
}

/* Code blocks */
pre[class*="language-"] {
padding: 1em;
margin: .5em 0;
overflow: auto;
}

:not(pre) > code[class*="language-"],
pre[class*="language-"], tt[class*="language-"] {
background: #f5f2f0;
}

/* Inline code */
:not(pre) > code[class*="language-"] {
padding: .1em;
border-radius: .3em;
white-space: normal;
}

.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
color: slategray;
}

.token.punctuation {
color: #999;
}

.namespace {
opacity: .7;
}

.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted {
color: #905;
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
color: #690;
}

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
color: #a67f59;
background: hsla(0, 0%, 100%, .5);
}

.token.atrule,
.token.attr-value,
.token.keyword {
color: #07a;
}

.token.function {
color: #DD4A68;
}

.token.regex,
.token.important,
.token.variable {
color: #e90;
}

.token.important,
.token.bold {
font-weight: bold;
}
.token.italic {
font-style: italic;
}

.token.entity {
cursor: help;
}

pre.line-numbers {
position: relative;
padding-left: 3.8em;
counter-reset: linenumber;
}

pre.line-numbers > code {
position: relative;
}

.line-numbers .line-numbers-rows {
position: absolute;
pointer-events: none;
top: 0;
font-size: 100%;
left: -3.8em;
width: 3em; /* works for line-numbers below 1000 lines */
letter-spacing: -1px;
border-right: 1px solid #999;

-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;

}

.line-numbers-rows > span {
pointer-events: none;
display: block;
counter-increment: linenumber;
}

.line-numbers-rows > span:before {
content: counter(linenumber);
color: #999;
display: block;
padding-right: 0.8em;
text-align: right;
}
4 changes: 4 additions & 0 deletions djadmin/static/admin/js/prism.js

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

9 changes: 9 additions & 0 deletions djadmin/templates/admin_doc/base_docs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "admin/base_site.html" %}
{% load staticfiles %}
{% block navbar-fixed %} navbar-fixed{% endblock %}
{% block extrastyle %}
<link rel="stylesheet" type="text/css" href="{% static "admin/css/prism.css" %}"/>
{% endblock %}
{% block extrajs %}
<script src="{% static "admin/js/prism.js" %}" type="text/javascript"></script>
{% endblock %}
30 changes: 30 additions & 0 deletions djadmin/templates/admin_doc/bookmarklets.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% extends "admin_doc/base_docs.html" %}
{% load i18n %}

{% block breadcrumbs %}
<nav class="{{ request.ADMIN_COLOR_THEME }}">
<div class="nav-wrapper">
<div class="col s12 l12 m12 ">
<a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
&rsaquo; <a href="{% url 'django-admindocs-docroot' %}">{% trans 'Documentation' %}</a>
&rsaquo; {% trans 'Bookmarklets' %}
</div>
</div>
</nav>
{% endblock %}
{% block title %}{% trans "Documentation bookmarklets" %}{% endblock %}

{% block content %}
<div class="card-panel">
<p class="help">{% blocktrans trimmed %}
To install bookmarklets, drag the link to your bookmarks toolbar, or right-click
the link and add it to your bookmarks. Now you can select the bookmarklet
from any page in the site.
{% endblocktrans %}</p>

<div id="content-main">
<h1><a href="javascript:(function(){if(typeof ActiveXObject!='undefined'){x=new ActiveXObject('Microsoft.XMLHTTP')}else if(typeof XMLHttpRequest!='undefined'){x=new XMLHttpRequest()}else{return;}x.open('HEAD',location.href,false);x.send(null);try{view=x.getResponseHeader('x-view');}catch(e){alert('No view found for this page');return;}if(view=='undefined'){alert('No view found for this page');}document.location='{% url 'django-admindocs-views-index' %}'+view+'/';})()">{% trans "Documentation for this page" %}</a></h1>
<p>{% trans "Jumps you from any page to the documentation for the view that generates that page." %}</p>
</div>
</div>
{% endblock %}
Loading

0 comments on commit 467d31b

Please sign in to comment.