app/soc/logic/models/request.py
author Sverre Rabbelier <srabbelier@gmail.com>
Sat, 31 Jan 2009 12:59:52 +0000
changeset 1106 e14b0995cf29
parent 1085 0afbdd0905ef
child 1115 0a723ff3d27c
permissions -rw-r--r--
Flush sidebar when creating a new entity Patch by: Sverre Rabbelier
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
631
3763d36bcebc Fix typo and too long lines in soc.logic.models.request module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 620
diff changeset
    17
"""Request (Model) query functions.
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
"""
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
674
0158b11cbf6d More DI on scope_logic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    21
  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
618
b2319f2633bc Added invitation received message upon creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 562
diff changeset
    22
  '"Lennard de Rijk" <ljvderijk@gmail.com>'
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
  ]
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
635
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 631
diff changeset
    25
import soc.models.request
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
635
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 631
diff changeset
    27
from soc.logic.helper import notifications
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
from soc.logic.models import base
674
0158b11cbf6d More DI on scope_logic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    29
from soc.logic.models import sponsor as sponsor_logic
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
class Logic(base.Logic):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 495
diff changeset
    33
  """Logic methods for the Request model.
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
  """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
535
9045b8888772 Refactor classes in soc/logic/models to make more use of inheritance. Add
Todd Larsen <tlarsen@google.com>
parents: 530
diff changeset
    36
  def __init__(self, model=soc.models.request.Request,
674
0158b11cbf6d More DI on scope_logic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    37
               base_model=None, scope_logic=sponsor_logic):
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
    """Defines the name, key_name and model for this entity.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
    """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
674
0158b11cbf6d More DI on scope_logic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    41
    super(Logic, self).__init__(model, base_model=base_model,
0158b11cbf6d More DI on scope_logic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 655
diff changeset
    42
                                scope_logic=scope_logic)
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
  def getKeyValues(self, entity):
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
    """See base.Logic.getKeyNameValues.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
    """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
676
c6433532ddff Swap the order of request key fields
Sverre Rabbelier <srabbelier@gmail.com>
parents: 674
diff changeset
    48
    return [entity.scope.link_id, entity.role, entity.link_id]
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
  def getKeyValuesFromFields(self, fields):
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
    """See base.Logic.getKeyValuesFromFields.
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    52
    """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    53
676
c6433532ddff Swap the order of request key fields
Sverre Rabbelier <srabbelier@gmail.com>
parents: 674
diff changeset
    54
    return [fields['scope_path'], fields['role'], fields['link_id']]
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    55
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    56
  def getKeyFieldNames(self):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 495
diff changeset
    57
    """See base.Logic.getKeyFieldNames.
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    58
    """
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    59
676
c6433532ddff Swap the order of request key fields
Sverre Rabbelier <srabbelier@gmail.com>
parents: 674
diff changeset
    60
    return ['scope_path', 'role', 'link_id']
618
b2319f2633bc Added invitation received message upon creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 562
diff changeset
    61
  
b2319f2633bc Added invitation received message upon creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 562
diff changeset
    62
  def _onCreate(self, entity):
b2319f2633bc Added invitation received message upon creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 562
diff changeset
    63
    """Sends out a message notifying users about the new invite/request.
b2319f2633bc Added invitation received message upon creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 562
diff changeset
    64
    """
818
ddd102e82107 Fixed whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 676
diff changeset
    65
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 928
diff changeset
    66
    if entity.status == 'group_accepted':
618
b2319f2633bc Added invitation received message upon creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 562
diff changeset
    67
      # this is an invite
635
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 631
diff changeset
    68
      notifications.sendInviteNotification(entity)
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 928
diff changeset
    69
    elif entity.status == 'new':
618
b2319f2633bc Added invitation received message upon creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 562
diff changeset
    70
      # this is a request
b2319f2633bc Added invitation received message upon creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 562
diff changeset
    71
      # TODO(Lennard) Create a new request message
b2319f2633bc Added invitation received message upon creating a new invite.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 562
diff changeset
    72
      pass
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    73
1106
e14b0995cf29 Flush sidebar when creating a new entity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1085
diff changeset
    74
    super(Logic, self)._onCreate(entity)
e14b0995cf29 Flush sidebar when creating a new entity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1085
diff changeset
    75
495
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    76
87afae6e4c51 Added basic 'invite' functionality
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    77
logic = Logic()