Added a Host profile and generalized some views
authorSverre Rabbelier <srabbelier@gmail.com>
Wed, 22 Oct 2008 06:20:02 +0000
changeset 404 44223e50e1fc
parent 403 d3e545a8bd26
child 405 f3525c1288ed
Added a Host profile and generalized some views Patch by: Sverre Rabbelier Reviewed by: to-be-reviewed
app/soc/logic/key_name.py
app/soc/logic/models/host.py
app/soc/logic/path_link_name.py
app/soc/logic/site/map.py
app/soc/models/base.py
app/soc/models/host.py
app/soc/models/person.py
app/soc/templates/soc/host/group_heading.html
app/soc/templates/soc/host/group_row.html
app/soc/templates/soc/host/public.html
app/soc/templates/soc/models/all.html
app/soc/templates/soc/models/edit.html
app/soc/templates/soc/models/public.html
app/soc/views/models/docs.py
app/soc/views/models/host.py
app/soc/views/models/sponsor.py
--- a/app/soc/logic/key_name.py	Wed Oct 22 06:19:12 2008 +0000
+++ b/app/soc/logic/key_name.py	Wed Oct 22 06:20:02 2008 +0000
@@ -166,3 +166,14 @@
 
   return 'Work:%s' % link_name
 
+
+def nameHost(sponsor_ln, user_ln):
+  """Placeholder for host namer"""
+
+  if not sponsor_ln:
+    raise Error('"sponsor_ln" must be non-False: "%s"' % sponsor_ln)
+
+  if not user_ln:
+    raise Error('"user_ln" must be non-False: "%s"' % user_ln)
+
+  return 'Host:%s:%s' % (sponsor_ln, user_ln)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/logic/models/host.py	Wed Oct 22 06:20:02 2008 +0000
@@ -0,0 +1,45 @@
+#!/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.
+
+"""Host (Model) query functions.
+"""
+
+__authors__ = [
+  '"Sverre Rabbelier" <sverer@rabbelier.nl>',
+  ]
+
+
+from soc.logic import key_name
+from soc.logic.models import base
+
+import soc.models.host
+
+
+class Logic(base.Logic):
+  """Logic methods for the Work model
+  """
+
+  def __init__(self):
+    """Defines the name, key_name and model for this entity.
+    """
+
+    self._name = "host"
+    self._model = soc.models.host.Host
+    self._keyName = key_name.nameHost
+    self._skip_properties = []
+
+
+logic = Logic()
--- a/app/soc/logic/path_link_name.py	Wed Oct 22 06:19:12 2008 +0000
+++ b/app/soc/logic/path_link_name.py	Wed Oct 22 06:20:02 2008 +0000
@@ -32,6 +32,7 @@
 #     zero or more of OR group
 LINKNAME_PATTERN_CORE = r'[0-9a-z](?:[0-9a-z]|_[0-9a-z])*'
 LINKNAME_ARG_PATTERN = r'(?P<link_name>%s)' % LINKNAME_PATTERN_CORE
+GENERIC_ARG_PATTERN = r'(?P<%%s>%s)' % LINKNAME_PATTERN_CORE 
 LINKNAME_PATTERN = r'^%s$' % LINKNAME_PATTERN_CORE
 LINKNAME_REGEX = re.compile(LINKNAME_PATTERN)
 
--- a/app/soc/logic/site/map.py	Wed Oct 22 06:19:12 2008 +0000
+++ b/app/soc/logic/site/map.py	Wed Oct 22 06:20:02 2008 +0000
@@ -250,6 +250,58 @@
   short_name='List Site Sponsors',
   parent=site_sponsor_sub_menu)
 
