Exemple #1
0
    def get(self):

        UID = self.get_argument('user', 0)
        ORIG_MSG_ID = self.get_argument('origmsg', 0)

        form = MessageForm(self)

        if UID:
            receiver = self.db.query(User).get(UID)
            if receiver:
                form.to.data = receiver.username
        else:
            receiver = None

        if ORIG_MSG_ID:
            M = self.db.query(Message).get(ORIG_MSG_ID)
            if M:
                form.to.data = M.sender.username
                subject = reply_regex.sub('', M.text.subject)
                form.subject.data = self.trans(_('Re: %s')) % subject
                form.text.data = '<pre>%s</pre>' % M.text.body

        d = {
            'title': self.trans(_('Send message')),
            'form': form,
            'RECEIVER': receiver
        }
        self.render('message/send_message.html', **d)
Exemple #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)
Exemple #3
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 )
Exemple #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)
Exemple #5
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)
Exemple #6
0
    def get(self):

        form = MessageForm(self)

        d = {'title': self.trans(_('Send a notice to all user')), 'form': form}
        self.render('message/send_notice.html', **d)