# HG changeset patch # User Sverre Rabbelier # Date 1236378746 0 # Node ID 599a5ff8f422e977e1ceb91fbc2f52c88e3212cd # Parent 699f65fbf08ad41a255c197c446f406ddd879d49 Clean document references This has the advantage that we can inform the user if a document could not be found. Patch by: Sverre Rabbelier diff -r 699f65fbf08a -r 599a5ff8f422 app/soc/views/models/base.py --- a/app/soc/views/models/base.py Fri Mar 06 22:31:43 2009 +0000 +++ b/app/soc/views/models/base.py Fri Mar 06 22:32:26 2009 +0000 @@ -660,21 +660,12 @@ fields: the new field values """ - scope_path = self._logic.getKeyNameFromFields(fields) - - key_fields = { - 'scope_path': scope_path, - 'prefix': self._params['document_prefix'], - } - - for field_name, original_name, logic, _ in self._params['references']: + references = self._params['references'] + for field_name, original_name, _ in references: if field_name not in fields: continue - key_fields['link_id'] = fields[field_name] - - # TODO notify the user if home_doc is not found - entity = logic.getFromKeyFields(key_fields) + entity = fields.get('resolved_%s' % field_name) fields[original_name] = entity # If scope_logic is not defined, this entity has no scope @@ -723,7 +714,7 @@ if 'scope_path' in form.fields: form.fields['scope_path'].initial = entity.scope_path - for field_name, _, _, getter in self._params['references']: + for field_name, _, getter in self._params['references']: try: field = getter(entity) form.fields[field_name].initial = field.link_id if field else None diff -r 699f65fbf08a -r 599a5ff8f422 app/soc/views/models/organization.py --- a/app/soc/views/models/organization.py Fri Mar 06 22:31:43 2009 +0000 +++ b/app/soc/views/models/organization.py Fri Mar 06 22:32:26 2009 +0000 @@ -132,9 +132,9 @@ soc.logic.models.organization, org_app_logic) } - # get rid of the clean method new_params['edit_extra_dynaproperties'] = { - 'clean': (lambda x: x.cleaned_data)} + 'clean': cleaning.clean_refs(new_params, ['home_link_id']) + } params = dicts.merge(params, new_params) diff -r 699f65fbf08a -r 599a5ff8f422 app/soc/views/models/presence.py --- a/app/soc/views/models/presence.py Fri Mar 06 22:31:43 2009 +0000 +++ b/app/soc/views/models/presence.py Fri Mar 06 22:32:26 2009 +0000 @@ -150,17 +150,7 @@ properties = {'home_for': None} document_logic.logic.updateEntityProperties(entity.home, properties) - scope_path = self._logic.getKeyNameFromFields(fields) - - key_fields = { - 'scope_path': scope_path, - 'link_id': fields['home_link_id'], - 'prefix': self._params['document_prefix'], - } - - # TODO notify the user if home_doc is not found - home_doc = document_logic.logic.getFromKeyFields(key_fields) - + home_doc = fields.get('resolved_home_link_id') fields['home'] = home_doc if home_doc: diff -r 699f65fbf08a -r 599a5ff8f422 app/soc/views/models/presence_with_tos.py --- a/app/soc/views/models/presence_with_tos.py Fri Mar 06 22:31:43 2009 +0000 +++ b/app/soc/views/models/presence_with_tos.py Fri Mar 06 22:32:26 2009 +0000 @@ -27,6 +27,7 @@ from django import forms from django.utils.translation import ugettext +from soc.logic import cleaning from soc.logic import dicts from soc.logic.models import document as document_logic from soc.views.models import presence @@ -49,8 +50,6 @@ """ new_params = {} - new_params['logic'] = soc.logic.models.presence_with_tos.logic - new_params['extra_dynaexclude'] = ['tos'] new_params['edit_extra_dynaproperties'] = { @@ -59,6 +58,8 @@ filter_fields={'prefix': params['document_prefix']}, label=ugettext('Terms of Service Document link ID'), help_text=soc.models.work.Work.link_id.help_text), + 'clean': cleaning.clean_refs(params, + ['home_link_id', 'tos_link_id']), } params = dicts.merge(params, new_params, sub_merge=True) @@ -84,17 +85,7 @@ if 'tos_link_id' not in fields: return super(View, self)._editPost(request, entity, fields) - scope_path = self._logic.getKeyNameFromFields(fields) - - key_fields = { - 'scope_path': scope_path, - 'link_id': fields['tos_link_id'], - 'prefix': self._params['document_prefix'], - } - - # TODO notify the user if tos_doc is not found - tos_doc = document_logic.logic.getFromKeyFields(key_fields) - + tos_doc = fields.get('resolved_tos_link_id') fields['tos'] = tos_doc super(View, self)._editPost(request, entity, fields) diff -r 699f65fbf08a -r 599a5ff8f422 app/soc/views/models/program.py --- a/app/soc/views/models/program.py Fri Mar 06 22:31:43 2009 +0000 +++ b/app/soc/views/models/program.py Fri Mar 06 22:32:26 2009 +0000 @@ -26,6 +26,7 @@ from django import forms from django.utils.translation import ugettext +from soc.logic import cleaning from soc.logic import dicts from soc.logic.helper import timeline as timeline_helper from soc.logic.models import host as host_logic @@ -113,19 +114,21 @@ result['workflow'] = forms.CharField(widget=widgets.ReadOnlyInput(), required=True) + result['clean'] = cleaning.clean_refs(new_params, + [i for i,_,_ in reference_fields]) new_params['edit_extra_dynaproperties'] = result - references = [ - ('org_admin_agreement_link_id', 'org_admin_agreement', document_logic, + document_references = [ + ('org_admin_agreement_link_id', 'org_admin_agreement', lambda x: x.org_admin_agreement), - ('mentor_agreement_link_id', 'mentor_agreement', document_logic, + ('mentor_agreement_link_id', 'mentor_agreement', lambda x: x.mentor_agreement), - ('student_agreement_link_id', 'student_agreement', document_logic, + ('student_agreement_link_id', 'student_agreement', lambda x: x.student_agreement), ] - new_params['references'] = references + new_params['references'] = document_references params = dicts.merge(params, new_params, sub_merge=True)