# HG changeset patch # User Madhusudan C.S # Date 1250893574 -19800 # Node ID 339696f3f5cffab668d0487a1733f77b159081f1 # Parent 3944749338d3845fc0a1bb1431103acb7305e86b Extended program configuration create/edit views specifically to support GHOP. Added the first views for GHOP, which are inherited from soc program views. Added new param keys, module_package. url_name key now specifies this is view is from a Melange GHOP module. Also added the view to GHOP module's callback.py. The program Logic class's timeline_logic variable is tied to corresponding timeline logic within the constructor. diff -r 3944749338d3 -r 339696f3f5cf app/soc/logic/cleaning.py --- a/app/soc/logic/cleaning.py Sat Aug 22 03:56:04 2009 +0530 +++ b/app/soc/logic/cleaning.py Sat Aug 22 03:56:14 2009 +0530 @@ -791,3 +791,29 @@ if not has_access(rights, access_level, scope_path, prefix): self._errors[field] = ErrorList([DEF_NO_RIGHTS_FOR_ACL_MSG]) del self.cleaned_data[field] + +def str2set(string_field): + """Clean method for cleaning comma separated string in the edit form. + + Obtains the comma separated string from the form and stores it as + returns it as a list of strings. + """ + + def wrapper(self): + """Decorator wrapper method. + """ + cleaned_data = self.cleaned_data + + string_data = cleaned_data.get(string_field) + + list_data = [] + for string in string_data.split(','): + string_strip = string.strip() + if string_strip and string_strip not in list_data: + list_data.append(string_strip) + + cleaned_data[string_field] = list_data + + return cleaned_data[string_field] + + return wrapper diff -r 3944749338d3 -r 339696f3f5cf app/soc/logic/models/program.py --- a/app/soc/logic/models/program.py Sat Aug 22 03:56:04 2009 +0530 +++ b/app/soc/logic/models/program.py Sat Aug 22 03:56:14 2009 +0530 @@ -27,22 +27,22 @@ from soc.logic.models import sponsor as sponsor_logic import gsoc.logic.models.timeline -import soc.logic.models.timeline import soc.models.program +import soc.modules.ghop.logic.models.timeline + class Logic(presence_with_tos.Logic): """Logic methods for the Program model. """ - TIMELINE_LOGIC = {'gsoc' : gsoc.logic.models.timeline.logic, - 'ghop' : soc.logic.models.timeline.logic} - def __init__(self, model=soc.models.program.Program, base_model=None, scope_logic=sponsor_logic): """Defines the name, key_name and model for this entity. """ + self.timeline_logic = gsoc.logic.models.timeline.logic + super(Logic, self).__init__(model=model, base_model=base_model, scope_logic=scope_logic) diff -r 3944749338d3 -r 339696f3f5cf app/soc/modules/ghop/callback.py --- a/app/soc/modules/ghop/callback.py Sat Aug 22 03:56:04 2009 +0530 +++ b/app/soc/modules/ghop/callback.py Sat Aug 22 03:56:14 2009 +0530 @@ -21,6 +21,9 @@ ] +from soc.modules.ghop.views.models import program + + class Callback(object): """Callback object that handles interaction between the core. """ @@ -39,9 +42,14 @@ self.core.requireUniqueService('registerWithSitemap') + self.core.registerSitemapEntry(program.view.getDjangoURLPatterns()) + def registerWithSidebar(self): """Called by the server when sidebar entries should be registered. """ # require that we had the chance to register the urls we need with the sitemap self.core.requireUniqueService('registerWithSidebar') + + self.core.registerSidebarEntry(program.view.getSidebarMenus) + diff -r 3944749338d3 -r 339696f3f5cf app/soc/modules/ghop/logic/models/program.py --- a/app/soc/modules/ghop/logic/models/program.py Sat Aug 22 03:56:04 2009 +0530 +++ b/app/soc/modules/ghop/logic/models/program.py Sat Aug 22 03:56:14 2009 +0530 @@ -27,6 +27,7 @@ import soc.models.program +import soc.modules.ghop.logic.models.timeline import soc.modules.ghop.models.program @@ -40,6 +41,8 @@ """Defines the name, key_name and model for this entity. """ + self.timeline_logic = soc.modules.ghop.logic.models.timeline.logic + super(Logic, self).__init__(model, base_model=base_model, scope_logic=scope_logic) diff -r 3944749338d3 -r 339696f3f5cf app/soc/modules/ghop/views/models/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/modules/ghop/views/models/__init__.py Sat Aug 22 03:56:14 2009 +0530 @@ -0,0 +1,17 @@ +# 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. + +"""This is the GHOP Views models module. +""" + diff -r 3944749338d3 -r 339696f3f5cf app/soc/modules/ghop/views/models/program.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/modules/ghop/views/models/program.py Sat Aug 22 03:56:14 2009 +0530 @@ -0,0 +1,123 @@ +#!/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 Programs. +""" + +__authors__ = [ + '"Madhusudan.C.S" ' + ] + + +import datetime + +from django import forms + +from soc.logic import cleaning +from soc.logic import dicts +from soc.views.helper import decorators +from soc.views.models import program +from soc.views.sitemap import sidebar + +import soc.cache.logic + +import soc.modules.ghop.logic.models.program + + +class View(program.View): + """View methods for the GHOP Program model. + """ + + def __init__(self, params=None): + """Defines the fields and methods required for the program View class + to provide the user with list, public, create, edit and delete views. + + Params: + params: a dict with params for this View + """ + + new_params = {} + new_params['logic'] = soc.modules.ghop.logic.models.program.logic + + new_params['name'] = "GHOP Program" + new_params['module_name'] = "program" + new_params['sidebar_grouping'] = 'Programs' + + new_params['module_package'] = 'soc.modules.ghop.views.models' + new_params['url_name'] = 'ghop/program' + + new_params['extra_dynaexclude'] = ['apps_tasks_limit', + 'min_slots', 'max_slots', + 'slots', 'slot_allocation', + 'allocations_visible', + 'task_difficulties', 'task_types', + ] + + new_params['create_dynafields'] = [ + {'name': 'task_difficulties_str', + 'base': forms.fields.CharField, + 'label': 'Task Difficulty levels', + }, + {'name': 'task_types_str', + 'base': forms.fields.CharField, + 'label': 'Task Types', + }, + ] + + new_params['create_extra_dynaproperties'] = { + 'clean_task_difficulties_str': cleaning.str2set( + 'task_difficulties_str'), + 'clean_task_types_str': cleaning.str2set( + 'task_types_str'), + } + + params = dicts.merge(params, new_params, sub_merge=True) + + super(View, self).__init__(params=params) + + def _editGet(self, request, entity, form): + """See base.View._editGet(). + """ + + if entity.task_difficulties: + form.fields['task_difficulties_str'].initial = ', '.join( + entity.task_difficulties) + + if entity.task_types: + form.fields['task_types_str'].initial = ', '.join(entity.task_types) + + return super(View, self)._editGet(request, entity, form) + + def _editPost(self, request, entity, fields): + """See base._editPost(). + """ + + fields['task_difficulties'] = fields['task_difficulties_str'] + fields['task_types'] = fields['task_types_str'] + + return super(View, self)._editPost(request, entity, fields) + + +view = View() + +admin = decorators.view(view.admin) +create = decorators.view(view.create) +delete = decorators.view(view.delete) +edit = decorators.view(view.edit) +list = decorators.view(view.list) +public = decorators.view(view.public) +export = decorators.view(view.export) +home = decorators.view(view.home)