--- a/app/soc/modules/ghop/views/helper/access.py Mon Sep 14 20:21:47 2009 +0200
+++ b/app/soc/modules/ghop/views/helper/access.py Tue Sep 15 20:54:40 2009 +0200
@@ -20,7 +20,8 @@
"""
__authors__ = [
- '"Madhusudan.C.S" <madhusudancs@gmail.com>'
+ '"Madhusudan.C.S" <madhusudancs@gmail.com>',
+ '"Lennard de Rijk" <ljvderijk@gmail.com>',
]
@@ -34,6 +35,7 @@
from soc.modules.ghop.logic.models import mentor as ghop_mentor_logic
from soc.modules.ghop.logic.models import org_admin as ghop_org_admin_logic
+from soc.modules.ghop.logic.models import program as ghop_program_logic
from soc.modules.ghop.logic.models import task as ghop_task_logic
@@ -41,6 +43,9 @@
'This task cannot be edited since it has been claimed at least '
'once before.')
+DEF_CANT_REGISTER = ugettext(
+ 'You have not completed your first task to register as a student. ')
+
DEF_MAX_TASKS_REACHED_MSG = ugettext(
'You have reached the maximum number of Tasks allowed '
'for your organization for this program.')
@@ -242,3 +247,33 @@
# this proposal can not be task at the moment
raise out_of_band.AccessViolation(
message_fmt=DEF_NO_PUB_TASK_MSG)
+
+ def checkCanApply(self, django_args):
+ """Checks if the user has the completed at least one task to register as
+ a student.
+
+ Args:
+ django_args: a dictionary with django's arguments
+
+ Raises:
+ AccessViolationResponse:
+ - If student has not completed even a single task
+ """
+
+ self.checkIsUser(django_args)
+
+ program_entity = ghop_program_logic.logic.getFromKeyNameOr404(
+ django_args['scope_path'])
+
+ filter = {
+ 'user': self.user,
+ 'program': program_entity,
+ 'status': 'AwaitingRegistration',
+ }
+
+ if ghop_task_logic.logic.getForFields(filter, unique=True):
+ return
+
+ # no completed tasks found, access denied
+ raise out_of_band.AccessViolation(
+ message_fmt=DEF_CANT_REGISTER)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/modules/ghop/views/models/student.py Tue Sep 15 20:54:40 2009 +0200
@@ -0,0 +1,96 @@
+#!/usr/bin/python2.5
+#
+# Copyright 2009 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.
+
+"""GHOP specific views for Student.
+"""
+
+__authors__ = [
+ '"Madhusudan.C.S" <madhusudancs@gmail.com>',
+ '"Lennard de Rijk" <ljvderijk@gmail.com>',
+ ]
+
+
+from soc.logic import dicts
+from soc.views.helper import decorators
+from soc.views.helper import dynaform
+from soc.views.models import student
+
+from soc.modules.ghop.logic.models import mentor as ghop_mentor_logic
+from soc.modules.ghop.logic.models import organization as ghop_org_logic
+from soc.modules.ghop.logic.models import org_admin as ghop_org_admin_logic
+from soc.modules.ghop.logic.models import program as ghop_program_logic
+from soc.modules.ghop.logic.models import student as ghop_student_logic
+from soc.modules.ghop.views.helper import access as ghop_access
+from soc.modules.ghop.views.models import program as ghop_program_view
+
+import soc.modules.ghop.logic.models.student
+
+
+class View(student.View):
+ """View methods for the GHOP Student model.
+ """
+
+ def __init__(self, params=None):
+ """Defines the fields and methods required for the student View class
+ to provide the user with list, public, create, edit and delete views.
+
+ Params:
+ params: a dict with params for this View
+ """
+
+ rights = ghop_access.GHOPChecker(params)
+ rights['edit'] = [('checkIsMyActiveRole', ghop_student_logic.logic)]
+ rights['apply'] = [
+ 'checkIsUser',
+ ('checkIsActivePeriod',
+ ['student_signup', 'scope_path', ghop_program_logic.logic]),
+ ('checkIsNotParticipatingInProgramInScope', [ghop_program_logic.logic,
+ ghop_student_logic.logic, ghop_org_admin_logic.logic,
+ ghop_mentor_logic.logic]),
+ 'checkCanApply']
+ rights['manage'] = [('checkIsMyActiveRole', ghop_student_logic.logic)]
+
+ new_params = {}
+ new_params['logic'] = soc.modules.ghop.logic.models.student.logic
+ new_params['rights'] = rights
+
+ new_params['group_logic'] = ghop_program_logic.logic
+ new_params['group_view'] = ghop_program_view.view
+
+ new_params['scope_view'] = ghop_program_view
+
+ new_params['name'] = "GHOP Student"
+ new_params['module_name'] = "student"
+ new_params['sidebar_grouping'] = 'Students'
+
+ new_params['module_package'] = 'soc.modules.ghop.views.models'
+ new_params['url_name'] = 'ghop/student'
+
+ params = dicts.merge(params, new_params, sub_merge=True)
+
+ super(View, self).__init__(params=params)
+
+
+view = View()
+
+apply = decorators.view(view.apply)
+create = decorators.view(view.create)
+delete = decorators.view(view.delete)
+edit = decorators.view(view.edit)
+list = decorators.view(view.list)
+manage = decorators.view(view.manage)
+public = decorators.view(view.public)
+export = decorators.view(view.export)
--- a/app/soc/views/helper/access.py Mon Sep 14 20:21:47 2009 +0200
+++ b/app/soc/views/helper/access.py Tue Sep 15 20:54:40 2009 +0200
@@ -1159,13 +1159,18 @@
raise out_of_band.AccessViolation(message_fmt=DEF_NO_APPLICATION_MSG)
- def checkIsNotParticipatingInProgramInScope(self, django_args, program_logic):
+ def checkIsNotParticipatingInProgramInScope(self, django_args, program_logic,
+ student_logic, org_admin_logic,
+ mentor_logic):
"""Checks if the current user has no roles for the given
program in django_args.
Args:
django_args: a dictionary with django's arguments
program_logic: Program Logic instance
+ student_logic: Student Logic instance
+ org_admin_logic: Org Admin Logic instance
+ mentor_logic: Mentor Logic instance
Raises:
AccessViolationResponse: if the current user has a student, mentor or
--- a/app/soc/views/models/student.py Mon Sep 14 20:21:47 2009 +0200
+++ b/app/soc/views/models/student.py Tue Sep 15 20:54:40 2009 +0200
@@ -29,6 +29,8 @@
from soc.logic import cleaning
from soc.logic import dicts
+from soc.logic.models import mentor as mentor_logic
+from soc.logic.models import org_admin as org_admin_logic
from soc.logic.models import program as program_logic
from soc.logic.models import student as student_logic
from soc.logic.models import user as user_logic
@@ -66,7 +68,8 @@
'checkIsUser',
('checkIsActivePeriod',
['student_signup', 'scope_path', program_logic.logic]),
- ('checkIsNotParticipatingInProgramInScope', [program_logic.logic]),
+ ('checkIsNotParticipatingInProgramInScope', [program_logic.logic,
+ student_logic.logic, org_admin_logic.logic, mentor_logic.logic]),
]
rights['manage'] = [('checkIsMyActiveRole', student_logic.logic)]
rights['list_projects'] = [