damned-lies r1184 - in trunk: . common languages media/css stats teams templates
- From: claudep svn gnome org
- To: svn-commits-list gnome org
- Subject: damned-lies r1184 - in trunk: . common languages media/css stats teams templates
- Date: Sat, 22 Nov 2008 21:53:37 +0000 (UTC)
Author: claudep
Date: Sat Nov 22 21:53:37 2008
New Revision: 1184
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1184&view=rev
Log:
2008-11-22 Claude Paroz <claude 2xlibre net>
* README: Add note about OpenID optional support.
* common/views.py: site_login view handles the login process.
* media/css/login.css: New css specific to login.html.
* media/css/main.css: Add errornote style for showing messages.
* settings_sample.py: Add LOGIN_URL variable (may be used by
login_required decorator).
* languages/views.py:
* stats/views.py:
* teams/views.py: Use more complete RequestContext to be able to access
user variable in templates.
* templates/base.html: Add support for showing user messages and for
adding extra headers (css, js, etc.).
* templates/login.html: New template for login.
* urls.py: Add login view.
Added:
trunk/media/css/login.css
trunk/templates/login.html
Modified:
trunk/ChangeLog
trunk/README
trunk/common/views.py
trunk/languages/views.py
trunk/media/css/main.css
trunk/settings_sample.py
trunk/stats/views.py
trunk/teams/views.py
trunk/templates/base.html
trunk/urls.py
Modified: trunk/README
==============================================================================
--- trunk/README (original)
+++ trunk/README Sat Nov 22 21:53:37 2008
@@ -45,6 +45,15 @@
4 - Configure Sites in admin interface to define the 'View on site'
link.
+OpenID support
+==============
+If you want OpenID support, checkout Simon Willison's django_openid
+package (WIP, part of django-openid, not confuse!):
+svn co http://django-openid.googlecode.com/svn/trunk/django_openid
+Put it somewhere in your Python path and uncomment 'django_openid' in your
+settings.py INSTALLED_APPS.
+Run 'python manage.py syncdb' and here we go!
+
Databases
=========
Modified: trunk/common/views.py
==============================================================================
--- trunk/common/views.py (original)
+++ trunk/common/views.py Sat Nov 22 21:53:37 2008
@@ -19,8 +19,13 @@
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from django.shortcuts import render_to_response
+from django.http import HttpResponseRedirect
+from django.core.urlresolvers import reverse
from django.template import RequestContext
-from django.utils.translation import ugettext_lazy as _
+from django.utils.translation import ugettext as _
+from django.contrib.auth import login, authenticate, logout
+from django.conf import settings
+
def index(request):
translator_credits = _("translator-credits")
@@ -35,3 +40,42 @@
'translator_credits': translator_credits
}
return render_to_response('index.html', context, context_instance=RequestContext(request))
+
+def site_login(request):
+ """ Site-specific login page. Not named 'login' to not confuse with auth.login """
+ messages = []
+ referer = None
+ openid_path = ''
+ if request.method == 'POST':
+ if request.POST.has_key('logout') and request.POST['logout']:
+ logout(request)
+ messages.append(_("You have been logged out."))
+ elif request.POST.has_key('username'):
+ username = request.POST['username']
+ password = request.POST['password']
+ user = authenticate(username=username, password=password)
+ if user is not None:
+ if user.is_active:
+ login(request, user)
+ message = _("You have been successfully logged in.")
+ user.message_set.create(message=message)
+ if request.POST['referer']:
+ return HttpResponseRedirect(request.POST['referer'])
+ else:
+ return HttpResponseRedirect(reverse("home"))
+ else:
+ messages.append(_("We're sorry, but your account has been disabled."))
+ else:
+ messages.append(_("Login unsuccessful. Please verify your username and password."))
+ else:
+ referer = request.META.get('HTTP_REFERER', None)
+
+ if 'django_openid' in settings.INSTALLED_APPS:
+ openid_path = '/openid/'
+ context = {
+ 'pageSection': 'home',
+ 'openid_path': openid_path,
+ 'messages': messages,
+ 'referer': referer,
+ }
+ return render_to_response('login.html', context, context_instance=RequestContext(request))
Modified: trunk/languages/views.py
==============================================================================
--- trunk/languages/views.py (original)
+++ trunk/languages/views.py Sat Nov 22 21:53:37 2008
@@ -23,6 +23,7 @@
import tarfile
from datetime import date, datetime
from django.shortcuts import render_to_response, get_object_or_404
+from django.template import RequestContext
from django.http import HttpResponse, HttpResponseRedirect
from stats.conf import settings
from common import utils
@@ -35,7 +36,7 @@
'pageSection': "languages",
'languages': utils.trans_sort_object_list(languages, 'name')
}
- return render_to_response('languages/language_list.html', context)
+ return render_to_response('languages/language_list.html', context, context_instance=RequestContext(request))
def language_release(request, locale, release_name):
language = get_object_or_404(Language, locale=Language.unslug_locale(locale))
@@ -47,7 +48,7 @@
'release': release,
'stats': stats
}
- return render_to_response('languages/language_release.html', context)
+ return render_to_response('languages/language_release.html', context, context_instance=RequestContext(request))
def language_release_tar(request, locale, release_name, dtype):
release = get_object_or_404(Release, name=release_name)
Added: trunk/media/css/login.css
==============================================================================
--- (empty file)
+++ trunk/media/css/login.css Sat Nov 22 21:53:37 2008
@@ -0,0 +1,9 @@
+/* LOGIN FORM */
+
+.login #container { background:white; border:1px solid #ccc; width:28em; min-width:300px; margin-left:auto; margin-right:auto; margin-top:100px; }
+.login #content-main { width:100%; }
+.login form { margin-top:1em; }
+.login .form-row { padding:4px 0; float:left; width:100%; }
+.login .form-row label { float:left; width:11em; padding-right:0.5em; line-height:1.1em; text-align:right; font-size:1em; color:#333; }
+.login .form-row #id_username, .login .form-row #id_password { width:14em; }
+.login .submit-row { clear:both; padding:1em 0 0 11.4em; }
Modified: trunk/media/css/main.css
==============================================================================
--- trunk/media/css/main.css (original)
+++ trunk/media/css/main.css Sat Nov 22 21:53:37 2008
@@ -123,6 +123,7 @@
div#authenticated {
text-align: right;
+ margin-right: 4px;
font-size: small;
font-style: italic;
color: #aaaaaa;
@@ -148,6 +149,12 @@
color: #666666;
}
+.errornote {
+ border: 1px solid;
+ padding: 5px;
+ background: #FAE28E;
+}
+
.footnote {
text-align: center;
font-size: small;
Modified: trunk/settings_sample.py
==============================================================================
--- trunk/settings_sample.py (original)
+++ trunk/settings_sample.py Sat Nov 22 21:53:37 2008
@@ -69,6 +69,8 @@
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/media/admin/'
+LOGIN_URL = '/login/'
+
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'zk!^92901p458c8lo0(fox-&k7jj(aple76_k%eva7b1)xjo8-'
@@ -98,6 +100,7 @@
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
+# 'django_openid',
'languages',
'people',
'stats',
Modified: trunk/stats/views.py
==============================================================================
--- trunk/stats/views.py (original)
+++ trunk/stats/views.py Sat Nov 22 21:53:37 2008
@@ -21,9 +21,10 @@
from django.shortcuts import render_to_response, get_object_or_404
from stats.models import Statistics, Module, Release
from stats.conf import settings
-from djamnedlies.stats import utils
+from stats import utils
from django.core import serializers
from django.http import HttpResponse
+from django.template import RequestContext
from django.utils.translation import ugettext_lazy as _
MIME_TYPES = {'json': 'application/json',
@@ -35,7 +36,7 @@
'pageSection': "module",
'modules': utils.sortObjectList(all_modules, 'get_description')
}
- return render_to_response('module_list.html', context)
+ return render_to_response('module_list.html', context, context_instance=RequestContext(request))
def module(request, module_name):
mod = get_object_or_404(Module, name=module_name)
@@ -44,7 +45,7 @@
'module': mod,
'prof': utils.Profiler()
}
- return render_to_response('module.html', context)
+ return render_to_response('module.html', context, context_instance=RequestContext(request))
def docimages(request, module_name, potbase, branch_name, langcode):
mod = get_object_or_404(Module, name=module_name)
@@ -58,7 +59,7 @@
'module': mod,
'stat': stat
}
- return render_to_response('module_images.html', context)
+ return render_to_response('module_images.html', context, context_instance=RequestContext(request))
def releases(request, format='html'):
all_releases = Release.objects.order_by('status', '-name')
@@ -70,7 +71,7 @@
'pageSection': "releases",
'releases': all_releases
}
- return render_to_response('release_list.html', context)
+ return render_to_response('release_list.html', context, context_instance=RequestContext(request))
def release(request, release_name):
rel = get_object_or_404(Release, name=release_name)
@@ -78,5 +79,5 @@
'pageSection': "releases",
'release': rel
}
- return render_to_response('release.html', context)
+ return render_to_response('release.html', context, context_instance=RequestContext(request))
Modified: trunk/teams/views.py
==============================================================================
--- trunk/teams/views.py (original)
+++ trunk/teams/views.py Sat Nov 22 21:53:37 2008
@@ -20,6 +20,7 @@
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from django.shortcuts import render_to_response, get_object_or_404
+from django.template import RequestContext
from common import utils
from teams.models import Team, FakeTeam
from languages.models import Language
@@ -31,7 +32,7 @@
'pageSection': 'teams',
'teams': utils.trans_sort_object_list(teams, 'description')
}
- return render_to_response('teams/team_list.html', context)
+ return render_to_response('teams/team_list.html', context, context_instance=RequestContext(request))
def team(request, team_slug):
try:
@@ -44,5 +45,5 @@
'pageSection': 'teams',
'team': team
}
- return render_to_response('teams/team_detail.html', context)
+ return render_to_response('teams/team_detail.html', context, context_instance=RequestContext(request))
Modified: trunk/templates/base.html
==============================================================================
--- trunk/templates/base.html (original)
+++ trunk/templates/base.html Sat Nov 22 21:53:37 2008
@@ -15,6 +15,8 @@
<link rel="stylesheet" href="/media/css/rtl.css"/>
{% endif %}
<script src="/media/js/main.js" type="text/javascript"></script>
+ {% block extrahead %}
+ {% endblock %}
</head>
<body>
@@ -80,11 +82,19 @@
<div id="authenticated">
{% if user.is_authenticated %}
{% blocktrans with user.username as username %} Logged in as: {{ username }}{% endblocktrans %}
+ {% else %}
+ <!-- Not useful right now <a href="{% url login %}">{% trans "Login" %}</a> -->
{% endif %}
</div>
<div class="body">
<div id="content">
+ {% if messages %}
+ {% for message in messages %}
+ <p class="errornote">{{ message }}</p>
+ {% endfor %}
+ {% endif %}
+
{% block content %}
{% endblock %}
</div>
Added: trunk/templates/login.html
==============================================================================
--- (empty file)
+++ trunk/templates/login.html Sat Nov 22 21:53:37 2008
@@ -0,0 +1,51 @@
+{% extends "base.html" %}
+{% load i18n %}
+
+{% block title %} {% trans "Damned Lies about GNOME" %} {% endblock %}
+{% block extrahead %} <link rel="stylesheet" href="/media/css/login.css"/> {% endblock %}
+{% block content %}
+<div class="mainpage">
+
+{% if user.is_authenticated %}
+ <p>{% blocktrans with user.username as username %}You are already logged in as {{ username }}.{% endblocktrans %}</p>
+ <form action="" method="post">
+ <input type="hidden" name="logout" value="1" />
+ <div class="submit-row">
+ <label> </label><input type="submit" value="{% trans 'Log out' %}" />
+ </div>
+ </form>
+{% else %}
+<p>{% trans 'Log in with your username and password:' %}</p>
+<form action="{{ app_path }}" method="post" id="login-form" class="login">
+ <div class="form-row">
+ <label for="id_username">{% trans 'Username:' %}</label> <input type="text" name="username" id="id_username" />
+ </div>
+ <div class="form-row">
+ <label for="id_password">{% trans 'Password:' %}</label> <input type="password" name="password" id="id_password" />
+ <input type="hidden" name="this_is_the_login_form" value="1" />
+ <input type="hidden" name="post_data" value="{{ post_data }}" />
+ <input type="hidden" name="referer" value="{{ referer|default:"" }}" />
+ </div>
+ <div class="submit-row">
+ <label> </label><input type="submit" value="{% trans 'Log in' %}" />
+ </div>
+</form>
+
+{% if openid_path %}
+ <p>{% trans 'Or use your OpenID:' %}</p>
+ <form action="{{ openid_path }}" method="post" id="openid-login-form" class="login">
+ <div class="form-row">
+ <label for="id_openid"><img src="{{ openid_path }}logo/" alt=""> {% trans 'OpenID:' %}</label> <input type="text" name="openid_url" id="id_openid" />
+ </div>
+ <div class="submit-row">
+ <label> </label><input type="submit" value="{% trans 'Log in with OpenID' %}" />
+ </div>
+ </form>
+{% endif %}
+
+<script type="text/javascript">
+document.getElementById('id_username').focus()
+</script>
+{% endif %}
+</div>
+{% endblock %}
Modified: trunk/urls.py
==============================================================================
--- trunk/urls.py (original)
+++ trunk/urls.py Sat Nov 22 21:53:37 2008
@@ -7,6 +7,7 @@
urlpatterns = patterns('',
url(r'^$', 'common.views.index', name='home'),
+ url(r'^login/$', 'common.views.site_login', name='login'),
(r'^teams/', include('teams.urls')),
(r'^people/', include('people.urls')),
(r'^languages/', include('languages.urls')),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]