Exemple #1
0
def addmessage(id=None,subj=None):
    form = MessageForm()
    if id:
        recp = Users.objects(id=id).get()
        form.recipients.data = recp.username
    
    if form.validate_on_submit():
        if g.user.username in form.recipients.data:
            flash('Expeditorul nu poate fi si destinatar!',category='alert-danger')
            return redirect(request.referrer)
        else:
            recs = []
            for i in form.recipients.data.split(','):
                try:
                    temp_user = Users.objects(username=i).get()
                    recs.append(temp_user)
                except:
                    flash('Utilizatorul '+i+' nu exista!')
                    return redirect(request.referrer)

            msg = Messages(sender=g.user, recipients=recs, title=form.title.data, content=form.content.data, ownerid=g.user, folder='trimise',read=True, msgid=generate_msgid())
            msg.save()
            for i in recs:
                print i.username
                temp = Messages(sender=g.user, recipients=recs, title=form.title.data, content=form.content.data, ownerid=i, folder='inbox', msgid=msg.msgid, date=msg.date)
                temp.save()
            flash('Mesaj trimis!',category='alert-success')
            return redirect(url_for('messages.list'))

    return render_template('messages/add.html',form=form)
Exemple #2
0
def send_message_to_org(id):
    recipient_org = Organization.query.filter_by(id=id).first_or_404()
    form = MessageForm()
    if form.validate_on_submit():
        thread = Thread()
        db.session.add(thread)
        recipients = User.query
        for recipitent in recipients:
            recipitent.add_thread(thread)
        current_user.add_thread(thread)
        msg = Message(sender=current_user,
                      recipient_org=recipient_org,
                      thread=thread,
                      body=form.message.data)
        db.session.add(msg)

        recipient.add_notification('unread_message_count',
                                   recipient.new_messages_count())

        db.session.commit()
        flash('Your message has been sent.')
        return redirect(url_for('messages.messages'))
    return render_template('messages/send_message.html',
                           title='Send Message',
                           form=form,
                           recipient_org=recipient_org)
Exemple #3
0
def team_members():
    enlister = User.query.filter_by(id=current_user.invited_by).first()
    partners = []
    if enlister is not None:
        partners = User.query.filter_by(
            invited_by=enlister.id,
            is_active=True).order_by('first_name').all()
        for user in partners:
            if user.id == current_user.id:
                partners.remove(user)
        partners.append(enlister)
    enlistees = User.query.filter_by(invited_by=current_user.id,
                                     is_active=True).all()
    form = MessageForm()
    if form.validate_on_submit():
        user_ids = form.user_list.data
        message = Message(subject=form.subject.data,
                          content=form.content.data,
                          message_type=1,
                          created_by=current_user.id,
                          is_urgent=False)
        db.session.add(message)
        db.session.commit()
        message_id = message.id
        for id in user_ids.split(","):
            user_message = UserMessage(message_id=message_id, user_id=int(id))
            db.session.add(user_message)
        db.session.commit()
        flash('Message was successfully submitted', 'success')
        return redirect(url_for('main.home'))
    return render_template('my_team.html',
                           enlister=enlister,
                           partners=partners,
                           enlistees=enlistees,
                           form=form)
Exemple #4
0
def replymessage(id=None):
    form = MessageForm()
    if id:
        tmp = Messages.objects(id=id).get()
        temp_recps = [tmp.sender.username]
        for i in tmp.recipients:
            if i.username != g.user.username:
                temp_recps.append(i.username)
        form.recipients.data = ','.join(temp_recps)
        if 'RE:' not in tmp.title:
            form.title.data = 'RE:' + tmp.title
    else:
        flash('Mesajul nu exista!', category='alert-danger')
        return redirect(request.referrer)

    if form.validate_on_submit():
        if g.user.username in form.recipients.data:
            flash('Expeditorul nu poate fi si destinatar!',
                  category='alert-danger')
            return redirect(request.referrer)
        else:
            threadid = Messages.objects(id=id).get().msgid
            recs = []
            for i in form.recipients.data.split(','):
                try:
                    temp_user = Users.objects(username=i).get()
                    recs.append(temp_user)
                except:
                    flash('Utilizatorul ' + i + ' nu exista!')
                    return redirect(request.referrer)

            msg = Messages(sender=g.user,
                           recipients=recs,
                           title=form.title.data,
                           content=form.content.data,
                           ownerid=g.user,
                           folder='trimise',
                           read=True,
                           threadid=threadid,
                           msgid=generate_msgid())
            msg.save()
            for i in recs:
                temp = Messages(sender=g.user,
                                recipients=recs,
                                title=form.title.data,
                                content=form.content.data,
                                ownerid=i,
                                folder='inbox',
                                msgid=msg.msgid,
                                date=msg.date,
                                threadid=threadid)
                temp.save()
            flash('Mesaj trimis!', category='alert-success')
            return redirect(url_for('messages.list'))

    return render_template('messages/add.html', form=form)
