From c7dbb750031ae5b8bcdf22a66e3b2fa3e2740a48 Mon Sep 17 00:00:00 2001 From: Thomas NOEL Date: Sun, 13 May 2012 17:09:40 +0200 Subject: [PATCH] login/logout logic (sort of) --- .gitignore | 1 + polynum/pages/__init__.py | 0 polynum/pages/models.py | 3 ++ .../bootstrap/css/bootstrap-responsive.css | 0 .../css/bootstrap-responsive.min.css | 0 .../static/bootstrap/css/bootstrap.css | 0 .../static/bootstrap/css/bootstrap.min.css | 0 .../img/glyphicons-halflings-white.png | Bin .../bootstrap/img/glyphicons-halflings.png | Bin .../static/bootstrap/js/bootstrap.js | 0 .../static/bootstrap/js/bootstrap.min.js | 0 .../static/dauphine/img/favicon.ico | Bin .../static/html5shim/js/html5.js | 0 .../static/jquery/js/jquery-1.7.2.min.js | 0 .../static/jquery/js/jquery.js | 0 polynum/pages/urls.py | 7 ++++ polynum/pages/views.py | 5 +++ .../wizard_form.html => new_request.html} | 5 ++- polynum/request/views.py | 6 ++- polynum/settings.py | 21 +++++++++-- polynum/{request => }/templates/base.html | 35 ++++++++---------- polynum/templates/homepage.html | 33 +++++++++++++++++ polynum/templates/login.html | 26 +++++++++++++ polynum/templates/logout.html | 11 ++++++ polynum/urls.py | 6 ++- 25 files changed, 132 insertions(+), 27 deletions(-) create mode 100644 polynum/pages/__init__.py create mode 100644 polynum/pages/models.py rename polynum/{request => pages}/static/bootstrap/css/bootstrap-responsive.css (100%) rename polynum/{request => pages}/static/bootstrap/css/bootstrap-responsive.min.css (100%) rename polynum/{request => pages}/static/bootstrap/css/bootstrap.css (100%) rename polynum/{request => pages}/static/bootstrap/css/bootstrap.min.css (100%) rename polynum/{request => pages}/static/bootstrap/img/glyphicons-halflings-white.png (100%) rename polynum/{request => pages}/static/bootstrap/img/glyphicons-halflings.png (100%) rename polynum/{request => pages}/static/bootstrap/js/bootstrap.js (100%) rename polynum/{request => pages}/static/bootstrap/js/bootstrap.min.js (100%) rename polynum/{request => pages}/static/dauphine/img/favicon.ico (100%) rename polynum/{request => pages}/static/html5shim/js/html5.js (100%) rename polynum/{request => pages}/static/jquery/js/jquery-1.7.2.min.js (100%) rename polynum/{request => pages}/static/jquery/js/jquery.js (100%) create mode 100644 polynum/pages/urls.py create mode 100644 polynum/pages/views.py rename polynum/request/templates/{formtools/wizard/wizard_form.html => new_request.html} (92%) rename polynum/{request => }/templates/base.html (83%) create mode 100644 polynum/templates/homepage.html create mode 100644 polynum/templates/login.html create mode 100644 polynum/templates/logout.html diff --git a/.gitignore b/.gitignore index 33d3c4e..f64df72 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.pyc polynum.db +polynum/static diff --git a/polynum/pages/__init__.py b/polynum/pages/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/polynum/pages/models.py b/polynum/pages/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/polynum/pages/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/polynum/request/static/bootstrap/css/bootstrap-responsive.css b/polynum/pages/static/bootstrap/css/bootstrap-responsive.css similarity index 100% rename from polynum/request/static/bootstrap/css/bootstrap-responsive.css rename to polynum/pages/static/bootstrap/css/bootstrap-responsive.css diff --git a/polynum/request/static/bootstrap/css/bootstrap-responsive.min.css b/polynum/pages/static/bootstrap/css/bootstrap-responsive.min.css similarity index 100% rename from polynum/request/static/bootstrap/css/bootstrap-responsive.min.css rename to polynum/pages/static/bootstrap/css/bootstrap-responsive.min.css diff --git a/polynum/request/static/bootstrap/css/bootstrap.css b/polynum/pages/static/bootstrap/css/bootstrap.css similarity index 100% rename from polynum/request/static/bootstrap/css/bootstrap.css rename to polynum/pages/static/bootstrap/css/bootstrap.css diff --git a/polynum/request/static/bootstrap/css/bootstrap.min.css b/polynum/pages/static/bootstrap/css/bootstrap.min.css similarity index 100% rename from polynum/request/static/bootstrap/css/bootstrap.min.css rename to polynum/pages/static/bootstrap/css/bootstrap.min.css diff --git a/polynum/request/static/bootstrap/img/glyphicons-halflings-white.png b/polynum/pages/static/bootstrap/img/glyphicons-halflings-white.png similarity index 100% rename from polynum/request/static/bootstrap/img/glyphicons-halflings-white.png rename to polynum/pages/static/bootstrap/img/glyphicons-halflings-white.png diff --git a/polynum/request/static/bootstrap/img/glyphicons-halflings.png b/polynum/pages/static/bootstrap/img/glyphicons-halflings.png similarity index 100% rename from polynum/request/static/bootstrap/img/glyphicons-halflings.png rename to polynum/pages/static/bootstrap/img/glyphicons-halflings.png diff --git a/polynum/request/static/bootstrap/js/bootstrap.js b/polynum/pages/static/bootstrap/js/bootstrap.js similarity index 100% rename from polynum/request/static/bootstrap/js/bootstrap.js rename to polynum/pages/static/bootstrap/js/bootstrap.js diff --git a/polynum/request/static/bootstrap/js/bootstrap.min.js b/polynum/pages/static/bootstrap/js/bootstrap.min.js similarity index 100% rename from polynum/request/static/bootstrap/js/bootstrap.min.js rename to polynum/pages/static/bootstrap/js/bootstrap.min.js diff --git a/polynum/request/static/dauphine/img/favicon.ico b/polynum/pages/static/dauphine/img/favicon.ico similarity index 100% rename from polynum/request/static/dauphine/img/favicon.ico rename to polynum/pages/static/dauphine/img/favicon.ico diff --git a/polynum/request/static/html5shim/js/html5.js b/polynum/pages/static/html5shim/js/html5.js similarity index 100% rename from polynum/request/static/html5shim/js/html5.js rename to polynum/pages/static/html5shim/js/html5.js diff --git a/polynum/request/static/jquery/js/jquery-1.7.2.min.js b/polynum/pages/static/jquery/js/jquery-1.7.2.min.js similarity index 100% rename from polynum/request/static/jquery/js/jquery-1.7.2.min.js rename to polynum/pages/static/jquery/js/jquery-1.7.2.min.js diff --git a/polynum/request/static/jquery/js/jquery.js b/polynum/pages/static/jquery/js/jquery.js similarity index 100% rename from polynum/request/static/jquery/js/jquery.js rename to polynum/pages/static/jquery/js/jquery.js diff --git a/polynum/pages/urls.py b/polynum/pages/urls.py new file mode 100644 index 0000000..f65aec9 --- /dev/null +++ b/polynum/pages/urls.py @@ -0,0 +1,7 @@ +from django.conf.urls import url, patterns +import views + +urlpatterns = patterns('', + url(r'^/*$', views.homepage, name='homepage'), +) + diff --git a/polynum/pages/views.py b/polynum/pages/views.py new file mode 100644 index 0000000..74656f9 --- /dev/null +++ b/polynum/pages/views.py @@ -0,0 +1,5 @@ +from django.shortcuts import render, redirect + +def homepage(request): + return render(request, 'homepage.html') + diff --git a/polynum/request/templates/formtools/wizard/wizard_form.html b/polynum/request/templates/new_request.html similarity index 92% rename from polynum/request/templates/formtools/wizard/wizard_form.html rename to polynum/request/templates/new_request.html index b6ecbd9..0a2b72d 100644 --- a/polynum/request/templates/formtools/wizard/wizard_form.html +++ b/polynum/request/templates/new_request.html @@ -8,7 +8,8 @@ {{ wizard.form.media }} {% endblock %} -{% block body %} +{% block content %} +

