app/soc/views/models/notification.py
changeset 747 ad62f4c3245e
parent 738 61867ffea8a8
child 760 48d38f8a50ab
equal deleted inserted replaced
746:018efb9863dc 747:ad62f4c3245e
    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 view code for Notifications
    17 """This module contains the view code for Notifications.
    18 """
    18 """
    19 
    19 
    20 __authors__ = [
    20 __authors__ = [
    21   '"Lennard de Rijk" <ljvderijk@gmail.com>',
    21   '"Lennard de Rijk" <ljvderijk@gmail.com>',
    22 ]
    22 ]
    23 
    23 
    24 
    24 
    25 import time
    25 import time
    26 
    26 
    27 from google.appengine.api import users
       
    28 
       
    29 from django import forms
    27 from django import forms
    30 from django import http
       
    31 from django.utils.translation import ugettext_lazy
    28 from django.utils.translation import ugettext_lazy
    32 
    29 
    33 from soc.logic import dicts
    30 from soc.logic import dicts
    34 from soc.logic import validate
    31 from soc.logic import validate
    35 from soc.models import notification as notification_model
    32 from soc.models import notification as notification_model
    36 from soc.views import helper
    33 from soc.views import helper
    37 from soc.views import out_of_band
       
    38 from soc.views.helper import access
    34 from soc.views.helper import access
    39 from soc.views.helper import redirects
    35 from soc.views.helper import redirects
    40 from soc.views.models import base
    36 from soc.views.models import base
    41 from soc.logic.models import notification as notification_logic
    37 from soc.logic.models import notification as notification_logic
    42 from soc.logic.models import user as user_logic
    38 from soc.logic.models import user as user_logic
    58 
    54 
    59     # set form fields order
    55     # set form fields order
    60     self.fields.keyOrder = ['to_user', 'subject', 'message']
    56     self.fields.keyOrder = ['to_user', 'subject', 'message']
    61 
    57 
    62   class Meta:
    58   class Meta:
       
    59     """Inner Meta class that defines some behavior for the form.
       
    60     """
    63     model = notification_model.Notification
    61     model = notification_model.Notification
    64 
    62 
    65     # exclude the necessary fields from the form
    63     # exclude the necessary fields from the form
    66     exclude = ['link_id', 'scope', 'scope_path', 'from_user', 'unread']
    64     exclude = ['link_id', 'scope', 'scope_path', 'from_user', 'unread']
    67 
    65 
   120     params = dicts.merge(params, new_params)
   118     params = dicts.merge(params, new_params)
   121 
   119 
   122     super(View, self).__init__(params=params)
   120     super(View, self).__init__(params=params)
   123 
   121 
   124   def list(self, request, access_type,
   122   def list(self, request, access_type,
   125            page_name=None, params=None, seed=None, **kwargs):
   123            page_name=None, params=None, filter=None):
   126     """Lists all notifications that the current logged in user has stored.
   124     """Lists all notifications that the current logged in user has stored.
   127 
   125 
   128     for parameters see base.list()
   126     for parameters see base.list()
   129     """
   127     """
   130 
   128 
   159     current_user = user_logic.logic.getForCurrentAccount()
   157     current_user = user_logic.logic.getForCurrentAccount()
   160 
   158 
   161     to_user = user_logic.logic.getForFields(
   159     to_user = user_logic.logic.getForFields(
   162         {'link_id' : fields['to_user']}, unique=True)
   160         {'link_id' : fields['to_user']}, unique=True)
   163 
   161 
   164     fields['link_id'] = '%i' %(time.time())
   162     fields['link_id'] = '%i' % (time.time())
   165     fields['scope'] = to_user
   163     fields['scope'] = to_user
   166     fields['from_user'] = current_user
   164     fields['from_user'] = current_user
   167     fields['scope_path'] = fields['to_user']
   165     fields['scope_path'] = fields['to_user']
   168 
   166 
   169   def _editSeed(self, request, seed):
   167   def _editSeed(self, request, seed):