# HG changeset patch # User Pawel Solyga # Date 1219187604 0 # Node ID 3f4f7c540b7542d821deadf9262266f8fa3fe59a # Parent 1456e633bf8ab603d5e0c39e7ab4635d838ec6c7 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc). Updated User model helper text. Added basic user profile view (not finished yet). Added css entries for buttons and added buttons background. Added /user/profile and /user/profile/linkname support in urls.py. diff -r 1456e633bf8a -r 3f4f7c540b75 app/soc/content/css/soc.css --- a/app/soc/content/css/soc.css Tue Aug 19 22:37:40 2008 +0000 +++ b/app/soc/content/css/soc.css Tue Aug 19 23:13:24 2008 +0000 @@ -108,7 +108,8 @@ } th, td { - padding: 0; + /*padding: 0;*/ + padding:2px 5px; vertical-align: top; text-align: left; } @@ -130,6 +131,10 @@ td.formfieldheading { font-weight: bold; } + + td.formfieldlabel { + font-weight: bold; + } /* ---------------------------- */ @@ -188,6 +193,29 @@ padding-bottom: 25px; } + #body .buttons { + margin-right: 4px; + margin-top: 20px; + } + + #body a.button, input[type^="submit"], input[type^="button"] { + margin: 0; + padding: 2px 5px 2px 5px; + font-family: Arial, Sans-serif; + font-size: 12px; + text-decoration: none; + color: #222; + cursor: default; + background: #ddd url("/soc/content/images/button-background.gif") repeat-x 0 0; + border: 1px solid #aaa; + } + + #body a.button:hover, input[type^="submit"]:hover, input[type^="button"]:hover { + border-color: #9cf #69e #69e #7af; + } + + + #footer { clear: both; text-align: center; diff -r 1456e633bf8a -r 3f4f7c540b75 app/soc/content/images/button-background.gif Binary file app/soc/content/images/button-background.gif has changed diff -r 1456e633bf8a -r 3f4f7c540b75 app/soc/models/user.py --- a/app/soc/models/user.py Tue Aug 19 22:37:40 2008 +0000 +++ b/app/soc/models/user.py Tue Aug 19 23:13:24 2008 +0000 @@ -61,5 +61,5 @@ link_name = db.StringProperty(required=True, verbose_name=ugettext_lazy('Link name')) link_name.help_text = ugettext_lazy( - 'Required field used in URLs to identify user.' - 'Lower ASCII characters only') + 'Field used in URLs to identify user. ' + 'Lower ASCII characters only.') diff -r 1456e633bf8a -r 3f4f7c540b75 app/soc/templates/soc/base.html --- a/app/soc/templates/soc/base.html Tue Aug 19 22:37:40 2008 +0000 +++ b/app/soc/templates/soc/base.html Tue Aug 19 23:13:24 2008 +0000 @@ -27,8 +27,18 @@
{% block login_links %} - Report bugs | - Sign in + {% if user %} + {{ user.email }} ({{ user.nickname }}) | + {% endif %} + {% if is_dev %} + Admin | + {% endif %} + Report bugs | + {% if user %} + Sign out + {% else %} + Sign in + {% endif %} {% endblock %}
@@ -45,6 +55,9 @@
{% block header_title %}Google Open Source Programs{% endblock %}
+
diff -r 1456e633bf8a -r 3f4f7c540b75 app/soc/templates/soc/templatetags/_field_as_table_row.html --- a/app/soc/templates/soc/templatetags/_field_as_table_row.html Tue Aug 19 22:37:40 2008 +0000 +++ b/app/soc/templates/soc/templatetags/_field_as_table_row.html Tue Aug 19 23:13:24 2008 +0000 @@ -26,7 +26,7 @@ - {% if field.field.required %}required{% endif %} + {% if field.field.required %}(required){% endif %} {{ field }} diff -r 1456e633bf8a -r 3f4f7c540b75 app/soc/templates/soc/user/profile.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/templates/soc/user/profile.html Tue Aug 19 23:13:24 2008 +0000 @@ -0,0 +1,36 @@ +{% extends "soc/base.html" %} +{% comment %} +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +{% endcomment %} +{% load forms_helpers %} +{% block page_title %}User Profile{% endblock %} +{% block header_title %}User Profile{% endblock %} +{% block body %} +

+

+{% block instructions %} +Please use this form to set basic site-wide settings for your participation in Google Open Source Programs. +{% endblock %} +