+# Host Group public view
+host_profile = page.Page(
+  page.Url(
+    r'^host/profile/%s/%s$' %
+        (path_link_name.GENERIC_ARG_PATTERN % 'sponsor_ln',
+         path_link_name.GENERIC_ARG_PATTERN % 'user_ln'),
+    'soc.views.models.host.public'),
+  'Host Public Profile',
+  parent=home)
+
+# Host Group Site views
+site_host_sub_menu = page.NonPage(
+  'site-host-sub-menu',
+  'Site: Host Sub-Menu',
+  short_name='Site Hosts',
+  parent=site_settings_edit)
+
+site_host_create = page.Page(
+  page.Url(
+    r'^site/host/profile$',
+    'soc.views.models.host.create'),
+  'Site: Create New Host',
+  short_name='Create Site Host',
+  parent=site_host_sub_menu)
+
+site_host_delete = page.Page(
+  page.Url(
+    r'^site/host/delete/%s/%s$' %
+        (path_link_name.GENERIC_ARG_PATTERN % 'sponsor_ln',
+         path_link_name.GENERIC_ARG_PATTERN % 'user_ln'),
+    'soc.views.models.host.delete'),
+  'Site: Delete Existing Host',
+  short_name='Delete Site Host',
+  parent=site_host_sub_menu)
+
+site_host_edit = page.Page(
+  page.Url(
+    r'^site/host/profile/%s/%s$' %
+        (path_link_name.GENERIC_ARG_PATTERN % 'sponsor_ln',
+         path_link_name.GENERIC_ARG_PATTERN % 'user_ln'),
+    'soc.views.models.host.edit'),
+  'Site: Modify Existing Host',
+  short_name='Modify Site Host',
+  parent=site_host_sub_menu)
+
+site_host_list = page.Page(
+  page.Url(
+    r'^site/host/list$',
+    'soc.views.models.host.list'),
+  'Site: List of Hosts',
+  short_name='List Site Hosts',
+  parent=site_host_sub_menu)
 
 # these are not really used...
 #    (r'^org/profile/(?P<program>ghop[_0-9a-z]+)/(?P<link_name>[_0-9a-z]+)/$',
--- a/app/soc/models/base.py	Wed Oct 22 06:19:12 2008 +0000
+++ b/app/soc/models/base.py	Wed Oct 22 06:20:02 2008 +0000
@@ -80,5 +80,5 @@
           model = cls
       
       cls._fields_cache = FieldsProxy()
-
-    return cls._fields_cache
\ No newline at end of file
+    raise
+    return cls._fields_cache
--- a/app/soc/models/host.py	Wed Oct 22 06:19:12 2008 +0000
+++ b/app/soc/models/host.py	Wed Oct 22 06:20:02 2008 +0000
@@ -32,9 +32,19 @@
   """Host details for a specific Program.
   """
 
+  KEY_FIELDS = ['sponsor_ln', 'user_ln']
+
   #: A 1:1 relationship associating a Host with specific
   #: Sponsor details and capabilities. The back-reference in
   #: the Sponsor model is a Query named 'host'.  
   sponsor = db.ReferenceProperty(reference_class=soc.models.sponsor.Sponsor,
                                  required=True, collection_name='hosts')
 
