[Commits] python.it commit r275 - in
code/pythonisti/trunk/pythonisti: . apps/profile media/s
templates/profile
commit a svn.python.it
commit a svn.python.it
Lun 22 Gen 2007 18:52:02 CET
Author: rhymes
Date: Mon Jan 22 18:51:56 2007
New Revision: 275
Added:
code/pythonisti/trunk/pythonisti/apps/profile/forms.py
code/pythonisti/trunk/pythonisti/apps/profile/urls.py
code/pythonisti/trunk/pythonisti/templates/profile/
code/pythonisti/trunk/pythonisti/templates/profile/add_user_profile.html
Modified:
code/pythonisti/trunk/pythonisti/apps/profile/views.py
code/pythonisti/trunk/pythonisti/media/s/form.css
code/pythonisti/trunk/pythonisti/media/s/site.css
code/pythonisti/trunk/pythonisti/settings.py
code/pythonisti/trunk/pythonisti/urls.py
Log:
Add the signup wizard's first page and the stub of the geolocation form (the second page).
Added: code/pythonisti/trunk/pythonisti/apps/profile/forms.py
==============================================================================
--- (empty file)
+++ code/pythonisti/trunk/pythonisti/apps/profile/forms.py Mon Jan 22 18:51:56 2007
@@ -0,0 +1,16 @@
+from django import newforms as forms
+
+class UserRegistrationForm(forms.Form):
+ username = forms.CharField(max_length=30, label="Choose your username")
+ password1 = forms.CharField(widget=forms.PasswordInput, max_length=128, label="Enter password")
+ password2 = forms.CharField(widget=forms.PasswordInput, max_length=128, label="Enter password again")
+ first_name = forms.CharField(max_length=30)
+ last_name = forms.CharField(max_length=30)
+ email = forms.EmailField(label="Enter a valid e-mail address")
+
+class UserGeoLocationForm(forms.Form):
+ address = forms.CharField(label="Address", required=False)
+ city = forms.CharField(label="City")
+ country = forms.CharField(max_length=50, label="Country")
+
+ # TODO: the other fields
Added: code/pythonisti/trunk/pythonisti/apps/profile/urls.py
==============================================================================
--- (empty file)
+++ code/pythonisti/trunk/pythonisti/apps/profile/urls.py Mon Jan 22 18:51:56 2007
@@ -0,0 +1,7 @@
+from django.conf.urls.defaults import *
+from pythonisti.apps.profile import views
+
+urlpatterns = patterns('',
+ (r'^add/$', views.add_user_profile),
+ (r'^add/1/$', views.add_user_profile_location),
+)
Modified: code/pythonisti/trunk/pythonisti/apps/profile/views.py
==============================================================================
--- code/pythonisti/trunk/pythonisti/apps/profile/views.py (original)
+++ code/pythonisti/trunk/pythonisti/apps/profile/views.py Mon Jan 22 18:51:56 2007
@@ -1 +1,59 @@
-# Create your views here.
+from django.shortcuts import render_to_response
+from django.http import HttpResponseRedirect
+from django.contrib.auth.models import User
+from django.newforms.util import ErrorList
+
+from pythonisti.apps.profile import forms
+from pythonisti.apps.profile import models
+
+def add_user_profile(request):
+ if request.method == "POST":
+ form = forms.UserRegistrationForm(request.POST)
+
+ # if the username has already been chosen, chose another one
+ username = request.POST["username"]
+ if username: # used to avoiding wiping out other possible errors
+ is_user_in = bool(User.objects.filter(username=username))
+ if is_user_in:
+ # build up the error for username
+ err_msg = _(u'This username belongs to someone else. Please choose another one')
+ username_errors = ErrorList([err_msg])
+ form.errors["username"] = username_errors
+
+ if form.is_valid():
+ # go to the next step
+ user_data = dict(username=request.POST["username"],
+ password=request.POST["password1"],
+ first_name=request.POST["first_name"],
+ last_name=request.POST["last_name"],
+ email=request.POST["email"])
+ request.session["user_data"] = user_data
+ return HttpResponseRedirect("/user/add/1")
+ else:
+ form = forms.UserRegistrationForm()
+
+ context = {'form': form}
+ return render_to_response("profile/add_user_profile.html", context)
+
+def add_user_profile_location(request):
+ try:
+ referer = request.META["HTTP_REFERER"]
+ # if the user is not coming from the previous page of the
+ # wizard we do the trick and redirect him
+
+ if not referer.endswith("/user/add/"):
+ raise KeyError
+ except KeyError:
+ return HttpResponseRedirect("/")
+
+ # TODO: fill the country field with ip2cc
+ if request.method == "POST":
+ form = forms.UserGeoLocationForm(request.POST)
+
+ if form.is_valid():
+ pass
+ else:
+ form = forms.UserGeoLocationForm()
+
+ context = {'form': form}
+ return render_to_response("profile/add_user_profile.html", context)
Modified: code/pythonisti/trunk/pythonisti/media/s/form.css
==============================================================================
--- code/pythonisti/trunk/pythonisti/media/s/form.css (original)
+++ code/pythonisti/trunk/pythonisti/media/s/form.css Mon Jan 22 18:51:56 2007
@@ -1,5 +1,10 @@
form {
-
+ margin-left: 1em;
+ padding-left: 1em;
+}
+
+.errorlist {
+ color: #f00;
}
fieldset {
Modified: code/pythonisti/trunk/pythonisti/media/s/site.css
==============================================================================
--- code/pythonisti/trunk/pythonisti/media/s/site.css (original)
+++ code/pythonisti/trunk/pythonisti/media/s/site.css Mon Jan 22 18:51:56 2007
@@ -109,3 +109,7 @@
border: none;
}
+
+#content {
+ margin-top: 1.5em;
+}
Modified: code/pythonisti/trunk/pythonisti/settings.py
==============================================================================
--- code/pythonisti/trunk/pythonisti/settings.py (original)
+++ code/pythonisti/trunk/pythonisti/settings.py Mon Jan 22 18:51:56 2007
@@ -23,7 +23,7 @@
# Language code for this installation. All choices can be found here:
# http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes
# http://blogs.law.harvard.edu/tech/stories/storyReader$15
-LANGUAGE_CODE = 'it'
+LANGUAGE_CODE = 'en'
SITE_ID = 1
Added: code/pythonisti/trunk/pythonisti/templates/profile/add_user_profile.html
==============================================================================
--- (empty file)
+++ code/pythonisti/trunk/pythonisti/templates/profile/add_user_profile.html Mon Jan 22 18:51:56 2007
@@ -0,0 +1,22 @@
+{% extends "base.html" %}
+
+{% block title %}
+ Signup | Profile | We do Python
+{% endblock %}
+
+{% block css_head %}
+ <link rel="stylesheet" href="/media/s/form.css" type="text/css" media="screen" />
+{% endblock %}
+
+{% block body_start_tag %}
+ <body>
+{% endblock %}
+
+{% block content %}
+<form action="." method="post">
+ <table class="form">
+ {{ form }}
+ </table>
+ <input type="submit" value="Go to next step" />
+</form>
+{% endblock %}
Modified: code/pythonisti/trunk/pythonisti/urls.py
==============================================================================
--- code/pythonisti/trunk/pythonisti/urls.py (original)
+++ code/pythonisti/trunk/pythonisti/urls.py Mon Jan 22 18:51:56 2007
@@ -5,6 +5,7 @@
(r'^$', 'pythonisti.apps.geo.views.gmap'),
(r'^geo/', include('pythonisti.apps.geo.urls')),
(r'^admin/', include('django.contrib.admin.urls')),
+ (r'^user/', include('pythonisti.apps.profile.urls')),
)
if settings.DEBUG:
Maggiori informazioni sulla lista
Commits