# HG changeset patch # User Sverre Rabbelier # Date 1224656402 0 # Node ID 44223e50e1fc1dc8263db5e65d93d41a477f4981 # Parent d3e545a8bd267663f28d3220e1deaede59aae89e Added a Host profile and generalized some views Patch by: Sverre Rabbelier Reviewed by: to-be-reviewed diff -r d3e545a8bd26 -r 44223e50e1fc app/soc/logic/key_name.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) diff -r d3e545a8bd26 -r 44223e50e1fc app/soc/logic/models/host.py --- /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" ', + ] + + +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() diff -r d3e545a8bd26 -r 44223e50e1fc app/soc/logic/path_link_name.py --- 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%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) diff -r d3e545a8bd26 -r 44223e50e1fc app/soc/logic/site/map.py --- 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/(?Pghop[_0-9a-z]+)/(?P[_0-9a-z]+)/$', diff -r d3e545a8bd26 -r 44223e50e1fc app/soc/models/base.py --- 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 diff -r d3e545a8bd26 -r 44223e50e1fc app/soc/models/host.py --- 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) + diff -r d3e545a8bd26 -r 44223e50e1fc app/soc/models/person.py --- 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 diff -r d3e545a8bd26 -r 44223e50e1fc app/soc/templates/soc/host/group_heading.html --- /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 @@ + + Name + Sponsor + Link name + diff -r d3e545a8bd26 -r 44223e50e1fc app/soc/templates/soc/host/group_row.html --- /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 @@ + + + + + + diff -r d3e545a8bd26 -r 44223e50e1fc app/soc/templates/soc/host/public.html --- /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 %} +
Created on: {{ entity.created }}
+
Created by: {{ entity.author.nick_name }}
+
{{ entity.content|safe }}
+
Last updated on: {{ entity.modified }}
+{% endblock %} diff -r d3e545a8bd26 -r 44223e50e1fc app/soc/templates/soc/models/all.html --- /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 %} +

+

+{% block instructions %} +List of {{ entity_type_plural }} in Google Open Source Programs. +{% endblock %} +

+{% include list_main %} +

+{% endblock %} diff -r d3e545a8bd26 -r 44223e50e1fc app/soc/templates/soc/models/edit.html --- /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 %} + +{% endblock %} +{% block header_title %} +{{ page.short_name }} + {% if entity %} + + "{{ entity_type }}" + {% endif %} +{% endblock %} + +{% block body %} +

+

+{% block instructions %} +Please use this form to edit the {{ entity_name }} +{% endblock %} +

+
+ + {{ form.as_table }} + + + +
 
+ + + {% block submit_buttons %} + + + {% if entity %} + + {% endif %} + {% endblock %} + +
+ + + + + +
+
+

+{% endblock %} diff -r d3e545a8bd26 -r 44223e50e1fc app/soc/templates/soc/models/public.html --- /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 %} + +{{ form.as_table }} +{% endblock %} diff -r d3e545a8bd26 -r 44223e50e1fc app/soc/views/models/docs.py --- 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', diff -r d3e545a8bd26 -r 44223e50e1fc app/soc/views/models/host.py --- /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" ', + ] + + +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 diff -r d3e545a8bd26 -r 44223e50e1fc app/soc/views/models/sponsor.py --- 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()