app/soc/views/models/site_settings.py
changeset 446 0b479d573a4c
child 452 160c748988a2
equal deleted inserted replaced
445:31927f21970d 446:0b479d573a4c
       
     1 #!/usr/bin/python2.5
       
     2 #
       
     3 # Copyright 2008 the Melange authors.
       
     4 #
       
     5 # Licensed under the Apache License, Version 2.0 (the "License");
       
     6 # you may not use this file except in compliance with the License.
       
     7 # You may obtain a copy of the License at
       
     8 #
       
     9 #   http://www.apache.org/licenses/LICENSE-2.0
       
    10 #
       
    11 # Unless required by applicable law or agreed to in writing, software
       
    12 # distributed under the License is distributed on an "AS IS" BASIS,
       
    13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    14 # See the License for the specific language governing permissions and
       
    15 # limitations under the License.
       
    16 
       
    17 """Views for Site Settings.
       
    18 """
       
    19 
       
    20 __authors__ = [
       
    21     '"Sverre Rabbelier" <sverre@rabbelier.nl>',
       
    22   ]
       
    23 
       
    24 
       
    25 from google.appengine.ext import db
       
    26 from google.appengine.api import users
       
    27 
       
    28 from django import forms
       
    29 from django.utils.translation import ugettext_lazy
       
    30 
       
    31 from soc.logic import dicts
       
    32 from soc.logic import validate
       
    33 from soc.views import helper
       
    34 from soc.views.helper import widgets
       
    35 from soc.views.models import home_settings
       
    36 
       
    37 import soc.models.site_settings
       
    38 import soc.logic.models.site_settings
       
    39 import soc.logic.dicts
       
    40 import soc.views.helper
       
    41 import soc.views.helper.widgets
       
    42 
       
    43 
       
    44 class CreateForm(home_settings.SettingsValidationForm):
       
    45   """Django form displayed when creating or editing Site Settings.
       
    46   """
       
    47 
       
    48   class Meta:
       
    49     """Inner Meta class that defines some behavior for the form.
       
    50     """
       
    51     #: db.Model subclass for which the form will gather information
       
    52     model = soc.models.site_settings.SiteSettings
       
    53 
       
    54     #: list of model fields which will *not* be gathered by the form
       
    55     exclude = ['inheritance_line', 'home']
       
    56 
       
    57 
       
    58 class EditForm(CreateForm):
       
    59   """Django form displayed a Document is edited.
       
    60   """
       
    61 
       
    62   pass
       
    63 
       
    64 
       
    65 class View(home_settings.View):
       
    66   """View methods for the Docs model
       
    67   """
       
    68 
       
    69   def __init__(self, original_params=None, original_rights=None):
       
    70     """Defines the fields and methods required for the base View class
       
    71     to provide the user with list, public, create, edit and delete views.
       
    72 
       
    73     Params:
       
    74       original_params: a dict with params for this View
       
    75       original_rights: a dict with right definitions for this View
       
    76     """
       
    77 
       
    78     params = {}
       
    79     rights = {}
       
    80 
       
    81     params['name'] = "SiteSetting"
       
    82     params['name_short'] = "Site"
       
    83     params['name_plural'] = "SiteSettings"
       
    84 
       
    85     params['edit_form'] = EditForm
       
    86     params['create_form'] = CreateForm
       
    87 
       
    88     params['lists_template'] = {
       
    89       'list_main': 'soc/list/list_main.html',
       
    90       'list_pagination': 'soc/list/list_pagination.html',
       
    91       'list_row': 'soc/site_settings/list/site_row.html',
       
    92       'list_heading': 'soc/site_settings/list/site_heading.html',
       
    93     }
       
    94 
       
    95     params['delete_redirect'] = 'site/list'
       
    96     params['create_redirect'] = 'site/edit'
       
    97 
       
    98     params = dicts.merge(original_params, params)
       
    99     rights = dicts.merge(original_rights, rights)
       
   100 
       
   101     home_settings.View.__init__(self, original_rights=rights, original_params=params, stop=True)
       
   102 
       
   103     self._logic = soc.logic.models.site_settings.logic
       
   104 
       
   105   def main_public(self, request, page=None, **kwargs):
       
   106     """Displays the main site settings page
       
   107 
       
   108     Args:
       
   109       request: the standard Django HTTP request object
       
   110       page: a soc.logic.site.page.Page object
       
   111       kwargs: not used
       
   112     """
       
   113 
       
   114     keys = self._logic.getKeyFieldNames()
       
   115     values = self._logic.getMainKeyValues()
       
   116     key_values = dicts.zip(keys, values)
       
   117 
       
   118     return self.public(request, page, **key_values)
       
   119 
       
   120   def main_edit(self, request, page=None, **kwargs):
       
   121     """Displays the edit page for the main site settings page
       
   122 
       
   123     Args:
       
   124       request: the standard Django HTTP request object
       
   125       page: a soc.logic.site.page.Page object
       
   126       kwargs: not used
       
   127     """
       
   128 
       
   129     keys = self._logic.getKeyFieldNames()
       
   130     values = self._logic.getMainKeyValues()
       
   131     key_values = dicts.zip(keys, values)
       
   132 
       
   133     return self.edit(request, page, **key_values)
       
   134 
       
   135 
       
   136 view = View()
       
   137 
       
   138 create = view.create
       
   139 edit = view.edit
       
   140 delete = view.delete
       
   141 list = view.list
       
   142 public = view.public
       
   143 main_public = view.main_public
       
   144 main_edit = view.main_edit