Exemple #5
0
def new_message():
    form = MessageForm()
    if form.validate_on_submit():
        message = Message(body=form.body.data)
        db.session.add(message)
        db.session.commit()
        flash("Message created successfully")
        return redirect(url_for("posts.list_posts"))
    else:
        return render_template("posts/form.html", form=form, url=url_for("messages.new_message"))
Exemple #6
0
def send_message(recipient):
    user = db.session.query(User).filter_by(username=recipient).first_or_404()
    form = MessageForm()
    if form.validate_on_submit():
        _sent_message(current_user, user, form.message.data)
        return redirect(url_for('main.user', username=recipient))
    return render_template('messages/send_message.html',
                           title=_('Send Message'),
                           form=form,
                           recipient=recipient)
def forum_messages(course_code):
    current_user.last_message_read_time = datetime.now()  # pragma: no cover
    db.session.commit()  # pragma: no cover
    form = MessageForm()  # pragma: no cover
    forum = Forum.query.filter_by(
        course=course_code).first_or_404()  # pragma: no cover
    course = Course.query.filter_by(
        course_code=course_code).first_or_404()  # pragma: no cover
    ordered_messages = forum.messages_received.order_by(
        Message.upvote_count.desc())  # pragma: no cover
    if request.method == 'GET':  # pragma: no cover
        page = request.args.get('page', 1, type=int)
        messages = forum.messages_received.paginate(
            page, current_app.config['POSTS_PER_PAGE'], False)
        next_url = url_for('messages.forum_messages',course_code=course_code ,page=messages.next_num) \
            if messages.has_next else None
        prev_url = url_for('messages.forum_messages',course_code=course_code, page=messages.prev_num) \
            if messages.has_prev else None

    if form.validate_on_submit():  # pragma: no cover
        myfile = request.files['message_attachment']
        if form.message.data == '':
            if myfile.filename == '':
                return redirect(
                    url_for('messages.forum_messages',
                            course_code=course_code))
        if myfile.filename == '':
            msg = Message(author=current_user,
                          body=form.message.data,
                          forum=forum,
                          upvote_count=0)
        else:  # pragma: no cover
            filename = secure_filename(myfile.filename)
            myfile.save(os.path.join(UPLOAD_FOLDER, filename))
            msg = Message(author=current_user,
                          body=form.message.data,
                          forum=forum,
                          attachment_name=filename,
                          upvote_count=0)

        db.session.add(msg)
        db.session.commit()

        return redirect(
            url_for('messages.forum_messages', course_code=course_code))
    return render_template(
        'messages/forum_messages.html',
        title='forum messages',
        messages=messages.items,
        next_url=next_url,
        prev_url=prev_url,
        form=form,
        course_code=course_code,
        ordered_messages=ordered_messages)  # pragma: no cover
Exemple #8
0
def send_message(recipient):
    user = User.query.filter_by(username=recipient).first_or_404()
    form = MessageForm()
    if form.validate_on_submit():
        msg = Message(sender=current_user,
                      recipient=user,
                      body=form.message.data)
        db.session.add(msg)
        user.add_notification('unread_message_count', user.new_messages())
        db.session.commit()
        flash(_('Your message has been sent.'))
        return redirect(url_for('main.user', username=recipient))
    return render_template('messages/send_message.html',
                           title=_('Send Message'),
                           form=form,
                           recipient=recipient)
