app/soc/views/models/host.py
author Sverre Rabbelier <srabbelier@gmail.com>
Mon, 17 Nov 2008 00:01:59 +0000
changeset 497 73666a7cd718
parent 495 87afae6e4c51
child 499 d22e4fe8e64b
permissions -rw-r--r--
Added a default _editSeed method Also added the invite shortcut in the host view.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    17
"""Views for Host profiles.
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
"""
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
429
e50e18936f06 Fixed typo in e-mail address
Sverre Rabbelier <srabbelier@gmail.com>
parents: 413
diff changeset
    21
    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    22
  ]
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
from django.utils.translation import ugettext_lazy
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
from soc.logic import dicts
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
from soc.views import helper
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
from soc.views.models import base
494
5e9c656a1b68 Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 493
diff changeset
    30
from soc.views.models import role
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    32
import soc.models.host
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    33
import soc.logic.models.host
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    34
import soc.logic.models.sponsor
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
import soc.views.helper
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    37
408
7cd6bdfbf95c Inherit from BaseForm in all forms instead of from DbModelForm. This change doesn't include changes to templates and usage of as_table everywhere (work in progress).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 406
diff changeset
    38
class CreateForm(helper.forms.BaseForm):
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    39
  """Django form displayed when creating a Host.
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
  """
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    42
  class Meta:
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    43
    """Inner Meta class that defines some behavior for the form.
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    44
    """
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    46
    #: db.Model subclass for which the form will gather information
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    47
    model = soc.models.host.Host
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
    #: list of model fields which will *not* be gathered by the form
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    50
    exclude = ['inheritance_line']
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    51
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    52
  def clean_empty(self, field):
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    53
    data = self.cleaned_data.get(field)
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    54
    if not data or data == u'':
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    55
      return None
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    56
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    57
    return data
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    58
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    59
  def clean_home_page(self):
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    60
    return self.clean_empty('home_page')
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    62
  def clean_blog(self):
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    63
    return self.clean_empty('blog')
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    64
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    65
  def clean_photo_url(self):
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    66
    return self.clean_empty('photo_url')
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    67
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    68
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    69
class EditForm(CreateForm):
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    70
  """Django form displayed when editing a Host.
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    71
  """
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    72
431
96b6ee5efdc3 Added a missing 'pass' statement
Sverre Rabbelier <srabbelier@gmail.com>
parents: 429
diff changeset
    73
  pass
96b6ee5efdc3 Added a missing 'pass' statement
Sverre Rabbelier <srabbelier@gmail.com>
parents: 429
diff changeset
    74
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    75
class View(role.RoleView):
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    76
  """View methods for the Host model
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    77
  """
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    78
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    79
  def __init__(self, original_params=None, original_rights=None):
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    80
    """Defines the fields and methods required for the base View class
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    81
    to provide the user with list, public, create, edit and delete views.
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    82
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    83
    Params:
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    84
      original_params: a dict with params for this View
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    85
      original_rights: a dict with right definitions for this View
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    86
    """
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    87
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    88
    self._logic = soc.logic.models.host.logic
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    89
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    90
    params = {}
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    91
    rights = {}
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    92
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    93
    params['logic'] = soc.logic.models.host.logic
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    94
    params['group_logic'] = soc.logic.models.sponsor.logic
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    95
    params['invite_filter'] = {'group_ln': 'link_name'}
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    96
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    97
    params['name'] = "Host"
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    98
    params['name_short'] = "Host"
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    99
    params['name_plural'] = "Hosts"
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   100
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   101
    params['edit_form'] = EditForm
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   102
    params['create_form'] = CreateForm
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   103
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   104
    # TODO(tlarsen) Add support for Django style template lookup
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
   105
    params['edit_template'] = 'soc/models/edit.html'
409
9d24850db88f Addressed comments by Pawel and Todd
Sverre Rabbelier <srabbelier@gmail.com>
parents: 408
diff changeset
   106
    params['public_template'] = 'soc/host/public.html'
445
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 431
diff changeset
   107
    params['list_template'] = 'soc/models/list.html'
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
   108
    params['invite_template'] = 'soc/models/invite.html'
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   109
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   110
    params['lists_template'] = {
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   111
      'list_main': 'soc/list/list_main.html',
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   112
      'list_pagination': 'soc/list/list_pagination.html',
413
ec1b590418df Rename Host list templates from group_<something> to host_<something> and move then to soc/host/list folder. Update affected files with new paths.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 409
diff changeset
   113
      'list_row': 'soc/host/list/host_row.html',
ec1b590418df Rename Host list templates from group_<something> to host_<something> and move then to soc/host/list folder. Update affected files with new paths.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 409
diff changeset
   114
      'list_heading': 'soc/host/list/host_heading.html',
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   115
    }
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   116
489
35fbec27f6cb Fixed typo in soc.views.models.host redirects
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
   117
    params['delete_redirect'] = '/host/list'
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
   118
    params['invite_redirect'] = '/request/list'
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   119
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   120
    params['save_message'] = [ugettext_lazy('Profile saved.')]
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   121
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   122
    params['edit_params'] = {
402
021e86368600 Incorperated suggestions by Todd
Sverre Rabbelier <srabbelier@gmail.com>
parents: 400
diff changeset
   123
        self.DEF_SUBMIT_MSG_PARAM_NAME: self.DEF_SUBMIT_MSG_PROFILE_SAVED,
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   124
        }
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   125
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   126
    rights['list'] = [helper.access.checkIsDeveloper]
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   127
    rights['delete'] = [helper.access.checkIsDeveloper]
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   128
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   129
    params = dicts.merge(original_params, params)
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   130
    rights = dicts.merge(original_rights, rights)
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   131
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
   132
    role.RoleView.__init__(self, original_rights=rights, original_params=params)
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   133
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   134
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   135
view = View()
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   136
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   137
create = view.create
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
   138
delete = view.delete
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   139
edit = view.edit
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   140
list = view.list
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   141
public = view.public
497
73666a7cd718 Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 495
diff changeset
   142
invite = view.invite