Requests are almost working now
You can accept a request by clicking on it in the roles view.
Patch by: Sverre Rabbelier
--- a/app/soc/logic/lists.py Sat Nov 22 18:16:42 2008 +0000
+++ b/app/soc/logic/lists.py Sat Nov 22 18:22:36 2008 +0000
@@ -137,7 +137,6 @@
"""Returns the redirect for the current row item in the current list.
"""
- logic = self.get('logic')
- action = self.get('action')
- suffix = logic.getKeySuffix(self.row_data)
- return "%s/%s" % (action, suffix)
+ action, args = self.get('action')
+ result = action(self.row_data, args)
+ return result
--- a/app/soc/templates/soc/host/list/row.html Sat Nov 22 18:16:42 2008 +0000
+++ b/app/soc/templates/soc/host/list/row.html Sat Nov 22 18:22:36 2008 +0000
@@ -1,7 +1,7 @@
<tr class="off" onmouseover="this.className='on'" onmouseout="this.className='off'"
-onclick="document.location.href='/{{ entity_type|lower }}/edit/{{ list.item.sponsor.link_id }}/{{ list.item.user.link_id }}'" name="name">
+onclick="document.location.href='{{ list.redirect }}'" name="name">
<td align="right"><div class="user_link_id"><a class="noul"
- href="/{{ entity_type|lower }}/edit/{{ list.item.sponsor.link_id }}/{{ list.item.user.link_id }}">{{ list.item.user.link_id }}</a>
+ href="{{ list.redirect }}">{{ list.item.user.link_id }}</a>
</div>
</td>
<td><div class="sponsor_name">{{ list.item.sponsor.name }}</div></td>
--- a/app/soc/views/models/base.py Sat Nov 22 18:16:42 2008 +0000
+++ b/app/soc/views/models/base.py Sat Nov 22 18:22:36 2008 +0000
@@ -140,7 +140,7 @@
new_params['list_row'] = 'soc/%(module_name)s/list/row.html' % params
new_params['list_heading'] = 'soc/%(module_name)s/list/heading.html' % params
- new_params['list_action'] = '/' + params['url_name'] + '/edit'
+ new_params['list_action'] = (self.getEditRedirect, None)
new_params['list_params'] = {
'list_action': 'action',
'list_description': 'description',
@@ -443,6 +443,14 @@
return http.HttpResponseRedirect(redirect)
+ def getEditRedirect(self, entity, _):
+ """Returns the edit redirect for the specified entity
+ """
+
+ suffix = self._logic.getKeySuffix(entity)
+ url_name = self._params['url_name']
+ return '/%s/edit/%s' % (url_name, suffix)
+
def _editPost(self, request, entity, fields):
"""Performs any required processing on the entity to post its edit page.
--- a/app/soc/views/models/host.py Sat Nov 22 18:16:42 2008 +0000
+++ b/app/soc/views/models/host.py Sat Nov 22 18:22:36 2008 +0000
@@ -31,8 +31,8 @@
import soc.models.host
import soc.logic.models.host
-import soc.logic.models.sponsor
import soc.views.helper
+import soc.views.models.sponsor
class CreateForm(helper.forms.BaseForm):
@@ -89,7 +89,7 @@
params = {}
params['logic'] = soc.logic.models.host.logic
- params['group_logic'] = soc.logic.models.sponsor.logic
+ params['group_view'] = soc.views.models.sponsor.view
params['invite_filter'] = {'group_ln': 'link_id'}
params['name'] = "Host"
--- a/app/soc/views/models/request.py Sat Nov 22 18:16:42 2008 +0000
+++ b/app/soc/views/models/request.py Sat Nov 22 18:22:36 2008 +0000
@@ -37,6 +37,7 @@
from soc.views import out_of_band
from soc.views.helper import widgets
from soc.views.models import base
+from soc.views.models import role as role_view
import soc.models.request
import soc.logic.models.request
@@ -150,8 +151,7 @@
'accepted' : True,
'declined' : False}
- # TODO(SRabbelier): make into a usefull redirect
- # params['list_action'] = '/host/create'
+ params['list_action'] = (self.inviteAcceptedRedirect, None)
params['list_description'] = "An overview of your unhandled requests"
uh = helper.lists.getListContent(request, params, self._logic, filter)
@@ -161,6 +161,13 @@
contents = [uh]
return self._list(request, params, contents, page_name)
+ def inviteAcceptedRedirect(self, entity, _):
+ """Returns the redirect for accepting a request
+ """
+
+ return '/%s/create/%s/%s' % (
+ entity.role, entity.to.link_id, entity.requester.link_id)
+
def _editSeed(self, request, seed):
"""See base.View._editGet().
"""
--- a/app/soc/views/models/role.py Sat Nov 22 18:16:42 2008 +0000
+++ b/app/soc/views/models/role.py Sat Nov 22 18:22:36 2008 +0000
@@ -89,99 +89,35 @@
"""Displays the request promotion to Role page.
"""
+ if not params:
+ params = {}
new_params = {}
+ link_id = kwargs['link_id']
- new_params['list_template'] = 'soc/models/list.html'
- new_params['list_redirect_action'] = '/request/create/%s/%s' % (
- self._params['url_name'], kwargs['link_id'])
- new_params['name'] = self._params['name']
- new_params['name_short'] = self._params['name_short']
- new_params['name_plural'] = self._params['name_plural']
+ new_params['list_action'] = (self.getCreateRequestRedirect, link_id)
new_params['instruction_text'] = \
self.DEF_INVITE_INSTRUCTION_MSG_FMT % self._params
- params = dicts.merge(params, new_params)
+ params = dicts.merge(new_params, params)
+ params = dicts.merge(new_params, user_view.view._params)
try:
self.checkAccess('invite', request)
except out_of_band.Error, error:
return error.response(request)
- return user_view.list(request, page_name=page_name, params=params)
-
- def promote(self, request, page_name=None, **kwargs):
- """Displays the promote to Role page.
-
- Args:
- request: the standard Django HTTP request object
- page_name: the page name displayed in templates as page and header title
- kwargs: the Key Fields for the specified entity
- """
+ content = helper.lists.getListContent(request, params, user_logic.logic, None)
+ contents = [content]
- properties = {
- 'accepted': True,
- }
-
- entity = request_logic.logic.updateOrCreateFromFields(properties, **kwargs)
-
- # TODO(SRabbelier) finish this
+ return self._list(request, params, contents, page_name)
- def accept(self, request, page_name=None, params=None, **kwargs):
- """Displays the accept a Role request page.
-
- Args:
- request: the standard Django HTTP request object
- page_name: the page name displayed in templates as page and header title
- kwargs: the Key Fields for the specified entity
+ def getCreateRequestRedirect(self, entity, group_scope):
+ """Returns the edit redirect for the specified entity
"""
- entity = request_logic.logic.getFromFields(**kwargs)
-
- if entity.declined:
- properties = {
- 'declined': False,
- }
-
- request_logic.logic.updateModelProperties(entity, **properties)
-
- if not entity.accepted:
- raise Error("The request has not yet been accepted")
-
- id = users.get_current_user()
- user = models.user.logic.getFromFields(email=id.email())
-
- if entity.user != user:
- raise Error("The request is being accepted by the wrong person")
-
- if entity.role != params['name'].lower():
- raise Error("The wrong module is handling the request")
-
- redirect = params['accept_redirect']
- suffix = self._logic.getKeySuffix(entity)
-
- return helper.responses.redirectToChangedSuffix(
- request, suffix, suffix)
-
- def decline(self, request, page_name=None, **kwargs):
- """Displays the decline a Role request page.
-
- Args:
- request: the standard Django HTTP request object
- page_name: the page name displayed in templates as page and header title
- kwargs: the Key Fields for the specified entity
- """
-
- properties = {
- 'declined': True,
- }
-
- request_logic.logic.updateOrCreateFromFields(properties, **kwargs)
-
- redirect = self._params['decline_redirect']
- suffix = self._logic.getKeySuffix(entity)
-
- return helper.responses.redirectToChangedSuffix(
- request, suffix, suffix)
+ result ='/request/create/%s/%s/%s' % (
+ self._params['url_name'], group_scope, entity.link_id)
+ return result
def getDjangoURLPatterns(self):
"""See base.View.getDjangoURLPatterns().