+
+ + {% field_as_table_row form.nick_name %} + {% field_as_table_row form.link_name %} +
+
+ + +
+
+

+{% endblock %} \ No newline at end of file diff -r 1456e633bf8a -r 3f4f7c540b75 app/soc/views/helpers/response_helpers.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/views/helpers/response_helpers.py Tue Aug 19 23:13:24 2008 +0000 @@ -0,0 +1,73 @@ +#!/usr/bin/python2.5 +# +# Copyright 2008 the Melange authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Helpers used to display various views that are forms. +""" + +__authors__ = [ + '"Pawel Solyga" ', + ] + +import os + +from google.appengine.api import users +from django import http +from django import shortcuts + +IS_DEV = os.environ['SERVER_SOFTWARE'].startswith('Dev') + +# DeadlineExceededError can live in two different places +try: + # When deployed + from google.appengine.runtime import DeadlineExceededError +except ImportError: + # In the development server + from google.appengine.runtime.apiproxy_errors import DeadlineExceededError + +def respond(request, template, params=None): + """Helper to render a response, passing standard stuff to the response. + + Args: + request: The request object. + template: The template name; '.html' is appended automatically. + params: A dict giving the template parameters; modified in-place. + + Returns: + Whatever render_to_response(template, params) returns. + + Raises: + Whatever render_to_response(template, params) raises. + """ + if params is None: + params = {} + + params['request'] = request + params['user'] = users.get_current_user() + params['is_admin'] = users.is_current_user_admin() + params['is_dev'] = IS_DEV + params['sign_in'] = users.create_login_url(request.path) + params['sign_out'] = users.create_logout_url(request.path) + try: + return shortcuts.render_to_response(template, params) + except DeadlineExceededError: + logging.exception('DeadlineExceededError') + return http.HttpResponse('DeadlineExceededError') + except MemoryError: + logging.exception('MemoryError') + return http.HttpResponse('MemoryError') + except AssertionError: + logging.exception('AssertionError') + return http.HttpResponse('AssertionError') \ No newline at end of file diff -r 1456e633bf8a -r 3f4f7c540b75 app/soc/views/user/profile.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/views/user/profile.py Tue Aug 19 23:13:24 2008 +0000 @@ -0,0 +1,72 @@ +#!/usr/bin/python2.5 +# +# Copyright 2008 the Melange authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Views relevant to the User role. +""" + +__authors__ = [ + '"Pawel Solyga" ', + ] + + +from google.appengine.api import users +from django import http +from django import shortcuts +from django import newforms as forms + +from soc.models import user +from soc.views.helpers import forms_helpers +from soc.views.helpers import response_helpers + + +class UserForm(forms_helpers.DbModelForm): + """Django form displayed when creating or editing a User. + """ + + class Meta: + """Inner Meta class that defines some behavior for the form. + """ + #: db.Model subclass for which the form will gather information + model = user.User + + #: list of model fields which will *not* be gathered by the form + exclude = ['id'] + + +def profile(request, linkname=None, template='soc/user/profile.html'): + """View for a User to modify the properties of a UserModel. + + Args: + request: the standard django request object. + template: the template path to use for rendering the template. + + Returns: + A subclass of django.http.HttpResponse which either contains the form to + be filled out, or a redirect to the correct view in the interface. + """ + user = users.get_current_user() + if not user: + return http.HttpResponseRedirect(users.create_login_url(request.path)) + + form = UserForm() + if request.method=='POST': + form = UserForm(request.POST) + + if not form.errors: + return http.HttpResponse('This would update the model') + + return response_helpers.respond(request, + template, {'template': template, 'form': form}) diff -r 1456e633bf8a -r 3f4f7c540b75 app/urls.py --- a/app/urls.py Tue Aug 19 22:37:40 2008 +0000 +++ b/app/urls.py Tue Aug 19 23:13:24 2008 +0000 @@ -24,6 +24,8 @@ urlpatterns = patterns( '', (r'^$', 'soc.views.site.home.public'), + (r'^user/profile$','soc.views.user.profile'), + (r'^user/profile/(?P[_0-9a-z]+)$','soc.views.user.profile'), (r'^org/profile/(?Pghop[_0-9a-z]+)/(?P[_0-9a-z]+)/$', 'soc.views.person.profile.edit', {'template': 'ghop/person/profile/edit.html'}),