Code reduction, handle already logged in user redirection at the view and not at the template.

This commit is contained in:
Roberto Rosario
2015-04-01 14:18:05 -04:00
parent 338ac53c0f
commit e4bb97aaed
7 changed files with 41 additions and 104 deletions
@@ -8,7 +8,6 @@
{% block title %} :: {% trans 'About' %}{% endblock %} {% block title %} :: {% trans 'About' %}{% endblock %}
{% block stylesheets %} {% block stylesheets %}
<style> <style>
@font-face { @font-face {
@@ -16,7 +16,7 @@
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"> <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="{{ LANGUAGE_CODE }}" /> <meta http-equiv="Content-Language" content="{{ LANGUAGE_CODE }}" />
<title>{% project_name %}{{ request.new_window_url }}{% block title %}{% endblock %}</title> <title>{% block project_name %}{% project_name %}{% endblock %}{{ request.new_window_url }}{% block title %}{% endblock %}</title>
{% if new_window_url %} {% if new_window_url %}
<script type="text/javascript"> <script type="text/javascript">
@@ -27,10 +27,6 @@
</noscript> </noscript>
{% endif %} {% endif %}
{% if html_redirect %}
<META HTTP-EQUIV="refresh" CONTENT="{{ html_redirect_timeout|default:'2' }};{{ html_redirect|safe }}">
{% endif %}
{% compress css %} {% compress css %}
<link href="http://fonts.googleapis.com/css?family=IM+Fell+English+SC" rel="stylesheet" type="text/css"> <link href="http://fonts.googleapis.com/css?family=IM+Fell+English+SC" rel="stylesheet" type="text/css">
<link href="{% static 'appearance/packages/font-awesome-4.3.0/css/font-awesome.min.css' %}" media="screen" rel="stylesheet" type="text/css" /> <link href="{% static 'appearance/packages/font-awesome-4.3.0/css/font-awesome.min.css' %}" media="screen" rel="stylesheet" type="text/css" />
@@ -5,84 +5,53 @@
{% load autoadmin_tags %} {% load autoadmin_tags %}
{% load project_tags %} {% load project_tags %}
{% load theme_tags %}
{% block web_theme_head %} {% block project_name %}{% endblock %}
{% if user.is_authenticated %}
{% get_login_redirect_url %}
<meta http-equiv="REFRESH" content="5;url={{ LOGIN_REDIRECT_URL }}">
{% endif %}
{% endblock %}
{% block html_title %}{% project_name %} :: {% trans 'Login' %}{% endblock %} {% block content_plain %}
{% if user.is_authenticated %} <div class="row">
{% block web_theme_content %} <div class="col-xs-10 col-xs-offset-1 col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3 col-lg-4 col-lg-offset-4">
{% get_login_redirect_url %} {% auto_admin_properties %}
<div class="content"> {% if auto_admin_properties.account %}
<h2 class="title">{% trans 'You are already logged in' %}</h2> <div class="panel panel-primary">
<div class="inner"> <div class="panel-heading">
<p> <h3 class="panel-title">{% trans "First time login" %}</h3>
{% trans 'Redirecting you to the website entry point in 5 seconds.' %}
<p>
</p>
{% blocktrans %}Or click <a href="{{ LOGIN_REDIRECT_URL }}">here</a> if redirection doesn't work.{% endblocktrans %}
</p>
</div>
</div> </div>
{% endblock %} <div class="panel-body">
{% else %} <p>{% trans 'You have just finished installing <strong>Mayan EDMS</strong>, congratulations!' %}</p>
{% block content_plain %} <p>{% trans 'Login using the following credentials:' %}</p>
<div class="row"> <p>{% blocktrans with auto_admin_properties.account as account %}Username: <strong>{{ account }}</strong>{% endblocktrans %}</p>
<div class="col-xs-10 col-xs-offset-1 col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3 col-lg-4 col-lg-offset-4"> <p>{% blocktrans with auto_admin_properties.account.email as email %}Email: <strong>{{ email }}</strong>{% endblocktrans %}</p>
{% auto_admin_properties %} <p>{% blocktrans with auto_admin_properties.password as password %}Password: <strong>{{ password }}</strong>{% endblocktrans %}</p>
{% if auto_admin_properties.account %} <p>{% trans 'Be sure to change the password to increase security and to disable this message.' %}</p>
<div class="panel panel-primary"> </div>
<div class="panel-heading"> </div>
<h3 class="panel-title">{% trans "First time login" %}</h3> {% endif %}
</div> <div class="panel panel-primary">
<div class="panel-body"> <div class="panel-heading">
<p>{% trans 'You have just finished installing <strong>Mayan EDMS</strong>, congratulations!' %}</p> <h3 class="panel-title">&nbsp;</h3>
<p>{% trans 'Login using the following credentials:' %}</p> </div>
<p>{% blocktrans with auto_admin_properties.account as account %}Username: <strong>{{ account }}</strong>{% endblocktrans %}</p> <div class="panel-body">
<p>{% blocktrans with auto_admin_properties.account.email as email %}Email: <strong>{{ email }}</strong>{% endblocktrans %}</p> <h2>{% trans 'Sign in' %}</h2>
<p>{% blocktrans with auto_admin_properties.password as password %}Password: <strong>{{ password }}</strong>{% endblocktrans %}</p> <hr>
<p>{% trans 'Be sure to change the password to increase security and to disable this message.' %}</p> <div class="content login">
</div> <form action="." method="post" class="form login">{% csrf_token %}
</div> <div class="group wat-cf">
{% endif %} {% include 'appearance/generic_form_instance.html' %}
<div class="panel panel-primary"> <input type="hidden" name="next" value="{{ next|escape }}" />
<div class="panel-heading">
<h3 class="panel-title">&nbsp;</h3>
</div>
<div class="panel-body">
<h2>{% trans 'Sign in' %}</h2>
<hr>
<div class="content login">
<form action="." method="post" class="form login">{% csrf_token %}
<div class="group wat-cf">
{% include 'appearance/generic_form_instance.html' %}
<input type="hidden" name="next" value="{{ next|escape }}" />
<div class="form-group"> <div class="form-group">
<button class="btn btn-primary" name="{% if form.prefix %}{{ form.prefix }}-submit{% else %}submit{% endif %}" type="submit"><i class="fa fa-sign-in"></i> {% trans 'Sign in' %}</button> <button class="btn btn-primary" name="{% if form.prefix %}{{ form.prefix }}-submit{% else %}submit{% endif %}" type="submit"><i class="fa fa-sign-in"></i> {% trans 'Sign in' %}</button>
</div>
</form>
</div> </div>
</form>
</div>
</div> </div>
</div> </div>
</div> </div>
{% endblock %}
{% endif %}
{% block web_theme_stylesheets %}
<style>
input#id_email { width: 100%; }
</style>
{% endblock web_theme_stylesheets %}
{% block project_name %}{% endblock %}
</div>
</div>
{% endblock %}
+2 -3
View File
@@ -265,10 +265,9 @@ def login_view(request):
if not request.user.is_authenticated(): if not request.user.is_authenticated():
context = {'web_theme_view_type': 'plain'} context = {'web_theme_view_type': 'plain'}
return login(request, extra_context=context, **kwargs)
else: else:
context = {} return HttpResponseRedirect(reverse(getattr(settings, 'LOGIN_REDIRECT_URL', 'main:home')))
return login(request, extra_context=context, **kwargs)
def license_view(request): def license_view(request):
-2
View File
@@ -804,7 +804,6 @@ def document_print(request, document_id):
next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', post_redirect or document.get_absolute_url()))) next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', post_redirect or document.get_absolute_url())))
new_window_url = None new_window_url = None
html_redirect = None
if request.method == 'POST': if request.method == 'POST':
form = PrintForm(request.POST) form = PrintForm(request.POST)
@@ -827,7 +826,6 @@ def document_print(request, document_id):
'object': document, 'object': document,
'title': _('Print: %s') % document, 'title': _('Print: %s') % document,
'next': next, 'next': next,
'html_redirect': html_redirect if html_redirect else html_redirect,
'new_window_url': new_window_url if new_window_url else new_window_url 'new_window_url': new_window_url if new_window_url else new_window_url
}, context_instance=RequestContext(request)) }, context_instance=RequestContext(request))
@@ -1,24 +0,0 @@
from __future__ import unicode_literals
from django.conf import settings
from django.core.urlresolvers import reverse
from django.template import Library, Node
from django.utils.safestring import mark_safe
register = Library()
class LoginRedirectNode(Node):
def render(self, context):
context['LOGIN_REDIRECT_URL'] = getattr(settings, 'LOGIN_REDIRECT_URL', reverse('main:home'))
return ''
@register.tag
def get_login_redirect_url(parser, token):
return LoginRedirectNode()
@register.filter
def highlight(text, word):
return mark_safe(unicode(text).replace(word, mark_safe('<mark>%s</mark>' % word)))