# HG changeset patch # User Sverre Rabbelier # Date 1226277714 0 # Node ID 2cfcedaf7c1604aa407df8b97bb3b4c61682c772 # Parent e836e8914c8e4eb88f55a5628cc64a3408dde11b Preparation for generic user views Added a getSuffixValues method that is meant to allow for having a non-public field as key_name. Also added support for a key-name field being embeded in the form so that if the key-fields change the old key_name is not lost. diff -r e836e8914c8e -r 2cfcedaf7c16 app/soc/logic/models/base.py --- a/app/soc/logic/models/base.py Mon Nov 10 00:41:01 2008 +0000 +++ b/app/soc/logic/models/base.py Mon Nov 10 00:41:54 2008 +0000 @@ -94,6 +94,19 @@ raise NotImplementedError + def getSuffixValues(self, entity): + """Returns an array with the public values of the Key Fields + + Defaults to getKeyValues + If any of the Key Fields should not be made public, this method + should return their public counterparts instead. + + Args: + entity: the entity for which to construct the suffix + """ + + return self.getKeyValues(entity) + def getKeyValuesFromFields(self, fields): """Exctracts the key values from a dict and returns them @@ -119,7 +132,7 @@ if not entity: return None - key_values = self.getKeyValues(entity) + key_values = self.getSuffixValues(entity) suffix = '/'.join(key_values) return suffix diff -r e836e8914c8e -r 2cfcedaf7c16 app/soc/logic/models/user.py --- a/app/soc/logic/models/user.py Mon Nov 10 00:41:01 2008 +0000 +++ b/app/soc/logic/models/user.py Mon Nov 10 00:41:54 2008 +0000 @@ -53,13 +53,22 @@ def getKeyValues(self, entity): """See base.Logic.getKeyValues. """ - + return [entity.id.email()] + def getSuffixValues(self, entity): + """See base.Logic.getSuffixValues + """ + + return [entity.link_name] + def getKeyValuesFromFields(self, fields): """See base.Logic.getKeyValuesFromFields. """ + if 'email' in fields: + return [fields['email']] + properties = { 'link_name': fields['link_name'] } diff -r e836e8914c8e -r 2cfcedaf7c16 app/soc/templates/soc/user/public.html --- a/app/soc/templates/soc/user/public.html Mon Nov 10 00:41:01 2008 +0000 +++ b/app/soc/templates/soc/user/public.html Mon Nov 10 00:41:54 2008 +0000 @@ -13,15 +13,17 @@ limitations under the License. {% endcomment %} {% load forms_helpers %} -{% block page_title %}User Public Profile{% endblock %} + {% block header_title %} -User Public Profile for {{ link_name_user.nick_name }} +{{ page.short_name }} for {{ entity.nick_name }} {% endblock %} + {% block body %}

- {% readonly_field_as_table_row link_name_user.fields.nick_name.label link_name_user.nick_name %} - {% readonly_field_as_table_row link_name_user.fields.link_name.label link_name_user.link_name %} + {% readonly_field_as_table_row entity.fields.link_name.label entity.link_name %} + {% readonly_field_as_table_row entity.fields.nick_name.label entity.nick_name %} +

{% endblock %} diff -r e836e8914c8e -r 2cfcedaf7c16 app/soc/views/helper/forms.py --- a/app/soc/views/helper/forms.py Mon Nov 10 00:41:01 2008 +0000 +++ b/app/soc/views/helper/forms.py Mon Nov 10 00:41:54 2008 +0000 @@ -89,7 +89,7 @@ DEF_ERROR_ROW = u'%s' DEF_ROW_ENDER = '' DEF_HELP_TEXT_HTML = u'%s' - + def __init__(self, *args, **kwargs): """Parent class initialization. diff -r e836e8914c8e -r 2cfcedaf7c16 app/soc/views/models/base.py --- a/app/soc/views/models/base.py Mon Nov 10 00:41:01 2008 +0000 +++ b/app/soc/views/models/base.py Mon Nov 10 00:41:54 2008 +0000 @@ -203,15 +203,18 @@ if not form.is_valid(): return self._constructResponse(request, entity, context, form, params) - fields = self.collectCleanedFields(form) + key_name, fields = self.collectCleanedFields(form) # get the old_suffix before editing old_suffix = self._logic.getKeySuffix(entity) self._editPost(request, entity, fields) - key_fields = self._logic.getKeyFieldsFromDict(fields) - entity = self._logic.updateOrCreateFromFields(fields, key_fields) + if not key_name: + key_fields = self._logic.getKeyFieldsFromDict(fields) + key_name = self._logic.getKeyNameForFields(key_fields) + + entity = self._logic.updateOrCreateFromKeyName(fields, key_name) if not entity: return http.HttpResponseRedirect('/') @@ -247,6 +250,8 @@ # populate form with the existing entity form = params['edit_form'](instance=entity) + if 'key_name' in form.fields: + form.fields['key_name'].initial = entity.key().name() self._editGet(request, entity, form) else: form = params['create_form']() @@ -432,7 +437,7 @@ check(request) def collectCleanedFields(self, form): - """Collects all cleaned fields from form and returns them + """Collects all cleaned fields and returns them with the key_name Args: form: The form from which the cleaned fields should be collected @@ -440,7 +445,11 @@ fields = {} + key_name = None + if 'key_name' in form.cleaned_data: + key_name = form.cleaned_data.pop('key_name') + for field, value in form.cleaned_data.iteritems(): fields[field] = value - return fields + return key_name, fields