Make use of the new generic key_name by lookup up scope_path
This way base classes do not have to look up the 'scope' property,
instead they can rely on the base class to do it for them provided
they define the 'scope_logic' param.
Patch by: Sverre Rabbelier
--- a/app/soc/views/models/base.py Wed Dec 03 23:48:33 2008 +0000
+++ b/app/soc/views/models/base.py Wed Dec 03 23:49:10 2008 +0000
@@ -494,7 +494,12 @@
fields: the new field values
"""
- pass
+ # If scope_logic is not defined, this entity has no scope
+ if 'scope_logic' not in self._params:
+ return
+
+ scope = self._params['scope_logic'].logic.getFromKeyName(fields['scope_path'])
+ fields['scope'] = scope
def _public(self, request, entity, context):
"""Performs any required processing to get an entities public page.
@@ -516,7 +521,8 @@
form: the django form that will be used for the page
"""
- pass
+ # fill in the email field with the data from the entity
+ form.fields['scope_path'].initial = entity.scope_path
def _editSeed(self, request, seed):
"""Performs any required processing on the form to get its edit page.
--- a/app/soc/views/models/document.py Wed Dec 03 23:48:33 2008 +0000
+++ b/app/soc/views/models/document.py Wed Dec 03 23:49:10 2008 +0000
@@ -30,6 +30,7 @@
from soc.logic import dicts
from soc.logic import validate
+from soc.logic.models import user as user_logic
from soc.views import helper
from soc.views.models import base
@@ -114,25 +115,26 @@
"""
account = users.get_current_user()
- user = soc.logic.models.user.logic.getForFields({'account': account},
- unique=True)
+ user = user_logic.logic.getForFields({'account': account}, unique=True)
+
if not entity:
- # new document so set author
fields['author'] = user
else:
- # else the author is the original author
fields['author'] = entity.author
-
+
fields['modified_by'] = user
+ super(View, self)._editPost(request, entity, fields)
+
def _editGet(self, request, entity, form):
"""See base.View._editGet().
"""
-
+
form.fields['created_by'].initial = entity.author.name
form.fields['last_modified_by'].initial = entity.modified_by.name
form.fields['doc_key_name'].initial = entity.key().name()
+ super(View, self)._editGet(request, entity, form)
view = View()
--- a/app/soc/views/models/group.py Wed Dec 03 23:48:33 2008 +0000
+++ b/app/soc/views/models/group.py Wed Dec 03 23:49:10 2008 +0000
@@ -27,6 +27,7 @@
from django import forms
from soc.logic import dicts
+from soc.logic.models import user as user_logic
from soc.views import helper
from soc.views.models import base
@@ -75,9 +76,8 @@
"""See base.View._editPost().
"""
- account = users.get_current_user()
- user = soc.logic.models.user.logic.getForFields({'account': account},
- unique=True)
if not entity:
# only if we are creating a new entity we should fill in founder
+ account = users.get_current_user()
+ user = user_logic.logic.getForFields({'account': account}, unique=True)
fields['founder'] = user
--- a/app/soc/views/models/host.py Wed Dec 03 23:48:33 2008 +0000
+++ b/app/soc/views/models/host.py Wed Dec 03 23:49:10 2008 +0000
@@ -27,6 +27,7 @@
from soc.logic.models import sponsor as sponsor_logic
from soc.views import helper
from soc.views.models import role
+from soc.views.models import sponsor as sponsor_view
from soc.views.helper import access
import soc.models.host
@@ -91,6 +92,9 @@
new_params['rights'] = rights
new_params['logic'] = soc.logic.models.host.logic
+ new_params['scope_logic'] = sponsor_logic
+ new_params['scope_view'] = sponsor_view
+
new_params['logic'] = soc.logic.models.host.logic
new_params['group_view'] = soc.views.models.sponsor.view
new_params['invite_filter'] = {'group_ln': 'link_id'}
@@ -112,14 +116,10 @@
"""See base.View._editPost().
"""
- user = user_logic.logic.getForFields(
- {'link_id': fields['link_id']}, unique=True)
+ user = user_logic.logic.getFromKeyName(fields['link_id'])
fields['user'] = user
- sponsor = sponsor_logic.logic.getForFields(
- {'link_id': fields['scope_path']}, unique=True)
- fields['scope'] = sponsor
-
+ super(View, self)._editPost(request, entity, fields)
view = View()
--- a/app/soc/views/models/presence.py Wed Dec 03 23:48:33 2008 +0000
+++ b/app/soc/views/models/presence.py Wed Dec 03 23:49:10 2008 +0000
@@ -151,6 +151,8 @@
except db.Error:
pass
+ super(View, self)._editGet(request, entity, form)
+
def _editPost(self, request, entity, fields):
"""See base.View._editPost().
"""
@@ -164,6 +166,8 @@
fields['home'] = home_doc
+ super(View, self)._editPost(request, entity, fields)
+
view = View()
--- a/app/soc/views/models/program.py Wed Dec 03 23:48:33 2008 +0000
+++ b/app/soc/views/models/program.py Wed Dec 03 23:49:10 2008 +0000
@@ -53,6 +53,9 @@
new_params = {}
new_params['logic'] = soc.logic.models.program.logic
+ new_params['scope_logic'] = sponsor_logic
+ new_params['scope_view'] = sponsor_view
+
new_params['name'] = "Program"
new_params['name_short'] = "Program"
new_params['name_plural'] = "Programs"
@@ -95,20 +98,6 @@
redirect = redirects.getCreateRedirect
return self.select(request, view, redirect, **kwargs)
- def _editGet(self, request, entity, form):
- """See base.View._editGet().
- """
-
- # fill in the email field with the data from the entity
- form.fields['scope_path'].initial = entity.scope_path
-
- def _editPost(self, request, entity, fields):
- """See base.View._editPost().
- """
-
- sponsor = sponsor_logic.logic.getFromFields(link_id=fields['scope_path'])
- fields['scope'] = sponsor
-
view = View()
--- a/app/soc/views/models/request.py Wed Dec 03 23:48:33 2008 +0000
+++ b/app/soc/views/models/request.py Wed Dec 03 23:49:10 2008 +0000
@@ -198,6 +198,8 @@
form.fields['user'].initial = entity.link_id
form.fields['group'].initial = entity.scope_path
+ super(View, self)._editGet(request, entity, form)
+
def _editPost(self, request, entity, fields):
"""See base.View._editPost().
"""
@@ -207,6 +209,8 @@
fields['scope_path'] = fields['to'].link_id
fields['scope'] = fields['to']
+ super(View, self)._editPost(request, entity, fields)
+
view = View()
--- a/app/soc/views/models/user.py Wed Dec 03 23:48:33 2008 +0000
+++ b/app/soc/views/models/user.py Wed Dec 03 23:49:10 2008 +0000
@@ -146,15 +146,20 @@
def _editGet(self, request, entity, form):
"""See base.View._editGet().
"""
+
# fill in the email field with the data from the entity
form.fields['email'].initial = entity.account.email()
+ super(View, self)._editGet(request, entity, form)
+
def _editPost(self, request, entity, fields):
"""See base.View._editPost().
"""
+
# fill in the account field with the user created from email
fields['account'] = users.User(fields['email'])
+ super(View, self)._editPost(request, entity, fields)
view = View()
--- a/app/soc/views/models/user_self.py Wed Dec 03 23:48:33 2008 +0000
+++ b/app/soc/views/models/user_self.py Wed Dec 03 23:49:10 2008 +0000
@@ -223,15 +223,21 @@
def _editGet(self, request, entity, form):
"""See base.View._editGet().
"""
+
# fill in the email field with the data from the entity
form.fields['email'].initial = entity.account.email()
+ super(View, self)._editGet(request ,entity, form)
+
def _editPost(self, request, entity, fields):
"""See base.View._editPost().
"""
+
# fill in the account field with the user created from email
fields['account'] = users.User(fields['email'])
+ super(View, self)._editPost(request, entity, fields)
+
def getSidebarLinks(self, request, params=None):
"""Returns an dictionary with the user sidebar entry.
"""