Beispiel #1
0
def get_need(need_id):
    need = Need.get(need_id)
    if not need:
        return api_error('Need not found')
    if current_user.id != need.alert.user_id:
        return api_error('Permission denied')
    return jsonify(need.to_advocate_json())
Beispiel #2
0
def mark_need_resolved(need_id):
    """
    Resolve a need and close an alert if necessary.
    Send out a message stating the alert was closed as well.
    """
    need = Need.get(need_id)

    # Check validity of need_id
    if not need:
        return api_error('Need not found')
    if not current_user.is_admin and current_user.id != need.alert.user_id:
        return api_error('Permission denied')
    if need.resolved:
        return api_error('Need already resolved!')

    # validate the form
    form = ResolveNeedForm(need=need)
    if not form.validate_on_submit():
        return api_error(form.errors)

    # Update Need with form data, including setting resolved to True.
    need.resolved = True
    need.resolved_at = datetime.utcnow()
    need.resolve_notes = form.notes.data
    need.resolve_message = form.message.data
    for provision in need.provisions:
        provision.selected = provision.id in form.provisions.data
    need.save()

    # Check if alert is resolved, notify those involved
    resolve_need(need)

    return '', 200
Beispiel #3
0
def get_need(need_id):
    need = Need.get(need_id)
    if not need:
        return api_error('Need not found')
    if not current_user.is_admin and current_user.id != need.alert.user_id:
        return api_error('Permission denied')
    return jsonify(need.to_advocate_json())
Beispiel #4
0
def respond_to_alert(provider, needs_provided, alert):
    """
    Send a response from a provider to an advocate.
    """
    advocate = alert.user

    body = provider.email
    if provider.phone_number:
        body += ", %s" % provider.phone_number

    response = Response(user=provider, alert=alert)
    response.save()

    services_provided = []
    for provision in needs_provided:
        need = Need.get(provision["need_id"])
        need_provided = NeedProvided(need=need, response=response, message=provision["message"])
        need_provided.save()
        services_provided.append("%s: %s\n" % (need.service.name, provision["message"]))

    body += (" is availible for:\n\n%s") % ("\n".join(services_provided))

    queue_send_message.apply_async(
        kwargs=dict(email=advocate.email, number=advocate.phone_number, subject="15th Night Alert Response", body=body)
    )

    return response
Beispiel #5
0
def respond_to_alert(provider, needs_provided, alert):
    """
    Send a response from a provider to an advocate.
    """
    advocate = alert.user

    body = provider.email
    if provider.phone_number:
        body += ", %s" % provider.phone_number

    response = Response(user=provider, alert=alert)
    response.save()

    services_provided = []
    for provision in needs_provided:
        need = Need.get(provision['need_id'])
        need_provided = NeedProvided(need=need,
                                     response=response,
                                     message=provision['message'])
        need_provided.save()
        services_provided.append('%s: %s\n' %
                                 (need.service.name, provision['message']))

    body += (" is availible for:\n\n%s") % ("\n".join(services_provided))

    queue_send_message.apply_async(
        kwargs=dict(email=advocate.email,
                    number=advocate.phone_number,
                    subject='15th Night Alert Response',
                    body=body))

    return response
Beispiel #6
0
def resolve_need(need_id):
    need = Need.get(need_id)
    if not need:
        return api_error('Need not found')
    if current_user.id != need.alert.user_id:
        return api_error('Permission denied')
    if need.resolved:
        return api_error('Need already resolved!')
    form = ResolveNeedForm(need=need)
    if not form.validate_on_submit():
        return api_error(form.errors)
    need.resolved = True
    need.resolved_at = datetime.utcnow()
    need.resolve_notes = form.notes.data
    need.resolve_message = form.message.data
    for provision in need.provisions:
        provision.selected = provision.id in form.provisions.data
    send_out_resolution(need)
    need.save()
    return '', 200