Exemplo n.º 1
0
    def post(self):

        receiver = None

        form = MessageForm(self)
        if form.validate():
            receiver = self.db.query(User).filter_by(
                username=form.to.data).first()
            if receiver:
                T = MessageText(subject=form.subject.data, body=form.text.data)
                self.db.add(T)
                self.db.commit()

                M = Message(sender_id=self.current_user.id,
                            receiver_id=receiver.id,
                            text_id=T.id)

                self.db.add(M)

                # send a message to myself
                if receiver.id != self.current_user.id:
                    M = Message(sender_id=self.current_user.id,
                                receiver_id=receiver.id,
                                text_id=T.id)
                    M.isinbox = False
                    self.db.add(M)

                receiver.notify()
                self.db.commit()

                url = self.reverse_url('message:inbox')
                return self.redirect(url)

            else:
                form.to.errors.append(
                    self.trans(_('Can not find user %s')) % form.to.data)
            # end if

        d = {
            'title': self.trans(_('Send message')),
            'form': form,
            'RECEIVER': receiver
        }

        self.render('message/send_message.html', **d)
Exemplo n.º 2
0
    def post(self):

        receiver = None

        form = MessageForm(self)
        if form.validate():
            receiver = self.db.query(User).filter_by(username=form.to.data).first()
            if receiver:
                T = MessageText( subject = form.subject.data,
                                 body = form.text.data )
                self.db.add(T)
                self.db.commit()

                M = Message( sender_id = self.current_user.id,
                             receiver_id = receiver.id, text_id = T.id )

                self.db.add(M)

                # send a message to myself
                if receiver.id != self.current_user.id:
                    M = Message( sender_id = self.current_user.id,
                                 receiver_id = receiver.id, text_id = T.id )
                    M.isinbox = False
                    self.db.add(M)

                receiver.notify()
                self.db.commit()

                url = self.reverse_url('message:inbox')
                return self.redirect(url)

            else:
                form.to.errors.append( self.trans(_('Can not find user %s')) % form.to.data )
            # end if

        d = { 'title': self.trans(_('Send message')),
              'form': form, 'RECEIVER': receiver }

        self.render( 'message/send_message.html', **d )
Exemplo n.º 3
0
    def post(self):

        form = MessageForm(self)

        d = { 'title': self.trans(_('Send a notice to all user')),
              'form': form }

        if form.validate():
            to = form.to.data

            T = MessageText( subject = form.subject.data,
                             body = form.text.data )
            self.db.add(T)
            self.db.commit()

            current_user_id = self.current_user.id
            text_id = T.id

            M = Message( sender_id = current_user_id,
                         receiver_id = None, text_id = text_id )
            M.isinbox = False
            self.db.add(M)

            # TODO: select method
            for U in self.db.query(User):
                M = Message( sender_id = current_user_id,
                             receiver_id = U.id, text_id = text_id )
                self.db.add(M)
                U.notify()

            self.db.commit()

            url = self.reverse_url('message:notice')
            return self.redirect( url )

        # failed
        self.render( 'message/send_notice.html', **d)
Exemplo n.º 4
0
    def post(self):

        form = MessageForm(self)

        d = {'title': self.trans(_('Send a notice to all user')), 'form': form}

        if form.validate():
            to = form.to.data

            T = MessageText(subject=form.subject.data, body=form.text.data)
            self.db.add(T)
            self.db.commit()

            current_user_id = self.current_user.id
            text_id = T.id

            M = Message(sender_id=current_user_id,
                        receiver_id=None,
                        text_id=text_id)
            M.isinbox = False
            self.db.add(M)

            # TODO: select method
            for U in self.db.query(User):
                M = Message(sender_id=current_user_id,
                            receiver_id=U.id,
                            text_id=text_id)
                self.db.add(M)
                U.notify()

            self.db.commit()

            url = self.reverse_url('message:notice')
            return self.redirect(url)

        # failed
        self.render('message/send_notice.html', **d)
Exemplo n.º 5
0
    def post(self, ID):

        M = self.my_message(ID)
        if not M:
            return self.write(self.trans(_('Can not find message %s')) % ID)

        body = self.get_argument('text', '')
        if not body:
            return self.write(self.trans(_('No content write !')))

        subject = reply_regex.sub('', M.text.subject)
        subject = self.trans(_('Re: %s')) % subject
        T = MessageText(subject=subject, body=body)
        self.db.add(T)
        self.db.commit()

        NewMsg = Message(sender_id=self.current_user.id,
                         receiver_id=M.sender_id,
                         text_id=T.id)
        NewMsg.reply_id = M.id

        self.db.add(NewMsg)

        # do not send a message to myself
        if M.sender_id != self.current_user.id:
            NewMsg = Message(sender_id=self.current_user.id,
                             receiver_id=M.sender_id,
                             text_id=T.id)
            NewMsg.reply_id = M.id
            NewMsg.isinbox = False
            self.db.add(NewMsg)

        M.sender.notify()
        self.db.commit()

        url = self.reverse_url('message:outbox')
        self.redirect(url)
Exemplo n.º 6
0
    def post(self, ID):

        M = self.my_message( ID )
        if not M:
            return self.write( self.trans(_('Can not find message %s')) % ID )

        body = self.get_argument('text', '')
        if not body:
            return self.write( self.trans(_('No content write !')) )

        subject = reply_regex.sub('', M.text.subject)
        subject = self.trans(_('Re: %s')) % subject
        T = MessageText( subject = subject, body = body )
        self.db.add(T)
        self.db.commit()

        NewMsg = Message( sender_id = self.current_user.id,
                     receiver_id = M.sender_id, text_id = T.id )
        NewMsg.reply_id = M.id

        self.db.add(NewMsg)

        # do not send a message to myself
        if M.sender_id != self.current_user.id:
            NewMsg = Message( sender_id = self.current_user.id,
                              receiver_id = M.sender_id,
                              text_id = T.id )
            NewMsg.reply_id = M.id
            NewMsg.isinbox = False
            self.db.add(NewMsg)

        M.sender.notify()
        self.db.commit()

        url = self.reverse_url('message:outbox')
        self.redirect(url)