Issue trying to customizing the admin in Django - django

In order to add some links in the admin of my site I added a custom block (surrounded in red in the images below) to admin/base.html and set it in admin/base_site.html.
The issue is that it's shown in all admin pages (eg connexion screenshot shown below), while I'd like to show it only in the site admin first page.
Anybody could help?
admin/base.html
...
<!-- Content -->
<div id="content" class="{% block coltype %}colM{% endblock %}">
{% block pretitle %}{% endblock %}
{% block content_title %}{% if title %}<h1>{{ title }}</h1>{% endif %}{% endblock %}
{% block content %}
{% block object-tools %}{% endblock %}
{{ content }}
{% endblock %}
{% block sidebar %}{% endblock %}
{% block myblock %}{% endblock %} <!-- custom block -->
<br class="clear" />
</div>
<!-- END Content -->
....
admin/base_site.html
....
{% extends "admin/base.html" %}
{% load i18n %}
{% block title %}{{ title }} | {% trans 'Django site admin' %}{% endblock %}
{% block branding %}
<h1 id="site-name">{% trans 'Administration de Django' %}</h1>
{% endblock %}
{% block nav-global %}{% endblock %}
{% block myblock %}
<div style="margin-top:160px;">
<div style="font-size:18px; color:#666666;font-weight:bold;margin-bottom:10px;">Rapports</div>
Rapports journaliers<br/>
Rapports mensuels
</div>
{% endblock %}
....
Site admin
Connexion

Then you are better off overriding admin/index.html

For this purpose I would like to recommend to you django-admin-tools application. As documentation says:
django-admin-tools is a collection of extensions/tools for the default
django administration interface, it includes:
a full featured and customizable dashboard;
a customizable menu bar;
tools to make admin theming easier.
Please join the mailing list if you want to discuss of the future of django-admin-tools.

Related

How to place breadcrumb under Bootstrap3 jumbotron in Django CMS?

How to place breadcrumb under jumbotron? In base.html there is {% block content %} where jumbotron is being called. But if I add inside there
{% block breadcrumb %}
{% show_breadcrumb 0 "cms/breadcrumb.html" 0 %}
{% endblock %}
then nothing shows.
I've tried to insert that in feature.html page like this:
...
{% block content %}
<div class="jumbotron>
{% placeholder "feature" %}
</div>
<div class="breadcrumb">
{% block breadcrumb %}
{% endblock %}
</div>
<div>
{% placeholder "content" %}
</div>
{% endblock %}
But this magic don't shows breadcrumbs :-(
UPD: only thing that is shown is an empty row under jumbotron (in case if I add breadcrumb in feature.html as wrote above).
Its should be:
{% show_breadcrumb 0 "menu/breadcrumb.html" 0 %}
i.e show_breadcrumb with an underscore.
Docs: http://django-cms.readthedocs.org/en/latest/reference/navigation.html#show-breadcrumb
Holy crap, I made it!
I just added {% load cms_tags staticfiles sekizai_tags menu_tags thumbnail %} at the beggining of feature.html and changed a little bit code:
<div class="breadcrumb">
{% block breadcrumb %}
{% show_breadcrumb 0 "cms/breadcrumb.html" 0 %}
{% endblock %}
</div>
Now breadcrumbs shown under jumbotron with slider. Nice!

Djangocms template not showing up

I have a basic DjangoCMS up and running.
base.html contains:
{% block content %}{% endblock content %}
I also have feature.html:
{% extends "base.html" %}
{% load cms_tags %}
{% block title %}{% page_attribute "page_title" %}{% endblock title %}
{% block content %}
<div>
{% placeholder "feature2" %}
</div>
<div class="jumbotron"">
{% placeholder "feature" %}
</div>
<div>
{% placeholder "content" %}
</div>
{% endblock content %}
I added the "feature2" placeholder in the above, and it correctly displays for editing on the site.
I then added a new line to base.html:
{% block base_logo %}{% endblock base_logo %}
and created a new file, base_logo.html:
{% extends "base.html" %}
{% load cms_tags %}
{% block base_logo %}
<div>
{% placeholder logo %}
</div>
{% endblock base_logo %}
I expected this to also appear on the site for editing, but it doesnt. I have added the base_logo.html to the CMS_TEMPLATES in settings.py and TEMPLATE_DIR is also pointing correctly.
What else do I need to do for Djangocms to pick up my new template?
Take a look at template inheritance.
You're trying to use two {% extends %} tags, which won't work. You should use the {% include %} tag for base_logo, because it seems you'd want to include this in many templates. This question provides more info.

Overriding "Add user" header in django admin

How can I change the text at the top of the add user page? I am talking about the text in this section:
I've been reading the docs and searching through the code, but I'm not finding the place to override this.
This text is defined in the admin/auth/user/add_form.html template. To override it create your own template with the same name in your project.
EXAMPLE:
{% extends "admin/change_form.html" %}
{% block content_title %}
<h1>This is the title</h1>
{% endblock %}
{% block form_top %}
<p>This is the subtitle</p>
{% endblock %}
{% block after_field_sets %}
<script type="text/javascript">document.getElementById("id_username").focus();</script>
{% endblock %}

How to display layout content in Twig template based on a view

I have some content in my layout that are not supposed to be displayed in some pages.
E.g.: When a user is registering for the site my default frontpage sidebar should not be displayed:
<!DOCTYPE html>
<html>
<head>
{% block head %}
<link rel="stylesheet" href="style.css" />
<title>{% block title %}{% endblock %} - My Webpage</title>
{% endblock %}
</head>
<body>
<div id="content">
<div id="sidebar">
{% block sidebar %}
{% render "/layout/sidebar" %}
{% endblock %}
{% block content %}{% endblock %}
</div>
</div>
<div id="footer">
{% block footer %}
© Copyright 2011 by you.
{% endblock %}
</div>
</body>
</html>
In the above code:
{% block sidebar %}
should display some advertising instead!
So:
Something like:
{% if SOMEVIEW == TRUE %}
{% block sidebar %}
{% else %}
{% block advertising %}
{% endif %}
What expression could I use in my IF to accomplish that job?
Thanks in advance
You can look at
How to check if an user is logged in Symfony2 inside a controller?
and http://symfony.com/doc/current/book/security.html#access-control-in-templates
In the view you can use {{ is_granted('IS_AUTHENTICATED_FULLY') }} to check if a user is logged in.
Hope it's helpful.
Best regard.
I came accross to the solution here http://symfony.com/doc/current/cmf/bundles/core.html#twig:
app.request.attributes.get('_template').get('name')
will return the route name so that I can handle it inside my twig files.

Django Admin Login Background

how can i change only background image of admin login site in django? i have tried some method but didnt achieved.
i have put base_site.html to under templates\admin.
what is next for coding about background image?
{% extends "admin/base.html" %}
{% load i18n %}
{% block title %}{{ title }} | {% trans 'Django site admin' %}{% endblock %}
{% block extrastyle %}
<style type="text/css">
# body {background-color: #444444;}
</style>
{% endblock %}
{% block branding %}
<h1 id="site-name">{% trans 'Admin Login' %}</h1>
{% endblock %}
{% block nav-global %}{% endblock %}
The correct code is:
{% block extrastyle %}
<style type="text/css">
body.login {background-color: #444444;}
</style>
{% endblock %}
The problem was the # in the css which refers to an id, ie <some_tag id="body"> rather than <body>. body.login targets a body tag with a login class, ie <body class="login">, which is what the django admin site uses to identify the body of just the login screen.