Exemple #9
0
def view_message(thread_id: str):
    current_user.add_notification('unread_message_count',
                                  current_user.new_messages_count())
    db.session.commit()
    form = MessageForm()

    if isint(thread_id):
        thread = current_user.threads.filter_by(id=thread_id).first_or_404()

    else:
        recipient = User.query.filter_by(username=thread_id).first_or_404()
        thread = recipient.threads.intersect(current_user.threads).first()
        if not thread:
            thread = Thread()
            db.session.add(thread)
            recipient.add_thread(thread)
            recipient.add_notification('unread_message_count',
                                       recipient.new_messages_count())
            current_user.add_thread(thread)
            db.session.commit()
            return redirect(
                url_for('messages.view_message', thread_id=recipient.username))

    recipients = User.query.filter(User.id != current_user.id).filter(
        User.threads.any(Thread.id == thread.id)).all()

    for message in thread.messages:
        if not message.get_read_time(current_user):
            message.set_read_time(current_user, datetime.utcnow())

    if form.validate_on_submit():
        thread.last_updated = datetime.utcnow()
        for recipient in recipients:
            msg = Message(sender=current_user,
                          thread=thread,
                          body=form.message.data)
            db.session.add(msg)
            msg.add_recipient(recipient)
            recipient.add_notification('unread_message_count',
                                       recipient.new_messages_count())
            db.session.commit()
        flash('Your message has been sent.')
        return redirect(url_for('messages.view_message', thread_id=thread.id))
    return render_template('messages/view_message.html',
                           thread=thread,
                           recipients=recipients,
                           form=form)
def send_message(recipient):
    user = User.query.filter_by(
        username=recipient).first_or_404()  # pragma: no cover
    form = MessageForm()  # pragma: no cover
    if form.validate_on_submit():  # pragma: no cover
        msg = Message(author=current_user,
                      recipient=user,
                      body=form.message.data)
        db.session.add(msg)
        db.session.commit()
        flash('Your message has been sent.')
        return redirect(
            url_for('tutor.tutor_details', id_number=user.tutor.id_number))
    return render_template('messages/send_message.html',
                           title='Send Message',
                           form=form,
                           recipient=recipient)  # pragma: no cover
Exemple #11
0
def edit_message(id):
    message = Message.query.get(id)
    form = MessageForm()
    if request.method == 'GET':
        form = MessageForm(obj=message)
    if form.validate_on_submit():
        form.populate_obj(message)
        db.session.commit()
        if message.message_type == 1:
            return redirect(
                url_for('messages.view_messages',
                        message_type=1,
                        id=current_user.id))
        return redirect(
            url_for('messages.view_messages',
                    message_type=0,
                    id=message.created_by))

    return render_template('edit_message.html', form=form)
Exemple #12
0
def submit():
    categories = Category.query.all()
    form = MessageForm()
    form.category_id.choices = [(c.id, c.name) for c in categories]

    if form.validate_on_submit():

        msg = Message(subject='Enquiry',
                      sender='*****@*****.**',
                      recipients=['*****@*****.**'],
                      html=render_template('intro/_contact_form.html',
                                           form=form))

        mail.send(msg)
        flash('message sent', 'success')

    return render_template('intro/index.html',
                           form=form,
                           msg=msg,
                           title="message item")
Exemple #13
0
def reply(msg_id, recipient_id):
    recipient = db.session.query(User).filter_by(
        id=recipient_id).first_or_404()
    message = db.session.query(Message).filter_by(id=msg_id).first()
    form = MessageForm()
    if form.validate_on_submit():
        msg = Message(author=current_user,
                      recipient=recipient,
                      body=form.message.data,
                      reply_id=msg_id)
        db.session.add(msg)
        recipient.add_notification('new_message', current_user.username)
        db.session.commit()
        flash(_('Your reply has been sent.'))
        return redirect(url_for('main.user', username=current_user.username))
    return render_template('messages/send_message.html',
                           title=_('Send Message'),
                           form=form,
                           recipient=recipient.username,
                           message=message)
Exemple #14
0
def create_message(message_type):
    print(f'Received value {message_type}')
    form = MessageForm()
    if form.validate_on_submit():
        message = Message()
        form.populate_obj(message)
        message.created_by = current_user.id
        message.message_type = message_type
        message.created_at = datetime.datetime.utcnow()
        db.session.add(message)
        db.session.commit()
        message_id = message.id
        if form.is_urgent.data:
            send_broadcast_messages(message_id)
        return redirect(
            url_for('messages.view_messages',
                    message_type=message_type,
                    id=current_user.id))
    return render_template('create_message.html',
                           message_type=message_type,
                           form=form)