app/soc/models/group.py
changeset 181 fdd29818a954
parent 174 f065ee52d759
child 208 e076aee6e90f
equal deleted inserted replaced
180:a1c6123f9d06 181:fdd29818a954
     3 # Copyright 2008 the Melange authors.
     3 # Copyright 2008 the Melange authors.
     4 #
     4 #
     5 # Licensed under the Apache License, Version 2.0 (the "License");
     5 # Licensed under the Apache License, Version 2.0 (the "License");
     6 # you may not use this file except in compliance with 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
     7 # You may obtain a copy of the License at
     8 #
     8 # 
     9 #   http://www.apache.org/licenses/LICENSE-2.0
     9 #   http://www.apache.org/licenses/LICENSE-2.0
    10 #
    10 # 
    11 # Unless required by applicable law or agreed to in writing, software
    11 # Unless required by applicable law or agreed to in writing, software
    12 # distributed under the License is distributed on an "AS IS" BASIS,
    12 # distributed under the License is distributed on an "AS IS" BASIS,
    13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14 # See the License for the specific language governing permissions and
    14 # See the License for the specific language governing permissions and
    15 # limitations under the License.
    15 # limitations under the License.
    16 
    16 
    17 """This module contains the Group Model."""
    17 """This module contains the Group Model."""
    18 
    18 
    19 __authors__ = [
    19 __authors__ = [
    20   '"Todd Larsen" <tlarsen@google.com>',
    20   '"Todd Larsen" <tlarsen@google.com>',
       
    21   '"Pawel Solyga" <pawel.solyga@gmail.com>',
    21 ]
    22 ]
    22 
    23 
    23 from google.appengine.ext import db
    24 from google.appengine.ext import db
    24 
    25 
    25 from django.utils.translation import ugettext_lazy
    26 from django.utils.translation import ugettext_lazy
    26 
    27 
    27 from soc.models import base
    28 from soc.models import base
       
    29 from soc.models import countries
    28 import soc.models.user
    30 import soc.models.user
    29 
       
    30 
    31 
    31 class Group(base.ModelWithFieldAttributes):
    32 class Group(base.ModelWithFieldAttributes):
    32   """Common data fields for all groups.
    33   """Common data fields for all groups.
    33 
    34 
    34   A Group entity participates in the following relationships implemented as
    35   A Group entity participates in the following relationships
    35   a db.ReferenceProperty elsewhere in another db.Model:
    36   implemented as a db.ReferenceProperty elsewhere in another db.Model:
    36 
    37 
    37    school), club), sponsor), org)
    38    school), club), sponsor), org)
    38      a 1:1 relationship with each entity containing a more specific type of
    39      a 1:1 relationship with each entity containing a more specific type of
    39      Group.  These relationships are represented explicitly in the other
    40      Group.  These relationships are represented explicitly in the other
    40      "group" models by a db.ReferenceProperty named 'group'.  The
    41      "group" models by a db.ReferenceProperty named 'group'.  The
    41      collection_name argument to db.ReferenceProperty should be set to the
    42      collection_name argument to db.ReferenceProperty should be set to the
    42      singular of the entity model name of the other "group" class.  The
    43      singular of the entity model name of the other "group" class.  The
    43      above relationship names correspond, respectively to these Models:
    44      above relationship names correspond, respectively to these Models:
    44        School, Club, Sponsor, Organization
    45        School, Club, Sponsor, Organization
    45      The relationships listed here are mutually exclusive.  For example,
    46      The relationships listed here are mutually exclusive.  For example,
    46      a Group cannot be both a School and a Club at the same time.
    47      a Group cannot be both a School and a Club at the same time.  
    47   """
    48   """
       
    49 
       
    50   #: Required field storing name of the group.
       
    51   name = db.StringProperty(required=True,
       
    52       verbose_name=ugettext_lazy('Name'))
       
    53   name.help_text = ugettext_lazy('Complete, formal name of the group.')  
       
    54   
       
    55   #: Required field storing linkname used in URLs to identify group.
       
    56   #: Lower ASCII characters only.
       
    57   link_name = db.StringProperty(required=True,
       
    58       verbose_name=ugettext_lazy('Link name'))
       
    59   link_name.help_text = ugettext_lazy(
       
    60       'Field used in URLs to identify group. '
       
    61       'Lower ASCII characters only.')
       
    62   
       
    63   #: Required field storing short name of the group.
       
    64   #: It can be used for displaying group as sidebar menu item.
       
    65   short_name = db.StringProperty(required=True,
       
    66       verbose_name=ugettext_lazy('Short name'))
       
    67   short_name.help_text = ugettext_lazy('Short name used for sidebar menu')
    48 
    68 
    49   #: Required many:1 relationship indicating the founding User of the
    69   #: Required many:1 relationship indicating the founding User of the
    50   #: Group (this relationship is needed to keep track of lifetime group
    70   #: Group (this relationship is needed to keep track of lifetime group
    51   #: creation limits, used to prevent spamming, etc.).
    71   #: creation limits, used to prevent spamming, etc.).
    52   founder = db.ReferenceProperty(reference_class=soc.models.user.User,
    72   founder = db.ReferenceProperty(reference_class=soc.models.user.User,
    53                                  required=True, collection_name="groups")
    73                                  required=True, collection_name="groups")  
    54 
    74   #: Optional field storing a home page URL of the group.
    55   #: Required organization name; can only be lower ASCII, not UTF-8
    75   home_page = db.LinkProperty(
    56   #: text, because it is used, for example, as part of the shipping
    76       verbose_name=ugettext_lazy('Home Page URL'))
    57   #: address.
    77   
    58   name = db.StringProperty(required=True)
    78   #: Optional email address used as the "public" contact mechanism for
    59 
       
    60   #: Optional field used as a display name, such in Group lists displayed
       
    61   #: in the web application.  Should be the entire display name in the
       
    62   #: format the Group would like it displayed. Display names can be any
       
    63   #: valid UTF-8 text.
       
    64   displayname = db.StringProperty()
       
    65 
       
    66   #: Required email address used as the "public" contact mechanism for
       
    67   #: the Group (as opposed to the founder.id email address which is kept
    79   #: the Group (as opposed to the founder.id email address which is kept
    68   #: secret, revealed only to Developers).
    80   #: secret, revealed only to Developers).
    69   email = db.EmailProperty(required=True)
    81   email = db.EmailProperty(
       
    82       verbose_name=ugettext_lazy('Email'))  
       
    83   
       
    84   #: Optional field storing description of the group.
       
    85   description = db.TextProperty(
       
    86       verbose_name=ugettext_lazy('Description'))
       
    87       
       
    88   #: Optional field containing a group street address.
       
    89   #: Group street address can only be lower ASCII, not UTF-8 text, 
       
    90   #: because, if supplied, it is used as a shipping address.
       
    91   street = db.StringProperty(
       
    92       verbose_name=ugettext_lazy('Street address'))
       
    93   street.help_text = ugettext_lazy(
       
    94       'street number and name, lower ASCII characters only')
    70 
    95 
    71   #: Required home page URL.
    96   #: Optional field containing group address city.
    72   homepage = db.LinkProperty(required=True)
    97   #: City can only be lower ASCII, not UTF-8 text, because, if
       
    98   #: supplied, it is used as a shipping address.
       
    99   city = db.StringProperty(
       
   100       verbose_name=ugettext_lazy('City'))
       
   101   city.help_text = ugettext_lazy('lower ASCII characters only')
    73 
   102 
    74   # TODO(pawel.solyga): merge in the (required) mailing address stuff here...
   103   #: Optional field containing group address state or province.
       
   104   #: Group state/province can only be lower ASCII, not UTF-8
       
   105   #: text, because, if supplied, it is used as a shipping address.
       
   106   state = db.StringProperty(
       
   107       verbose_name=ugettext_lazy('State/Province'))
       
   108   state.help_text = ugettext_lazy(
       
   109       'optional if country/territory does not have states or provinces, '
       
   110       'lower ASCII characters only')
    75 
   111 
    76   # TODO(pawel.solyga): merge in the (optional) shipping address stuff here...
   112   #: Optional field containing address country or territory of the group.
       
   113   country = db.StringProperty(
       
   114       verbose_name=ugettext_lazy('Country/Territory'),
       
   115       choices=countries.COUNTRIES_AND_TERRITORIES)
    77 
   116 
    78   #: Required contact phone number that will be, amongst other uses,
   117   #: Optional field containing address postal code of the group (ZIP code in
       
   118   #: the United States). Postal code can only be lower ASCII, not UTF-8 
       
   119   #: text, because, if supplied, it is used as a shipping address.
       
   120   postalcode = db.StringProperty(
       
   121       verbose_name=ugettext_lazy('ZIP/Postal Code'))
       
   122   postalcode.help_text=ugettext_lazy('lower ASCII characters only')
       
   123 
       
   124   #: Optional contact phone number that will be, amongst other uses,
    79   #: supplied to shippers along with the shipping address; kept private.
   125   #: supplied to shippers along with the shipping address; kept private.
    80   phone = db.PhoneNumberProperty(required=True)
   126   phone = db.PhoneNumberProperty(
    81 
   127       verbose_name=ugettext_lazy('Phone Number'))
       
   128   phone.help_text = ugettext_lazy(
       
   129       'include complete international calling number with country code')