Пример #1
0
def relate_task(task_id, type, type_id):
    task = Task.query.get(task_id)
    if type == 'contact':
        contact = Contact.query.get(type_id)
        task._contacts.append(contact)
        flash(gettext('{} related to task'.format(contact.email)))
    elif type == 'user':
        user = get_user(type_id)
        task.assigned.append(user)
        flash(gettext('{} related to task'.format(user.email)))
    return 'success'
Пример #2
0
def relate_task_remove(task_id, type, type_id):
    task = Task.query.get(task_id)
    if type == 'contact':
        contact = Contact.query.get(type_id)
        task._contacts.remove(contact)
        flash(gettext('{} removed from task'.format(contact.email)))
    elif type == 'user':
        user = get_user(type_id)
        task.assigned.remove(user)
        flash(gettext('{} removed from task'.format(user.email)))
    db.session.commit()
    return 'success'
Пример #3
0
def start_conversation(offer_id):
    form = FormMessage(request.form)
    if form.validate():
        offer = get_offer(offer_id)
        seller = get_user(offer.author_id)
        data = FormNewConversation(
            subject=offer.summary,
            message=form.message.data,
            recipient=seller.id,
            offer=offer_id
        )
        conversation_id = create_conversation(data)
        return redirect('/account/messages/conversation/{}'.format(conversation_id))
    else:
        if form.errors:
            flash(form.errors)
Пример #4
0
def view_public(offer_id):
    form_message = FormMessage()
    offer = get_offer(offer_id)
    seller = get_user(offer.author_id)
    if 'new_message' in request.args:
        new_message = True
    else:
        new_message = False
    return render_template('offers/public/view.html',
                           form_message=form_message,
                           offer=offer,
                           seller=seller,
                           rec_category=rec_category,
                           rec_condition=rec_condition,
                           rec_unit=rec_unit,
                           rec_pricing_terms=rec_pricing_terms,
                           rec_payment=rec_payment,
                           countries=countries,
                           new_message=new_message)
Пример #5
0
def create_conversation(data):
    # create conversation
    new_conversation = Conversation(
        subject=data.subject,
        _offer_id=data.offer,
        author_id=current_user.id
    )
    db.session.add(new_conversation)
    new_message = Message(
        message=data.message,
        author_id=current_user.id
    )
    db.session.add(new_message)
    db.session.flush()
    conversation = Conversation.query.get(new_conversation.id)
    message = Message.query.get(new_message.id)
    user = get_user(data.recipient)
    conversation._recipients.append(user)
    conversation._messages.append(message)
    db.session.commit()
    return new_conversation.id