Code reduction, handle already logged in user redirection at the view and not at the template.
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
|
||||
{% block title %} :: {% trans 'About' %}{% endblock %}
|
||||
|
||||
|
||||
{% block stylesheets %}
|
||||
<style>
|
||||
@font-face {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<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-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 %}
|
||||
<script type="text/javascript">
|
||||
@@ -27,10 +27,6 @@
|
||||
</noscript>
|
||||
{% endif %}
|
||||
|
||||
{% if html_redirect %}
|
||||
<META HTTP-EQUIV="refresh" CONTENT="{{ html_redirect_timeout|default:'2' }};{{ html_redirect|safe }}">
|
||||
{% endif %}
|
||||
|
||||
{% compress 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" />
|
||||
|
||||
@@ -5,84 +5,53 @@
|
||||
|
||||
{% load autoadmin_tags %}
|
||||
{% load project_tags %}
|
||||
{% load theme_tags %}
|
||||
|
||||
{% block web_theme_head %}
|
||||
{% if user.is_authenticated %}
|
||||
{% get_login_redirect_url %}
|
||||
<meta http-equiv="REFRESH" content="5;url={{ LOGIN_REDIRECT_URL }}">
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block project_name %}{% endblock %}
|
||||
|
||||
{% block html_title %}{% project_name %} :: {% trans 'Login' %}{% endblock %}
|
||||
{% if user.is_authenticated %}
|
||||
{% block web_theme_content %}
|
||||
{% get_login_redirect_url %}
|
||||
<div class="content">
|
||||
<h2 class="title">{% trans 'You are already logged in' %}</h2>
|
||||
<div class="inner">
|
||||
<p>
|
||||
{% 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>
|
||||
{% block content_plain %}
|
||||
<div class="row">
|
||||
<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">
|
||||
{% auto_admin_properties %}
|
||||
{% if auto_admin_properties.account %}
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">{% trans "First time login" %}</h3>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% else %}
|
||||
{% block content_plain %}
|
||||
<div class="row">
|
||||
<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">
|
||||
{% auto_admin_properties %}
|
||||
{% if auto_admin_properties.account %}
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">{% trans "First time login" %}</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<p>{% trans 'You have just finished installing <strong>Mayan EDMS</strong>, congratulations!' %}</p>
|
||||
<p>{% trans 'Login using the following credentials:' %}</p>
|
||||
<p>{% blocktrans with auto_admin_properties.account as account %}Username: <strong>{{ account }}</strong>{% endblocktrans %}</p>
|
||||
<p>{% blocktrans with auto_admin_properties.account.email as email %}Email: <strong>{{ email }}</strong>{% endblocktrans %}</p>
|
||||
<p>{% blocktrans with auto_admin_properties.password as password %}Password: <strong>{{ password }}</strong>{% endblocktrans %}</p>
|
||||
<p>{% trans 'Be sure to change the password to increase security and to disable this message.' %}</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title"> </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="panel-body">
|
||||
<p>{% trans 'You have just finished installing <strong>Mayan EDMS</strong>, congratulations!' %}</p>
|
||||
<p>{% trans 'Login using the following credentials:' %}</p>
|
||||
<p>{% blocktrans with auto_admin_properties.account as account %}Username: <strong>{{ account }}</strong>{% endblocktrans %}</p>
|
||||
<p>{% blocktrans with auto_admin_properties.account.email as email %}Email: <strong>{{ email }}</strong>{% endblocktrans %}</p>
|
||||
<p>{% blocktrans with auto_admin_properties.password as password %}Password: <strong>{{ password }}</strong>{% endblocktrans %}</p>
|
||||
<p>{% trans 'Be sure to change the password to increase security and to disable this message.' %}</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title"> </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">
|
||||
<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 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>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</form>
|
||||
</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 %}
|
||||
|
||||
@@ -265,10 +265,9 @@ def login_view(request):
|
||||
|
||||
if not request.user.is_authenticated():
|
||||
context = {'web_theme_view_type': 'plain'}
|
||||
return login(request, extra_context=context, **kwargs)
|
||||
else:
|
||||
context = {}
|
||||
|
||||
return login(request, extra_context=context, **kwargs)
|
||||
return HttpResponseRedirect(reverse(getattr(settings, 'LOGIN_REDIRECT_URL', 'main:home')))
|
||||
|
||||
|
||||
def license_view(request):
|
||||
|
||||
@@ -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())))
|
||||
|
||||
new_window_url = None
|
||||
html_redirect = None
|
||||
|
||||
if request.method == 'POST':
|
||||
form = PrintForm(request.POST)
|
||||
@@ -827,7 +826,6 @@ def document_print(request, document_id):
|
||||
'object': document,
|
||||
'title': _('Print: %s') % document,
|
||||
'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
|
||||
}, 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)))
|
||||
Reference in New Issue
Block a user