app/soc/logic/models/site.py
author Lennard de Rijk <ljvderijk@gmail.com>
Sat, 07 Mar 2009 15:19:06 +0000
changeset 1713 e39ae44d0298
parent 1308 35b75ffcbb37
child 2072 eb4565a8e5b4
permissions -rw-r--r--
Added new template tag for a review. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
308
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
1308
35b75ffcbb37 Partially reverted "Update the copyright notice for 2009."
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1307
diff changeset
     3
# Copyright 2008 the Melange authors.
308
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
534
c31cfbf1a20f Replace HomeSettings with Presence Model class. Replace SiteSettings with
Todd Larsen <tlarsen@google.com>
parents: 530
diff changeset
    17
"""Site (Model) query functions.
308
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
"""
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
429
e50e18936f06 Fixed typo in e-mail address
Sverre Rabbelier <srabbelier@gmail.com>
parents: 347
diff changeset
    21
  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
308
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    22
  ]
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
1103
794162cfca92 Flush sidebar when creating site entity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1053
diff changeset
    25
from soc.cache import sidebar
1053
3b9552cf748a Rename the confusing Tossed Model class to PresenceWithToS.
Todd Larsen <tlarsen@google.com>
parents: 1051
diff changeset
    26
from soc.logic.models import presence_with_tos
316
9efdc7bc3565 Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 308
diff changeset
    27
1053
3b9552cf748a Rename the confusing Tossed Model class to PresenceWithToS.
Todd Larsen <tlarsen@google.com>
parents: 1051
diff changeset
    28
import soc.models.presence_with_tos
534
c31cfbf1a20f Replace HomeSettings with Presence Model class. Replace SiteSettings with
Todd Larsen <tlarsen@google.com>
parents: 530
diff changeset
    29
import soc.models.site
308
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
1053
3b9552cf748a Rename the confusing Tossed Model class to PresenceWithToS.
Todd Larsen <tlarsen@google.com>
parents: 1051
diff changeset
    32
class Logic(presence_with_tos.Logic):
534
c31cfbf1a20f Replace HomeSettings with Presence Model class. Replace SiteSettings with
Todd Larsen <tlarsen@google.com>
parents: 530
diff changeset
    33
  """Logic methods for the Site model.
308
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
  """
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
702
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    36
  DEF_SITE_LINK_ID = 'site'
347
52676c696cd4 First phase of making the / (site/home) view generic enough to use it for
Todd Larsen <tlarsen@google.com>
parents: 319
diff changeset
    37
535
9045b8888772 Refactor classes in soc/logic/models to make more use of inheritance. Add
Todd Larsen <tlarsen@google.com>
parents: 534
diff changeset
    38
  def __init__(self, model=soc.models.site.Site,
1053
3b9552cf748a Rename the confusing Tossed Model class to PresenceWithToS.
Todd Larsen <tlarsen@google.com>
parents: 1051
diff changeset
    39
               base_model=soc.models.presence_with_tos.PresenceWithToS):
308
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
    """Defines the name, key_name and model for this entity.
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
    """
655
9635cbaa2dcd Cleanups to the logic module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 537
diff changeset
    42
9635cbaa2dcd Cleanups to the logic module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 537
diff changeset
    43
    super(Logic, self).__init__(model=model, base_model=base_model)
308
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
1115
0a723ff3d27c Cleanups in base.Logic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1106
diff changeset
    45
  def getKeyValuesFromEntity(self, entity):
702
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    46
    """Returns the key values for the site settings.
535
9045b8888772 Refactor classes in soc/logic/models to make more use of inheritance. Add
Todd Larsen <tlarsen@google.com>
parents: 534
diff changeset
    47
752
e9a45874fe37 Some docstring fixes and unused import removal in soc.logic.models.site module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 702
diff changeset
    48
    The Site entity is a singleton, so this method returns 
e9a45874fe37 Some docstring fixes and unused import removal in soc.logic.models.site module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 702
diff changeset
    49
    a hard-coded link_id.
702
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    50
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    51
    Args:
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    52
      entity: unused
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 481
diff changeset
    53
    """
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
    54
702
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    55
    return [self.DEF_SITE_LINK_ID]
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    56
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    57
  def getKeyValuesFromFields(self, fields):
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    58
    """Extracts the key values from a dict and returns them.
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    59
752
e9a45874fe37 Some docstring fixes and unused import removal in soc.logic.models.site module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 702
diff changeset
    60
    The Site entity is a singleton, so this method returns 
e9a45874fe37 Some docstring fixes and unused import removal in soc.logic.models.site module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 702
diff changeset
    61
    a hard-coded link_id.
702
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    62
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    63
    Args:
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    64
      fields: unused
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    65
    """
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    66
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    67
    return [self.DEF_SITE_LINK_ID]
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    68
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    69
  def getKeyFieldNames(self):
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    70
    """Returns an array with the names of the Key Fields.
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    71
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    72
    The Site entity is an unscoped singleton, it's key fields consist
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    73
    of just the link_id.
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    74
    """
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    75
e3b91b6955ff Remove bogus scope from Site
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    76
    return ['link_id']
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents: 445
diff changeset
    77
851
506752de2e19 Add getSingleton() method to return the Site settings entity.
Todd Larsen <tlarsen@google.com>
parents: 752
diff changeset
    78
  def getSingleton(self):
506752de2e19 Add getSingleton() method to return the Site settings entity.
Todd Larsen <tlarsen@google.com>
parents: 752
diff changeset
    79
    """Return singleton Site settings entity, since there is always only one.
506752de2e19 Add getSingleton() method to return the Site settings entity.
Todd Larsen <tlarsen@google.com>
parents: 752
diff changeset
    80
    """
1115
0a723ff3d27c Cleanups in base.Logic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1106
diff changeset
    81
0a723ff3d27c Cleanups in base.Logic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1106
diff changeset
    82
    fields = {
0a723ff3d27c Cleanups in base.Logic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1106
diff changeset
    83
        'link_id': self.DEF_SITE_LINK_ID,
0a723ff3d27c Cleanups in base.Logic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1106
diff changeset
    84
        }
0a723ff3d27c Cleanups in base.Logic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1106
diff changeset
    85
1240
a94c9bcfa05d Always return a site singleton and fix Edit Site Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1115
diff changeset
    86
    key_name = self.getKeyNameFromFields(fields)
a94c9bcfa05d Always return a site singleton and fix Edit Site Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1115
diff changeset
    87
    singleton = self.getFromKeyName(key_name)
851
506752de2e19 Add getSingleton() method to return the Site settings entity.
Todd Larsen <tlarsen@google.com>
parents: 752
diff changeset
    88
1240
a94c9bcfa05d Always return a site singleton and fix Edit Site Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1115
diff changeset
    89
    # if there is no site singleton yet, create it
a94c9bcfa05d Always return a site singleton and fix Edit Site Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1115
diff changeset
    90
    if not singleton:
a94c9bcfa05d Always return a site singleton and fix Edit Site Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1115
diff changeset
    91
      singleton = self.updateOrCreateFromKeyName(fields, key_name)
a94c9bcfa05d Always return a site singleton and fix Edit Site Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1115
diff changeset
    92
a94c9bcfa05d Always return a site singleton and fix Edit Site Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1115
diff changeset
    93
    return singleton
1044
46907a9b0b8b Reverted r1646.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1040
diff changeset
    94
308
740090cd17c9 Added invididual model logic files
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    95
logic = Logic()