diff --git a/mgmt/context.py b/mgmt/context.py index 3dae94d..fd7b0d7 100644 --- a/mgmt/context.py +++ b/mgmt/context.py @@ -1,2 +1,34 @@ +#encoding: utf-8 + +import re + +from hms import hms + +show_blocks = dict( + testblk = dict(), + login = dict(hide='/login/$',show_logged=False)) def add_blocks(request): + blocks = {} + logged = request.user.is_authenticated() + for blk in hms.generate('block'): + if blk.name in show_blocks: + show = True + d = show_blocks[blk.name] + hre = d.get('hide',None) + if hre: + if re.match(hre,request.path): + show = False + sre = d.get('show','.*') + if not re.match(sre,request.path): + show = False + if 'show_logged' in d: + if logged != d['show_logged']: + show = False + if show: + blocks[blk.name] = blk.show() + if logged: + log_msg = u'Вы вошли в систему как %s.' % request.user.username + else: + log_msg = u'Вы не вошли.' + return dict(blocks=blocks,login_message=log_msg) diff --git a/mgmt/views.py b/mgmt/views.py index e44d24c..a2e8b5f 100644 --- a/mgmt/views.py +++ b/mgmt/views.py @@ -3,9 +3,22 @@ from datetime import datetime +from django.http import HttpResponse +from django.template import RequestContext +from django.template.loader import get_template from django.shortcuts import render_to_response import django.newforms as forms + from models import * +from context import add_blocks + +def render_it(template,dict,request): + c = RequestContext(request,dict,[add_blocks]) + t = get_template(template) + return HttpResponse(t.render(c)) + +# def render_it(template,dict,request): +# return render_to_response(template,dict) class CommentForm(forms.Form): title = forms.CharField() @@ -22,7 +35,7 @@ class DocForm(forms.Form): def main(request): projects = Project.objects.all() - return render_to_response('main.html',{'projects': projects}) + return render_it('main.html',{'projects': projects},request) def one_project(request,id): project = Project.objects.get(pk=id) @@ -37,10 +50,11 @@ def one_project(request,id): c.save() comments = Comment.objects.filter(object=project) form = CommentForm() - return render_to_response('project.html', + return render_it('project.html', {'project': project, 'comments': comments, - 'form': form}) + 'form': form}, + request) def project_bugs(request,id): project = Project.objects.get(pk=id) @@ -56,17 +70,19 @@ def project_bugs(request,id): b.save() bugs = Bug.objects.filter(project=project) form = BugForm() - return render_to_response('project_bugs.html', + return render_it('project_bugs.html', {'project': project, 'bugs': bugs, - 'form': form}) + 'form': form}, + request) def project_documents(request,id): project = Project.objects.get(pk=id) docs = Document.objects.filter(project=project) - return render_to_response('project_docs.html', + return render_it('project_docs.html', {'project': project, - 'docs': docs}) + 'docs': docs}, + request) def one_document(request,id): doc = Document.objects.get(pk=id) @@ -81,10 +97,11 @@ def one_document(request,id): c.save() comments = Comment.objects.filter(object=doc) form = CommentForm() - return render_to_response('document.html', + return render_it('document.html', {'document': doc, 'comments': comments, - 'form': form}) + 'form': form}, + request) def create_document(request): msg = "" @@ -100,11 +117,13 @@ def create_document(request): d.save() msg = u"Документ создан" form = DocForm() - return render_to_response('create_doc.html', + return render_it('create_doc.html', {'msg': msg, - 'form': form}) + 'form': form}, + request) def all_bugs(request): bugs = Bug.objects.all() - return render_to_response('all_bugs.html', - {'bugs': bugs}) + return render_it('all_bugs.html', + {'bugs': bugs}, + request) diff --git a/settings.py b/settings.py index 7404970..ec9526d 100644 --- a/settings.py +++ b/settings.py @@ -59,6 +59,10 @@ MIDDLEWARE_CLASSES = ( ROOT_URLCONF = 'projects.urls' +TEMPLATE_CONTEXT_PROCESSORS = ( + 'mgmt.context.add_blocks', +) + TEMPLATE_DIRS = ( # Put strings here, like "/home/html/django_templates". # Always use forward slashes, even on Windows. diff --git a/templates/base.html b/templates/base.html index ed1a13f..7ce7761 100644 --- a/templates/base.html +++ b/templates/base.html @@ -14,8 +14,16 @@ <div id='body'> <div id='header'> {%block header%} + {{login_message}} {%endblock%} </div> + + {% if blocks %} + <div id='blocks'> + {{blocks.login|safe}} + {{blocks.testblk|safe}} + </div> + {% endif %} <div id='main'> {% block main %}{% endblock %} diff --git a/templates/registration/logged_out.html b/templates/registration/logged_out.html new file mode 100644 index 0000000..d339ef0 --- /dev/null +++ b/templates/registration/logged_out.html @@ -0,0 +1,12 @@ +{% extends "admin/base_site.html" %} +{% load i18n %} + +{% block breadcrumbs %}<div class="breadcrumbs"><a href="../">{% trans 'Home' %}</a></div>{% endblock %} + +{% block content %} + +<p>{% trans "Thanks for spending some quality time with the Web site today." %}</p> + +<p><a href="../">{% trans 'Log in again' %}</a></p> + +{% endblock %} diff --git a/templates/registration/login.html b/templates/registration/login.html new file mode 100644 index 0000000..bb081bf --- /dev/null +++ b/templates/registration/login.html @@ -0,0 +1,16 @@ +{% extends "base.html" %} + +{% block title %}Вход в систему{% endblock %} + +{% block main %} + +{% if form.errors %} + <p class="error">Сожалеем, вы неправильно ввели логин или пароль</p> +{% endif %} + + <form action='/login/' method='post'> + <p><label for="username">Логин:</label><input type="text" name="username" value="" id="username"/></p> + <p><label for="password">Пароль:</label><input type="password" name="password" value="" id="password"/></p> + <input type="submit" value="login" /> + </form> +{% endblock %} diff --git a/templates/registration/password_change_done.html b/templates/registration/password_change_done.html new file mode 100644 index 0000000..4498c63 --- /dev/null +++ b/templates/registration/password_change_done.html @@ -0,0 +1,13 @@ +{% extends "admin/base_site.html" %} +{% load i18n %} +{% block breadcrumbs %}<div class="breadcrumbs"><a href="../../">{% trans 'Home' %}</a> › {% trans 'Password change' %}</div>{% endblock %} + +{% block title %}{% trans 'Password change successful' %}{% endblock %} + +{% block content %} + +<h1>{% trans 'Password change successful' %}</h1> + +<p>{% trans 'Your password was changed.' %}</p> + +{% endblock %} diff --git a/templates/registration/password_change_form.html b/templates/registration/password_change_form.html new file mode 100644 index 0000000..cd2b1e0 --- /dev/null +++ b/templates/registration/password_change_form.html @@ -0,0 +1,25 @@ +{% extends "admin/base_site.html" %} +{% load i18n %} +{% block breadcrumbs %}<div class="breadcrumbs"><a href="../">{% trans 'Home' %}</a> › {% trans 'Password change' %}</div>{% endblock %} + +{% block title %}{% trans 'Password change' %}{% endblock %} + +{% block content %} + +<h1>{% trans 'Password change' %}</h1> + +<p>{% trans "Please enter your old password, for security's sake, and then enter your new password twice so we can verify you typed it in correctly." %}</p> + +<form action="" method="post"> + +{% if form.old_password.errors %}{{ form.old_password.html_error_list }}{% endif %} +<p class="aligned wide"><label for="id_old_password">{% trans 'Old password:' %}</label>{{ form.old_password }}</p> +{% if form.new_password1.errors %}{{ form.new_password1.html_error_list }}{% endif %} +<p class="aligned wide"><label for="id_new_password1">{% trans 'New password:' %}</label>{{ form.new_password1 }}</p> +{% if form.new_password2.errors %}{{ form.new_password2.html_error_list }}{% endif %} +<p class="aligned wide"><label for="id_new_password2">{% trans 'Confirm password:' %}</label>{{ form.new_password2 }}</p> + +<p><input type="submit" value="{% trans 'Change my password' %}" /></p> +</form> + +{% endblock %} diff --git a/templates/registration/password_reset_done.html b/templates/registration/password_reset_done.html new file mode 100644 index 0000000..f97b568 --- /dev/null +++ b/templates/registration/password_reset_done.html @@ -0,0 +1,14 @@ +{% extends "admin/base_site.html" %} +{% load i18n %} + +{% block breadcrumbs %}<div class="breadcrumbs"><a href="../">{% trans 'Home' %}</a> › {% trans 'Password reset' %}</div>{% endblock %} + +{% block title %}{% trans 'Password reset successful' %}{% endblock %} + +{% block content %} + +<h1>{% trans 'Password reset successful' %}</h1> + +<p>{% trans "We've e-mailed a new password to the e-mail address you submitted. You should be receiving it shortly." %}</p> + +{% endblock %} diff --git a/templates/registration/password_reset_email.html b/templates/registration/password_reset_email.html new file mode 100644 index 0000000..f765dd0 --- /dev/null +++ b/templates/registration/password_reset_email.html @@ -0,0 +1,15 @@ +{% load i18n %} +{% trans "You're receiving this e-mail because you requested a password reset" %} +{% blocktrans %}for your user account at {{ site_name }}{% endblocktrans %}. + +{% blocktrans %}Your new password is: {{ new_password }}{% endblocktrans %} + +{% trans "Feel free to change this password by going to this page:" %} + +http://{{ domain }}/password_change/ + +{% trans "Your username, in case you've forgotten:" %} {{ user.username }} + +{% trans "Thanks for using our site!" %} + +{% blocktrans %}The {{ site_name }} team{% endblocktrans %} diff --git a/templates/registration/password_reset_form.html b/templates/registration/password_reset_form.html new file mode 100644 index 0000000..423821b --- /dev/null +++ b/templates/registration/password_reset_form.html @@ -0,0 +1,19 @@ +{% extends "admin/base_site.html" %} +{% load i18n %} + +{% block breadcrumbs %}<div class="breadcrumbs"><a href="../">{% trans 'Home' %}</a> › {% trans 'Password reset' %}</div>{% endblock %} + +{% block title %}{% trans "Password reset" %}{% endblock %} + +{% block content %} + +<h1>{% trans "Password reset" %}</h1> + +<p>{% trans "Forgotten your password? Enter your e-mail address below, and we'll reset your password and e-mail the new one to you." %}</p> + +<form action="" method="post"> +{% if form.email.errors %}{{ form.email.html_error_list }}{% endif %} +<p><label for="id_email">{% trans 'E-mail address:' %}</label> {{ form.email }} <input type="submit" value="{% trans 'Reset my password' %}" /></p> +</form> + +{% endblock %} diff --git a/urls.py b/urls.py index 36a9e1d..b18b1ad 100644 --- a/urls.py +++ b/urls.py @@ -1,14 +1,17 @@ from django.conf.urls.defaults import * -from mgmt.views import * +from django.contrib.auth.views import login, logout urlpatterns = patterns('', - (r'^$', main), - (r'^projects/(\d+)/$', one_project), - (r'^projects/(\d+)/bugs/$', project_bugs), - (r'^projects/(\d+)/docs/$', project_documents), - (r'^docs/(\d+)/$', one_document), - (r'^bugs/$', all_bugs), - (r'^create/doc/$', create_document), + (r'^$', "mgmt.views.main"), + (r'^projects/(\d+)/$', "mgmt.views.one_project"), + (r'^projects/(\d+)/bugs/$', "mgmt.views.project_bugs"), + (r'^projects/(\d+)/docs/$', "mgmt.views.project_documents"), + (r'^docs/(\d+)/$', "mgmt.views.one_document"), + (r'^bugs/$', "mgmt.views.all_bugs"), + (r'^create/doc/$', "mgmt.views.create_document"), + + (r'^login/', login), + (r'^logout/', logout), (r'^admin/', include('django.contrib.admin.urls')), )