Пример #1
0
def add_note_application(application_id=None, user_id=None):
    if request.form.get('note', '') is '':
        flash('You can\'t add an empty note !', 'danger')
        if user_id:
            return redirect(url_for('.user_view', user_id=user_id))
        return redirect(url_for('.view_application', application_id=application_id))

    if user_id:
        user_notes = mongo.db.notes.find_one({'user_id': user_id})
        if user_notes is None:
            user_notes = {
                'user_id': user_id,
                'notes': []
            }
    else:
        application = mongo.db.applications.find_one({'_id': ObjectId(application_id)})
        if application is None:
            abort(404)

    note = {
        'by': session.get('current_user')['main_character'],
        'user_id': session.get('current_user')['user_id'],
        'note': request.form.get('note', 'Empty note'),
        'added_at': datetime.datetime.utcnow()
    }

    if user_id:
        user_notes['notes'].append(note)
        mongo.db.notes.save(user_notes)
        Activity.new(
            session.get('current_user'),
            Action.new_auth_note, save=True,
            link=url_for('.user_view', user_id=user_id),
            user_id=user_id)
    else:
        if 'notes' not in application:
            application['notes'] = [note]
        else:
            application['notes'].append(note)
        application['updated_at'] = datetime.datetime.utcnow()
        mongo.db.applications.save(application)
        Activity.new(
            session.get('current_user'),
            Action.new_note, save=True,
            link=url_for('.view_application', application_id=application_id),
            applicant=application['applicant']['character_name'])

    flash('Note added !', 'success')
    if user_id:
        return redirect(url_for('.user_view', user_id=user_id))
    return redirect(url_for('.view_application', application_id=application_id))
Пример #2
0
def accept_application(application_id):
    application = mongo.db.applications.find_one({'_id': ObjectId(application_id)})
    if application is None:
        abort(404)
    application['status'] = Status.Accepted.value
    application['decided_by'] = session.get('current_user')['main_character']
    application['updated_at'] = datetime.datetime.utcnow()
    Activity.new(
        session.get('current_user'),
        Action.accepted_app, save=True,
        applicant=application['applicant']['character_name'],
        link=url_for('.view_application', application_id=application_id)
    )
    mongo.db.applications.save(application)
    flash('Application accepted !', 'success')
    # TODO : Dispatch email
    return redirect(url_for('.view_application', application_id=application_id))