app/soc/views/models/host.py
author Sverre Rabbelier <srabbelier@gmail.com>
Thu, 20 Nov 2008 20:58:46 +0000
changeset 514 55bd39dab49c
parent 512 aae25d2b4464
child 550 577dbfbeef97
permissions -rw-r--r--
Move saved message to the base class This removes some duplicate code that was in all the child classes of soc.views.models.base.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):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 497
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
507
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
    79
  def __init__(self, original_params=None):
400
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
    """
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    86
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    87
    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
    88
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    89
    params = {}
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    90
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    91
    params['logic'] = soc.logic.models.host.logic
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    92
    params['group_logic'] = soc.logic.models.sponsor.logic
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 507
diff changeset
    93
    params['invite_filter'] = {'group_ln': 'link_id'}
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents: 494
diff changeset
    94
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    95
    params['name'] = "Host"
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    96
    params['name_short'] = "Host"
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
    97
    params['name_plural'] = "Hosts"
502
e1e24c0a4e82 Add new parameters to views: url_name which is name used in urls (instead of using lower entity names) and module_name which is used for constructing django urls. Append changes to all affected files. Fix some title names. Change urls that included underscores like "site_settings" into urls with slash "site/settings". Plus some other minor fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 499
diff changeset
    98
    params['url_name'] = "host"
e1e24c0a4e82 Add new parameters to views: url_name which is name used in urls (instead of using lower entity names) and module_name which is used for constructing django urls. Append changes to all affected files. Fix some title names. Change urls that included underscores like "site_settings" into urls with slash "site/settings". Plus some other minor fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 499
diff changeset
    99
    params['module_name'] = "host"
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
502
e1e24c0a4e82 Add new parameters to views: url_name which is name used in urls (instead of using lower entity names) and module_name which is used for constructing django urls. Append changes to all affected files. Fix some title names. Change urls that included underscores like "site_settings" into urls with slash "site/settings". Plus some other minor fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 499
diff changeset
   117
    params['delete_redirect'] = '/' + params['url_name'] + '/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
507
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
   120
    params = dicts.merge(original_params, params)
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   121
507
3603fdafabf7 Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents: 502
diff changeset
   122
    role.RoleView.__init__(self, original_params=params)
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   123
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
view = View()
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   126
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   127
create = view.create
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 402
diff changeset
   128
delete = view.delete
400
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   129
edit = view.edit
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   130
list = view.list
8f07048d84ef Added a generic version of the Document views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   131
public = view.public
497
73666a7cd718 Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 495
diff changeset
   132
invite = view.invite