app/soc/views/models/host.py
author Todd Larsen <tlarsen@google.com>
Sat, 22 Nov 2008 08:55:55 +0000
changeset 546 850d9a5ad894
parent 514 55bd39dab49c
child 550 577dbfbeef97
permissions -rw-r--r--
Rename the User.public_name Property to simply 'name' (but leave the verbose name as "Public name"). This is to take advantage of standardizing on 'name' in the common edit template (and possibly other common templates). The Property was renamed because public_name was already a "name", unlike the recent change to the Work Model class, where 'title' was "aliases" using a tiny name() method instead. Patch by: Todd Larsen

#!/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 Host profiles.
"""

__authors__ = [
    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
  ]


from django.utils.translation import ugettext_lazy

from soc.logic import dicts
from soc.views import helper
from soc.views.models import base
from soc.views.models import role

import soc.models.host
import soc.logic.models.host
import soc.logic.models.sponsor
import soc.views.helper


class CreateForm(helper.forms.BaseForm):
  """Django form displayed when creating a Host.
  """

  class Meta:
    """Inner Meta class that defines some behavior for the form.
    """

    #: db.Model subclass for which the form will gather information
    model = soc.models.host.Host

    #: list of model fields which will *not* be gathered by the form
    exclude = ['inheritance_line']

  def clean_empty(self, field):
    data = self.cleaned_data.get(field)
    if not data or data == u'':
      return None

    return data

  def clean_home_page(self):
    return self.clean_empty('home_page')

  def clean_blog(self):
    return self.clean_empty('blog')

  def clean_photo_url(self):
    return self.clean_empty('photo_url')


class EditForm(CreateForm):
  """Django form displayed when editing a Host.
  """

  pass

class View(role.RoleView):
  """View methods for the Host model.
  """

  def __init__(self, original_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:
      original_params: a dict with params for this View
    """

    self._logic = soc.logic.models.host.logic

    params = {}

    params['logic'] = soc.logic.models.host.logic
    params['group_logic'] = soc.logic.models.sponsor.logic
    params['invite_filter'] = {'group_ln': 'link_id'}

    params['name'] = "Host"
    params['name_short'] = "Host"
    params['name_plural'] = "Hosts"
    params['url_name'] = "host"
    params['module_name'] = "host"

    params['edit_form'] = EditForm
    params['create_form'] = CreateForm

    # TODO(tlarsen) Add support for Django style template lookup
    params['edit_template'] = 'soc/models/edit.html'
    params['public_template'] = 'soc/host/public.html'
    params['list_template'] = 'soc/models/list.html'
    params['invite_template'] = 'soc/models/invite.html'

    params['lists_template'] = {
      'list_main': 'soc/list/list_main.html',
      'list_pagination': 'soc/list/list_pagination.html',
      'list_row': 'soc/host/list/host_row.html',
      'list_heading': 'soc/host/list/host_heading.html',
    }

    params['delete_redirect'] = '/' + params['url_name'] + '/list'
    params['invite_redirect'] = '/request/list'

    params = dicts.merge(original_params, params)

    role.RoleView.__init__(self, original_params=params)


view = View()

create = view.create
delete = view.delete
edit = view.edit
list = view.list
public = view.public
invite = view.invite