Étape {{ wizard.steps.step1 }} sur {{ wizard.steps.count }}

@@ -36,4 +37,6 @@ +
+ {% endblock %} diff --git a/polynum/request/views.py b/polynum/request/views.py index 771cb7d..14ef909 100644 --- a/polynum/request/views.py +++ b/polynum/request/views.py @@ -1,6 +1,7 @@ from django.shortcuts import redirect from django.contrib.formtools.wizard.views import NamedUrlSessionWizardView from django.core.files.storage import FileSystemStorage +from django.contrib.auth.decorators import login_required from forms import DocumentUploadForm, DocumentDetailsForm @@ -14,6 +15,7 @@ named_new_request_forms = ( class RequestWizardView(NamedUrlSessionWizardView): + template_name = 'new_request.html' file_storage = FileSystemStorage(location = '/tmp/pdf/') def done(self, form_list, **kwargs): @@ -32,7 +34,7 @@ class RequestWizardView(NamedUrlSessionWizardView): return initial -new_request_wizard = RequestWizardView.as_view(named_new_request_forms, +new_request_wizard = login_required(RequestWizardView.as_view(named_new_request_forms, url_name='new_request_step', - done_step_name='new_request_finished') + done_step_name='new_request_finished')) diff --git a/polynum/settings.py b/polynum/settings.py index fd0d948..e4c67af 100644 --- a/polynum/settings.py +++ b/polynum/settings.py @@ -1,5 +1,10 @@ # Django settings for polynum project. +import os.path +import django.conf.global_settings as DEFAULT_SETTINGS + +PROJECT_ROOT = os.path.join(os.path.dirname(__file__), '.') + DEBUG = True TEMPLATE_DEBUG = DEBUG @@ -48,18 +53,18 @@ USE_TZ = True # Absolute filesystem path to the directory that will hold user-uploaded files. # Example: "/home/media/media.lawrence.com/media/" -MEDIA_ROOT = '' +MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media') # URL that handles the media served from MEDIA_ROOT. Make sure to use a # trailing slash. # Examples: "http://media.lawrence.com/media/", "http://example.com/media/" -MEDIA_URL = '' +MEDIA_URL = '/media/' # Absolute path to the directory static files should be collected to. # Don't put anything in this directory yourself; store your static files # in apps' "static/" subdirectories and in STATICFILES_DIRS. # Example: "/home/media/media.lawrence.com/static/" -STATIC_ROOT = '' +STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static') # URL prefix for static files. # Example: "http://media.lawrence.com/static/" @@ -109,6 +114,7 @@ TEMPLATE_DIRS = ( # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. + os.path.join(PROJECT_ROOT, "templates"), ) INSTALLED_APPS = ( @@ -119,12 +125,13 @@ INSTALLED_APPS = ( 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.admin', + 'django.contrib.formtools', # 'django.contrib.admindocs', 'mptt', 'crispy_forms', + 'polynum.pages', 'polynum.base', 'polynum.request', - 'django.contrib.formtools', ) # From http://django-crispy-forms.readthedocs.org/en/d-0/install.html @@ -158,3 +165,9 @@ LOGGING = { }, } } + +try: + from local_settings import * +except: + pass + diff --git a/polynum/request/templates/base.html b/polynum/templates/base.html similarity index 83% rename from polynum/request/templates/base.html rename to polynum/templates/base.html index ed0a5a0..e0122a8 100644 --- a/polynum/request/templates/base.html +++ b/polynum/templates/base.html @@ -41,13 +41,14 @@ - - PolyNum -
- - Connexion - - + + PolyNum +
+ {% if user.is_authenticated %} + Déconnexion de «{{user}}» + {% else %} + Connexion + {% endif %}
-
- {% block body %}{% endblock %} -
+ {% block content %}{% endblock %}
diff --git a/polynum/templates/homepage.html b/polynum/templates/homepage.html new file mode 100644 index 0000000..2f4d74e --- /dev/null +++ b/polynum/templates/homepage.html @@ -0,0 +1,33 @@ +{% extends "base.html" %} + +{% block content %} +
+

PolyNum

+

Polycopiés numériques

+
+ +
+ {% if user.is_authenticated %} + Bienvenue, {{ user }} +{% else %} +
+

Demande

+

Pour faire une demande de reprographie, cliquez sur + nouvelle demande.

+

Vous pouvez ensuite suivre l'état de vos demandes dans votre + tableau de bord.

+
+ +
+

Validation

+

Consultez votre tableau de bord.

+
+ +
+

Reprographie

+

Consultez votre tableau de bord.

+
+{% endif %} +
+ +{% endblock %} diff --git a/polynum/templates/login.html b/polynum/templates/login.html new file mode 100644 index 0000000..c560bcc --- /dev/null +++ b/polynum/templates/login.html @@ -0,0 +1,26 @@ +{% extends "base.html" %} + +{% block content %} +
+ + {% if form.errors %} +

Utilisateur inconnu, ou mauvais mot de passe... Recommancez.

+ {% endif %} + +
+ {% csrf_token %} + + + + + + + +
{{ form.username.label_tag }} {{ form.username }}
{{ form.password.label_tag }} {{ form.password }}
+ + + +
+
+ +{% endblock %} diff --git a/polynum/templates/logout.html b/polynum/templates/logout.html new file mode 100644 index 0000000..8fd493b --- /dev/null +++ b/polynum/templates/logout.html @@ -0,0 +1,11 @@ +{% extends "base.html" %} + +{% block content %} +
+ +

Au revoir...

+ + +
+ +{% endblock %} diff --git a/polynum/urls.py b/polynum/urls.py index b467af3..56aa296 100644 --- a/polynum/urls.py +++ b/polynum/urls.py @@ -12,7 +12,11 @@ urlpatterns = patterns('', # Uncomment the admin/doc line below to enable admin documentation: # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), - # Uncomment the next line to enable the admin: url(r'^admin/', include(admin.site.urls)), + + url(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}, name='login'), + url(r'^accounts/logout/$', 'django.contrib.auth.views.logout', {'template_name': 'logout.html'}, name='logout'), + url(r'^request/', include('polynum.request.urls')), + url(r'^', include('polynum.pages.urls')), )