Finished migrating the "proto" app (which only contained a Person profile edit
authorTodd Larsen <tlarsen@google.com>
Mon, 11 Aug 2008 16:57:46 +0000
changeset 66 8c86470746fc
parent 65 d254d4577c30
child 67 a05bb313cda5
Finished migrating the "proto" app (which only contained a Person profile edit form) to the new combined trunk/app layout. Also, moved the form template from profile.html to profile/edit.html, to follow the "one template per view" approach (rather than have read-write vs. read-only logic in a single template).
app/ghop/content/css/ghop.css
app/ghop/content/images/ghop.jpg
app/ghop/templates/ghop/person/profile.html
app/ghop/templates/ghop/person/profile/edit.html
app/settings.py
app/soc/templates/soc/person/profile.html
app/soc/templates/soc/person/profile/edit.html
app/soc/views/person/__init__.py
app/soc/views/person/profile.py
app/urls.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/ghop/content/css/ghop.css	Mon Aug 11 16:57:46 2008 +0000
@@ -0,0 +1,36 @@
+/*
+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.
+ */
+
+body {
+  font-family: Verdana, Helvetica, sans-serif;
+  background-color: #DDDD00;
+}
+
+td.formfieldrequired {
+ font-style: italic;
+}
+
+td.formfieldhelptext {
+ font-style: italic;
+}
+
+td.formfielderror {
+ color: #FF0000;
+}
+
+td.formfieldheading {
+ font-weight: bold;
+}
Binary file app/ghop/content/images/ghop.jpg has changed
--- a/app/ghop/templates/ghop/person/profile.html	Mon Aug 11 16:44:47 2008 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-{% extends 'soc/person/profile.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 %}
-{% block 'stylesheet' %}
-<link rel="stylesheet" type="text/css" href="/content/proto.css" />
-{% endblock %}
-{% block 'logo' %}
-<img src="/content/logo.jpg" alt="Melange" />
-{% endblock %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/ghop/templates/ghop/person/profile/edit.html	Mon Aug 11 16:57:46 2008 +0000
@@ -0,0 +1,26 @@
+{% extends 'soc/person/profile/edit.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 %}
+{% block 'stylesheet' %}
+<link rel="stylesheet" type="text/css" href="/ghop/content/css/ghop.css" />
+{% endblock %}
+{% block 'logo' %}
+<img src="/ghop/content/images/ghop.jpg" alt="GHOP" />
+{% endblock %}
+{% block 'greeting' %}
+Welcome, {{linkname}} ({{user.nickname}}).
+{% endblock %}
+{% block 'instructions' %}
+Please update your profile for the {{program}} program:
+{% endblock %}
--- a/app/settings.py	Mon Aug 11 16:44:47 2008 +0000
+++ b/app/settings.py	Mon Aug 11 16:57:46 2008 +0000
@@ -93,7 +93,8 @@
 ROOT_PATH = os.path.dirname(__file__)
 TEMPLATE_DIRS = (
     # TODO(proto): customize the template search directories
-    os.path.join(ROOT_PATH, 'proto', 'templates'),
+    os.path.join(ROOT_PATH, 'ghop', 'templates'),
+    os.path.join(ROOT_PATH, 'gsoc', 'templates'),
     os.path.join(ROOT_PATH, 'soc', 'templates'),
 )
 
--- a/app/soc/templates/soc/person/profile.html	Mon Aug 11 16:44:47 2008 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,103 +0,0 @@
-{% 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 %}
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
-<html lang="en">
- <head>
-  <title>Profile</title>
-  {% block 'stylesheet' %}{% endblock %}
- </head>
- <body>
-  <p>
-   {% block 'logo' %}{% endblock %}
-   Welcome, {{user.nickname}}.
-   {% block 'instructions' %}Please update your profile:{% endblock %}
-   <form method="POST">
-    <table>
-     <tr>
-      <td class="formfieldheading" colspan="4">
-       Name <i>(publicly displayed)</i>
-      </td>
-     </tr>
-     {% field_as_table_row form.given_name %}
-     {% field_as_table_row form.surname %}
-     {% field_as_table_row form.nickname %}
-     {% field_as_table_row form.display_name %}
-     <tr><td colspan="4">&nbsp;</td></tr>
-
-     <tr>
-      <td class="formfieldheading" colspan="4">
-       Online Profile <i>(publicly displayed)</i>
-      </td>
-     </tr>
-     {% field_as_table_row form.email %}
-     {% field_as_table_row form.im_network %}
-     {% field_as_table_row form.im_handle %}
-     {% field_as_table_row form.home_page %}
-     {% field_as_table_row form.blog %}
-     {% field_as_table_row form.photo_url %}
-     <tr><td colspan="4">&nbsp;</td></tr>
-
-     <tr>
-      <td class="formfieldheading" colspan="4">
-       Location <i>(publicly displayed, these will be replaced with a
-                    Google Maps control)</i>
-      </td>
-     </tr>
-     {% field_as_table_row form.latitude %}
-     {% field_as_table_row form.longitude %}
-     <tr><td colspan="4">&nbsp;</td></tr>
-
-     <tr>
-      <td class="formfieldheading" colspan="4">
-       Residence Address <i>(kept private)</i>
-      </td>
-     </tr>
-     {% field_as_table_row form.res_street %}
-     {% field_as_table_row form.res_city %}
-     {% field_as_table_row form.res_state %}
-     {% field_as_table_row form.res_postalcode %}
-     {% field_as_table_row form.res_country %}
-     <tr><td colspan="4">&nbsp;</td></tr>
-
-     <tr>
-      <td class="formfieldheading" colspan="4">
-       Shipping Address <i>(kept private; optional, if omitted, Residence
-                            Address will be used)</i>
-      </td>
-     </tr>
-     {% field_as_table_row form.ship_street %}
-     {% field_as_table_row form.ship_city %}
-     {% field_as_table_row form.ship_state %}
-     {% field_as_table_row form.ship_postalcode %}
-     {% field_as_table_row form.ship_country %}
-
-     <tr><td colspan="4">&nbsp;</td></tr>
-
-     <tr>
-      <td class="formfieldheading" colspan="4">
-       Personal Information <i>(kept private)</i>
-      </td>
-     </tr>
-     {% field_as_table_row form.phone %}
-     {% field_as_table_row form.birth_date %}
-     {% field_as_table_row form.tshirt_size %}
-     {% field_as_table_row form.tshirt_style %}
-    </table>
-    <input type="submit" />
-   </form>
-  </p>
- </body>
-</html>
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/person/profile/edit.html	Mon Aug 11 16:57:46 2008 +0000
@@ -0,0 +1,113 @@
+{% 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 %}
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
+<html lang="en">
+ <head>
+  <title>Profile</title>
+  {% block 'stylesheet' %}{% endblock %}
+ </head>
+ <body>
+  <p>
+   {% block 'logo' %}
+   <img src="/soc/content/images/dune.jpg" alt="Melange" />
+   {% endblock %}
+   <p>
+   {% block 'greeting' %}
+   Welcome, {{user.nickname}}.
+   {% endblock %}
+   </p>
+   <p>
+   {% block 'instructions' %}
+   Please update your profile:
+   {% endblock %}
+   </p>
+   <form method="POST">
+    <table>
+     <tr>
+      <td class="formfieldheading" colspan="4">
+       Name <i>(publicly displayed)</i>
+      </td>
+     </tr>
+     {% field_as_table_row form.given_name %}
+     {% field_as_table_row form.surname %}
+     {% field_as_table_row form.nickname %}
+     {% field_as_table_row form.display_name %}
+     <tr><td colspan="4">&nbsp;</td></tr>
+
+     <tr>
+      <td class="formfieldheading" colspan="4">
+       Online Profile <i>(publicly displayed)</i>
+      </td>
+     </tr>
+     {% field_as_table_row form.email %}
+     {% field_as_table_row form.im_network %}
+     {% field_as_table_row form.im_handle %}
+     {% field_as_table_row form.home_page %}
+     {% field_as_table_row form.blog %}
+     {% field_as_table_row form.photo_url %}
+     <tr><td colspan="4">&nbsp;</td></tr>
+
+     <tr>
+      <td class="formfieldheading" colspan="4">
+       Location <i>(publicly displayed, these will be replaced with a
+                    Google Maps control)</i>
+      </td>
+     </tr>
+     {% field_as_table_row form.latitude %}
+     {% field_as_table_row form.longitude %}
+     <tr><td colspan="4">&nbsp;</td></tr>
+
+     <tr>
+      <td class="formfieldheading" colspan="4">
+       Residence Address <i>(kept private)</i>
+      </td>
+     </tr>
+     {% field_as_table_row form.res_street %}
+     {% field_as_table_row form.res_city %}
+     {% field_as_table_row form.res_state %}
+     {% field_as_table_row form.res_postalcode %}
+     {% field_as_table_row form.res_country %}
+     <tr><td colspan="4">&nbsp;</td></tr>
+
+     <tr>
+      <td class="formfieldheading" colspan="4">
+       Shipping Address <i>(kept private; optional, if omitted, Residence
+                            Address will be used)</i>
+      </td>
+     </tr>
+     {% field_as_table_row form.ship_street %}
+     {% field_as_table_row form.ship_city %}
+     {% field_as_table_row form.ship_state %}
+     {% field_as_table_row form.ship_postalcode %}
+     {% field_as_table_row form.ship_country %}
+
+     <tr><td colspan="4">&nbsp;</td></tr>
+
+     <tr>
+      <td class="formfieldheading" colspan="4">
+       Personal Information <i>(kept private)</i>
+      </td>
+     </tr>
+     {% field_as_table_row form.phone %}
+     {% field_as_table_row form.birth_date %}
+     {% field_as_table_row form.tshirt_size %}
+     {% field_as_table_row form.tshirt_style %}
+    </table>
+    <input type="submit" />
+   </form>
+  </p>
+ </body>
+</html>
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/views/person/profile.py	Mon Aug 11 16:57:46 2008 +0000
@@ -0,0 +1,91 @@
+#!/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 of Person entity contents, a "profile".
+
+edit: read-write form for modifying Person fields 
+
+TODO:
+public: read-only view of "public-only" Person fields
+"""
+
+__authors__ = [
+  '"Augie Fackler" <durin42@gmail.com>',
+  '"Todd Larsen" <tlarsen@google.com>',
+  ]
+
+
+from google.appengine.api import users
+from django import http
+from django import shortcuts
+from django import newforms as forms
+
+from soc.models import person
+from soc.views.helpers import forms_helpers
+
+
+class EditForm(forms_helpers.DbModelForm):
+  """Django form displayed when creating or editing a Person.
+  """
+
+  class Meta:
+    """Inner Meta class that defines some behavior for the form.
+    """
+    #: db.Model subclass for which the form will gather information
+    model = person.Person
+
+    #: list of model fields which will *not* be gathered by the form
+    exclude = ['user']
+
+
+def edit(request, program=None, linkname=None,
+         template='soc/person/profile/edit.html'):
+  """View for a Person to modify the properties of a Person Model.
+
+  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))
+
+  # TODO(tlarsen)
+  # if program:
+  #   query for the human-readable program name and pass that to the form
+  
+  # TODO(tlarsen)
+  # if linkname:
+  #   query for a site-wide user profile for a friendly display name
+  #      to use in the greeting
+  # else:
+  #   use user to query for a site-wide user profile for a friendly
+  #      display name to use in the greeting
+
+  form = EditForm()
+  if request.method=='POST':
+    form = EditForm(request.POST)
+
+    if not form.errors:
+      return http.HttpResponse('This would update the model')
+
+  return shortcuts.render_to_response(
+      template, dictionary={'template': template, 'form': form, 'user': user,
+                            'program': program, 'linkname': linkname})
--- a/app/urls.py	Mon Aug 11 16:44:47 2008 +0000
+++ b/app/urls.py	Mon Aug 11 16:57:46 2008 +0000
@@ -22,6 +22,9 @@
 
 urlpatterns = patterns(
     '',
-    (r'^person/profile/$', 'soc.views.person.profile',
-     {'template': 'proto/person/profile.html'}),
+    (r'^org/profile/(?P<program>ghop[_0-9a-z]+)/(?P<linkname>[_0-9a-z]+)/$',
+     'soc.views.person.profile.edit',
+     {'template': 'ghop/person/profile/edit.html'}),
+    (r'^org/profile/(?P<program>[_0-9a-z]+)/(?P<linkname>[_0-9a-z]+)/$',
+     'soc.views.person.profile.edit'),
 )