Ejemplo n.º 1
0
 def messages(self):
     if 'message' in request.params:
         title = request.params.get('title')
         message = request.params.get('message')
         users = meta.Session.query(User).all()
         for recipient in users:
             msg = PrivateMessage(c.user, recipient, title, message)
             msg.hidden_by_sender = True
         meta.Session.commit()
         h.flash('Message sent to %d users.' % len(users))
     return render('admin/messages.mako')
Ejemplo n.º 2
0
 def delete(self, id):
     message = PrivateMessage.get(id)
     if c.user == message.recipient:
         message.hidden_by_recipient = True
         message.is_read = True
     if c.user == message.sender:
         message.hidden_by_sender = True
     meta.Session.commit()
     redirect(url(controller='messages', action='index'))
Ejemplo n.º 3
0
 def thread(self, id):
     c.message = PrivateMessage.get(id)
     if not (c.user == c.message.sender or c.user == c.message.recipient):
         abort(404)
     c.thread = c.message.thread()
     for msg in c.thread:
         if msg.recipient.id == c.user.id:
             msg.is_read = True
     meta.Session.commit()
     return render('/messages/thread.mako')
Ejemplo n.º 4
0
 def reply(self, id):
     original = PrivateMessage.get(id)
     if not (c.user == original.sender or c.user == original.recipient):
         abort(404)
     recipient = original.sender if original.recipient.id == c.user.id else original.recipient
     original.is_read = True
     thread_id = original.thread_id or original.id
     msg = PrivateMessage(c.user, recipient, original.subject,
                          request.params.get('message'),
                          thread_id=thread_id)
     meta.Session.add(msg)
     # Make sure this thread is unhidden on both sides.
     original.hidden_by_sender = False
     original.hidden_by_recipient = False
     meta.Session.commit()
     if request.params.has_key('js'):
         return _('Message sent.')
     h.flash(_('Message sent.'))
     redirect(url(controller='messages', action='thread', id=thread_id))