# HG changeset patch
# User Sverre Rabbelier
# Date 1231449867 0
# Node ID 30da180c4bca58391843a618ce93ad279fe9cb61
# Parent 19f8930592ed17cd765f6cbfbb812aa66690dfc1
Added the club_app view, logic and model
Patch by: Sverre Rabbelier
diff -r 19f8930592ed -r 30da180c4bca app/soc/logic/models/group_app.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/logic/models/group_app.py Thu Jan 08 21:24:27 2009 +0000
@@ -0,0 +1,59 @@
+#!/usr/bin/python2.5
+#
+# Copyright 2008 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.
+
+"""Group Application (Model) query functions.
+"""
+
+__authors__ = [
+ '"Sverre Rabbelier" ',
+ ]
+
+
+from soc.logic.models import base
+
+import soc.models.group_app
+
+
+class Logic(base.Logic):
+ """Logic methods for the Group Application model.
+ """
+
+ def __init__(self, model=soc.models.group_app.GroupApplication,
+ base_model=None):
+ """Defines the name, key_name and model for this entity.
+ """
+
+ super(Logic, self).__init__(model=model, base_model=base_model)
+
+ def getKeyValues(self, entity):
+ """See base.Logic.getKeyNameValues.
+ """
+
+ return [entity.link_id]
+
+ def getKeyValuesFromFields(self, fields):
+ """See base.Logic.getKeyValuesFromFields.
+ """
+
+ return [fields['link_id']]
+
+ def getKeyFieldNames(self):
+ """See base.Logic.getKeyFieldNames.
+ """
+
+ return ['link_id']
+
+logic = Logic()
diff -r 19f8930592ed -r 30da180c4bca app/soc/templates/soc/club_app/list/heading.html
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/club_app/list/heading.html Thu Jan 08 21:24:27 2009 +0000
@@ -0,0 +1,4 @@
+
+ Name |
+ Link ID |
+
diff -r 19f8930592ed -r 30da180c4bca app/soc/templates/soc/club_app/list/row.html
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/club_app/list/row.html Thu Jan 08 21:24:27 2009 +0000
@@ -0,0 +1,8 @@
+
+
+ |
+ {{ list.item.link_id }} |
+
diff -r 19f8930592ed -r 30da180c4bca app/soc/templates/soc/club_app/public.html
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/club_app/public.html Thu Jan 08 21:24:27 2009 +0000
@@ -0,0 +1,35 @@
+{% extends "soc/base.html" %}
+{% comment %}
+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.
+{% endcomment %}
+{% load forms_helpers %}
+
+{% block header_title %}
+{{ page_name }} for {{ entity.name }}
+{% endblock %}
+
+{% block body %}
+
+
+ {% readonly_field_as_table_row entity.fields.name.label entity.name %}
+ {% readonly_field_as_table_row entity.fields.home_page.label entity.home_page %}
+ {% readonly_field_as_table_row entity.fields.description.label entity.description %}
+ {% readonly_field_as_table_row entity.fields.street.label entity.street %}
+ {% readonly_field_as_table_row entity.fields.city.label entity.city %}
+ {% readonly_field_as_table_row entity.fields.state.label entity.state %}
+ {% readonly_field_as_table_row entity.fields.country.label entity.country %}
+ {% readonly_field_as_table_row entity.fields.postalcode.label entity.postalcode %}
+ {% readonly_field_as_table_row entity.fields.phone.label entity.phone %}
+
+
+{% endblock %}
diff -r 19f8930592ed -r 30da180c4bca app/soc/views/helper/access.py
--- a/app/soc/views/helper/access.py Thu Jan 08 21:24:10 2009 +0000
+++ b/app/soc/views/helper/access.py Thu Jan 08 21:24:27 2009 +0000
@@ -40,6 +40,7 @@
from soc.logic import dicts
from soc.logic.models import host as host_logic
from soc.logic.models import notification as notification_logic
+from soc.logic.models import group_app as group_app_logic
from soc.logic.models import user as user_logic
from soc.logic.models import request as request_logic
from soc.views import helper
@@ -363,6 +364,50 @@
# TODO(ljvderijk) Make this give a proper error message
deny(request)
+def checkIsMyApplication(request):
+ """Returns an alternate HTTP response if this request is for a Notification belonging
+ to the current user.
+
+ Args:
+ request: a Django HTTP request
+
+ Raises:
+ AccessViolationResponse: if the required authorization is not met
+
+ Returns:
+ None if the current User is allowed to access this Notification.
+ """
+
+ try:
+ # if the current user is a developer we allow access
+ checkIsDeveloper(request)
+ return
+ except out_of_band.Error:
+ pass
+
+ checkIsUser(request)
+
+ # Mine the url for params
+ try:
+ callback, args, kwargs = urlresolvers.resolve(request.path)
+ except Exception:
+ deny(request)
+
+ properties = dicts.filter(kwargs, ['link_id'])
+
+ application = group_app_logic.logic.getForFields(properties, unique=True)
+ user = user_logic.logic.getForCurrentAccount()
+
+ # We need to check to see if the key's are equal since the User
+ # objects are different and the default __eq__ method does not check
+ # if the keys are equal (which is what we want).
+ if user.key() == application.applicant.key():
+ return None
+
+ # TODO(srabbelier) Make this give a proper error message
+ deny(request)
+
+
def checkCanInvite(request):
"""Checks to see if the current user can create an invite.
diff -r 19f8930592ed -r 30da180c4bca app/soc/views/models/club_app.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/views/models/club_app.py Thu Jan 08 21:24:27 2009 +0000
@@ -0,0 +1,137 @@
+#!/usr/bin/python2.5
+#
+# Copyright 2008 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.
+
+"""Views for Club App profiles.
+"""
+
+__authors__ = [
+ '"Sverre Rabbelier" ',
+ ]
+
+
+from django import forms
+from django.utils.translation import ugettext_lazy
+
+from soc.models import group_app as group_app_model
+from soc.logic import accounts
+from soc.logic import cleaning
+from soc.logic import dicts
+from soc.logic.models import user as user_logic
+from soc.views import helper
+from soc.views.models import group_app
+from soc.views.helper import access
+
+import soc.logic.dicts
+
+
+class View(group_app.View):
+ """View methods for the Sponsor model.
+ """
+
+ def __init__(self, params=None):
+ """Defines the fields and methods required for the base View class
+ to provide the user with list, public, create, edit and delete views.
+
+ Params:
+ params: a dict with params for this View
+ """
+
+ rights = {}
+ rights['create'] = [access.checkIsUser]
+ rights['delete'] = [access.checkIsMyApplication]
+ rights['edit'] = [access.checkIsMyApplication]
+ rights['list'] = [access.checkIsUser]
+
+ new_params = {}
+
+ new_params['rights'] = rights
+
+ new_params['create_template'] = 'soc/models/twoline_edit.html'
+ new_params['edit_template'] = 'soc/models/twoline_edit.html'
+
+ new_params['extra_dynaexclude'] = ['applicant', 'backup_admin']
+ new_params['create_extra_dynafields'] = {
+ 'backup_admin_link_id': forms.CharField(
+ label=group_app_model.GroupApplication.backup_admin.verbose_name
+ ),
+ 'clean_backup_admin_link_id': cleaning.clean_existing_user('backup_admin_link_id'),
+ }
+
+ new_params['name'] = "Club Application"
+ new_params['name_short'] = "Club Application"
+ new_params['name_plural'] = "Club Application"
+ new_params['url_name'] = "club_app"
+ new_params['module_name'] = "club_app"
+
+ params = dicts.merge(params, new_params)
+
+ super(View, self).__init__(params=params)
+
+ def list(self, request, access_type,
+ page_name=None, params=None, filter=None):
+ """Lists all notifications that the current logged in user has stored.
+
+ for parameters see base.list()
+ """
+
+ params = dicts.merge(params, self._params)
+
+ # get the current user
+ user_entity = user_logic.logic.getForCurrentAccount()
+
+ is_developer = accounts.isDeveloper(user=user_entity)
+
+ if is_developer:
+ filter = {}
+ else:
+ # only select the applications for this user so construct a filter
+ filter = {'applicant': user_entity}
+
+ if is_developer:
+ params['list_description'] = ugettext_lazy(
+ "An overview all club applications.")
+ else:
+ params['list_description'] = ugettext_lazy(
+ "An overview of your club applications.")
+
+ # use the generic list method with the filter. The access check in this
+ # method will trigger an errorResponse when user_entity is None
+ return super(View, self).list(request, access_type,
+ page_name, params, filter)
+
+ def _editGet(self, request, entity, form):
+ """See base.View._editGet().
+ """
+
+ form.fields['backup_admin_link_id'].initial = entity.backup_admin.link_id
+
+ def _editPost(self, request, entity, fields):
+ """See base.View._editPost().
+ """
+
+ fields['backup_admin'] = fields['backup_admin_link_id']
+
+ if not entity:
+ fields['applicant'] = user_logic.logic.getForCurrentAccount()
+
+
+view = View()
+
+create = view.create
+delete = view.delete
+edit = view.edit
+list = view.list
+public = view.public
diff -r 19f8930592ed -r 30da180c4bca app/soc/views/models/group_app.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/views/models/group_app.py Thu Jan 08 21:24:27 2009 +0000
@@ -0,0 +1,57 @@
+#!/usr/bin/python2.5
+#
+# Copyright 2008 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.
+
+"""Views for Group App.
+"""
+
+__authors__ = [
+ '"Sverre Rabbelier" ',
+ ]
+
+
+from django import forms
+
+from soc.logic import dicts
+from soc.logic.models import group_app as group_app_logic
+from soc.views.models import base
+
+import soc.logic.models.group_app
+
+
+class View(base.View):
+ """View methods for the Group App model.
+ """
+
+ def __init__(self, params=None):
+ """Defines the fields and methods required for the base 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.logic.models.group_app.logic
+
+ new_params['name'] = "Group App"
+ new_params['name_short'] = "Group App"
+ new_params['name_plural'] = "Group Apps"
+ new_params['url_name'] = "group_app"
+ new_params['module_name'] = "group_app"
+
+ params = dicts.merge(params, new_params)
+
+ super(View, self).__init__(params=params)
diff -r 19f8930592ed -r 30da180c4bca app/soc/views/sitemap/build.py
--- a/app/soc/views/sitemap/build.py Thu Jan 08 21:24:10 2009 +0000
+++ b/app/soc/views/sitemap/build.py Thu Jan 08 21:24:27 2009 +0000
@@ -25,6 +25,7 @@
from django.conf.urls import defaults
from soc.views.models import club
+from soc.views.models import club_app
from soc.views.models import document
from soc.views.models import host
from soc.views.models import notification
@@ -45,6 +46,7 @@
sidebar.addMenu(user_self.view.getSidebarMenus)
sidebar.addMenu(presence.view.getSidebarMenus)
sidebar.addMenu(club.view.getSidebarMenus)
+sidebar.addMenu(club_app.view.getSidebarMenus)
sidebar.addMenu(site.view.getSidebarMenus)
sidebar.addMenu(user.view.getSidebarMenus)
sidebar.addMenu(document.view.getSidebarMenus)
@@ -56,6 +58,7 @@
sidebar.addMenu(organization.view.getSidebarMenus)
sitemap.addPages(club.view.getDjangoURLPatterns())
+sitemap.addPages(club_app.view.getDjangoURLPatterns())
sitemap.addPages(document.view.getDjangoURLPatterns())
sitemap.addPages(host.view.getDjangoURLPatterns())
sitemap.addPages(notification.view.getDjangoURLPatterns())