+  def _get_link_name(self):
+    return self.sponsor.link_name
+
+  def _set_link_name(self, value):
+    self.sponsor.link_name = value
+
+  sponsor_ln = property(_get_link_name, _set_link_name)
+
--- a/app/soc/models/person.py	Wed Oct 22 06:19:12 2008 +0000
+++ b/app/soc/models/person.py	Wed Oct 22 06:20:02 2008 +0000
@@ -43,6 +43,16 @@
   fields are revealed is usually covered by Program terms of service.
   """
 
+  KEY_FIELDS = ['user_ln']
+
+  def _get_link_name(self):
+    return self.user.link_name
+
+  def _set_link_name(self, value):
+    self.user.link_name = value
+
+  user_ln = property(_get_link_name, _set_link_name)
+
   #: A required many:1 relationship that ties (possibly multiple
   #: entities of) Person details to a unique User.  A Person cannot
   #: exist unassociated from a login identity and credentials.  The
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/host/group_heading.html	Wed Oct 22 06:20:02 2008 +0000
@@ -0,0 +1,5 @@
+<tr align="left">
+  <th class="first" align="right">Name</th>
+	<th>Sponsor</th>
+  <th>Link name</th>
+</tr>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/host/group_row.html	Wed Oct 22 06:20:02 2008 +0000
@@ -0,0 +1,9 @@
+<tr class="off" onmouseover="this.className='on'" onmouseout="this.className='off'" 
+onclick="document.location.href='/site/{{ entity_type|lower }}/profile/{{ data_element.sponsor_ln }}/{{ data_element.user_ln }}'" name="name">
+  <td align="right"><div class="name"><a class="noul"
+         href="/site/{{ entity_type|lower }}/profile/{{ data_element.sponsor_ln }}/{{ data_element.user_ln }}">{{ data_element.given_name }} {{ data_element.surname}}</a>
+     </div>
+  </td>
+  <td><div class="sponsor">{{ data_element.sponsor.link_name }}</div></td>
+  <td><div class="link_name">{{ data_element.user.link_name }}</div></td>
+</tr>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/host/public.html	Wed Oct 22 06:20:02 2008 +0000
@@ -0,0 +1,29 @@
+{% 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 %}
+
+{% block page_title %}
+{{ entity.title }}
+{% endblock %}
+
+{% block header_title %}
+{{ entity.title }}
+{% endblock %}
+
+{% block body %}
+<div id="createdon">Created on: {{ entity.created }}</div>
+<div id="createdby">Created by: {{ entity.author.nick_name }}</div>
+<div id="content">{{ entity.content|safe }}</div>
+<div id="lastmodified">Last updated on: {{ entity.modified }}</div>
+{% endblock %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/models/all.html	Wed Oct 22 06:20:02 2008 +0000
@@ -0,0 +1,25 @@
+{% 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 body %}
+<p>
+<p>
+{% block instructions %}
+List of {{ entity_type_plural }} in Google Open Source Programs.
+{% endblock %}
+</p>
+{% include list_main %}
+</p>
+{% endblock %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/models/edit.html	Wed Oct 22 06:20:02 2008 +0000
@@ -0,0 +1,60 @@
+{% 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 %}
+
+{% block scripts %}
+	<script type="text/javascript" src="/tiny_mce/tiny_mce_src.js"></script>
+{% endblock %}
+{% block header_title %}
+{{ page.short_name }}
+ {% if entity %}
+   <!-- TODO(srabbelier) use a generic entity name as link -->
+   <a href="/{{ entity_type_short|lower }}/profile/{{ entity_suffix }}">"{{ entity_type }}"</a>
+ {% endif %}
+{% endblock %}
+
+{% block body %}
+<p>
+<p>
+{% block instructions %}
+Please use this form to edit the {{ entity_name }}
+{% endblock %}
+</p>
+<form method="POST">
+ <table>
+	{{ form.as_table }}
+  <tr>
+   <td colspan="4">&nbsp;</td>
+  </tr>
+  </table>
+  <table>
+  <tr>
+    {% block submit_buttons %}
+   <td> 
+    <input style="font-weight: bold" type="submit" value="Save Changes"/></span>
+   </td>
+   <td>
+    <input type="button" onclick="location.href='/'" value="Cancel"/>
+   </td>
+   {% if entity %}
+   <td>
+    <input type="button" onclick="location.href='{{ entity_name_short }}/delete/{{ entity_suffix }}'" value="Delete"/>
+   </td>
+   {% endif %}
+   {% endblock %}
+  </tr>
+ </table>
+</form>
+</p>
+{% endblock %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/models/public.html	Wed Oct 22 06:20:02 2008 +0000
@@ -0,0 +1,27 @@
+{% 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 %}
+
+{% block page_title %}
+{{ entity.title }}
+{% endblock %}
+
+{% block header_title %}
+{{ entity.title }}
+{% endblock %}
+
+{% block body %}
+<!-- TODO(pawel.solyga) Make this generically working etc.-->
+{{ form.as_table }}
+{% endblock %}
--- a/app/soc/views/models/docs.py	Wed Oct 22 06:19:12 2008 +0000
+++ b/app/soc/views/models/docs.py	Wed Oct 22 06:20:02 2008 +0000
@@ -101,7 +101,7 @@
     # TODO(tlarsen) Add support for Django style template lookup
     params['edit_template'] = 'soc/docs/edit.html'
     params['public_template'] = 'soc/docs/public.html'
-    params['list_template'] = 'soc/docs/list/all.html'
+    params['list_template'] = 'soc/list/all.html'
 
     params['lists_template'] = {
       'list_main': 'soc/list/list_main.html',
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/views/models/host.py	Wed Oct 22 06:20:02 2008 +0000
@@ -0,0 +1,146 @@
+#!/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 for Host profiles.
+"""
+
+__authors__ = [
+    '"Sverre Rabbelier" <sverer@rabbelier.nl>',
+  ]
+
+
+from google.appengine.api import users
+
+from django import forms
+from django.utils.translation import ugettext_lazy
+
+from soc.logic import dicts
+from soc.logic import validate
+from soc.views import helper
+from soc.views.helper import widgets
+from soc.views.models import base
+
+import soc.models.host
+import soc.logic.models.host
+import soc.logic.dicts
+import soc.views.helper
+import soc.views.helper.widgets
+
+
+class CreateForm(helper.forms.DbModelForm):
+  """Django form displayed when creating a Host.
+  """
+
+  class Meta:
+    """Inner Meta class that defines some behavior for the form.
+    """
+
+    #: db.Model subclass for which the form will gather information
+    model = soc.models.host.Host
+
+    #: list of model fields which will *not* be gathered by the form
+    exclude = ['inheritance_line']
+
+  def clean_empty(self, field):
+    data = self.cleaned_data.get(field)
+    if not data or data == u'':
+      return None
+
+    return data
+
+  def clean_home_page(self):
+    return self.clean_empty('home_page')
+
+  def clean_blog(self):
+    return self.clean_empty('blog')
+
+  def clean_photo_url(self):
+    return self.clean_empty('photo_url')
+
+
+class EditForm(CreateForm):
+  """Django form displayed when editing a Host.
+  """
+
+class View(base.View):
+  """View methods for the Host model
+  """
+
+  def __init__(self, original_params=None, original_rights=None):
+    """Defines the fields and methods required for the base View class
+    to provide the user with list, public, create, edit and delete views.
+
+    Params:
+      original_params: a dict with params for this View
+      original_rights: a dict with right definitions for this View
+    """
+
+    self._logic = soc.logic.models.host.logic
+
+    params = {}
+    rights = {}
+
+    params['name'] = "Host"
+    params['name_short'] = "Host"
+    params['name_plural'] = "Hosts"
+
+    params['edit_form'] = EditForm
+    params['create_form'] = CreateForm
+
+    # TODO(tlarsen) Add support for Django style template lookup
+    params['edit_template'] = 'soc/models/edit.html'
+    params['public_template'] = 'soc/models/public.html'
+    params['list_template'] = 'soc/models/all.html'
+
+    params['lists_template'] = {
+      'list_main': 'soc/list/list_main.html',
+      'list_pagination': 'soc/list/list_pagination.html',
+      'list_row': 'soc/host/group_row.html',
+      'list_heading': 'soc/host/group_heading.html',
+    }
+
+    params['delete_redirect'] = '/site/host/list'
+    params['create_redirect'] = '/site/host/profile'
+
+    params['save_message'] = [ugettext_lazy('Profile saved.')]
+
+    params['edit_params'] = {
+        self.DEF_SUBMIT_MSG_PARAM_NAME: self.DEF_SUBMIT_MSG_PROFILE_SAVED,
+        }
+
+    rights['list'] = [helper.access.checkIsDeveloper]
+    rights['delete'] = [helper.access.checkIsDeveloper]
+
+    params = dicts.merge(original_params, params)
+    rights = dicts.merge(original_rights, rights)
+
+    base.View.__init__(self, rights=rights, params=params)
+
+  def _editPost(self, request, entity, fields):
+    """
+    """
+
+    fields['sponsor_ln'] = fields['sponsor'].link_name
+    fields['user_ln'] = fields['user'].link_name
+
+
+view = View()
+
+create = view.create
+delete = view.delete
+edit = view.edit
+list = view.list
+public = view.public
--- a/app/soc/views/models/sponsor.py	Wed Oct 22 06:19:12 2008 +0000
+++ b/app/soc/views/models/sponsor.py	Wed Oct 22 06:20:02 2008 +0000
@@ -136,9 +136,7 @@
     """See base.View._editPost().
     """
 
-    id = users.get_current_user()
-    user = soc.logic.models.user.logic.getFromFields(email=id.email())
-    fields['founder'] = user
+    pass
 
 
 view = View()