def leave_project(request, project_id):
    volunteer_relation = VolunteerRelation.objects.filter(
        project_id=project_id, volunteer_id=request.user.id).first()
    if request.user.id == volunteer_relation.volunteer.id:
        body = json.loads(request.body)
        message = body['departure_message']
        if len(message) > 0:
            email_template = HtmlEmailTemplate()\
            .paragraph('{volunteer_name} is leaving {project_name} for the following reason:'.format(
                volunteer_name=volunteer_relation.volunteer.full_name(),
                project_name=volunteer_relation.project.project_name))\
            .paragraph('\"{message}\"'.format(message=message))
        else:
            email_template = HtmlEmailTemplate() \
                .paragraph('{volunteer_name} is leaving {project_name} for unspecified reasons.'.format(
                volunteer_name=volunteer_relation.volunteer.full_name(),
                project_name=volunteer_relation.project.project_name))
        email_subject = '{volunteer_name} is leaving {project_name}'.format(
            volunteer_name=volunteer_relation.volunteer.full_name(),
            project_name=volunteer_relation.project.project_name)
        send_to_project_owners(project=volunteer_relation.project,
                               sender=volunteer_relation.volunteer,
                               subject=email_subject,
                               template=email_template)
        update_project_timestamp(request, volunteer_relation.project)
        volunteer_relation.delete()
        return HttpResponse(status=200)
    else:
        raise PermissionDenied()
def contact_project_owner(request, project_id):
    if not request.user.is_authenticated():
        return HttpResponse(status=401)

    user = get_request_contributor(request)
    if not user.email_verified:
        return HttpResponse(status=403)

    body = json.loads(request.body)
    message = body['message']

    project = Project.objects.get(id=project_id)
    email_subject = '{firstname} {lastname} would like to connect with {project}'.format(
        firstname=user.first_name,
        lastname=user.last_name,
        project=project.project_name)
    email_template = HtmlEmailTemplate(use_signature=False)\
        .paragraph('\"{message}\" - {firstname} {lastname}'.format(
            message=message,
            firstname=user.first_name,
            lastname=user.last_name))\
        .paragraph('To contact this person, email them at {email}'.format(email=user.email))
    send_to_project_owners(project=project,
                           sender=user,
                           subject=email_subject,
                           template=email_template)
    return HttpResponse(status=200)
示例#3
0
def contact_project_owner(request, project_id):
    if not request.user.is_authenticated():
        return HttpResponse(status=401)

    user = get_request_contributor(request)
    if not user.email_verified:
        return HttpResponse(status=403)

    body = json.loads(request.body)
    message = body['message']

    project = Project.objects.get(id=project_id)
    email_subject = '{firstname} {lastname} would like to connect with {project}'.format(
                    firstname=user.first_name,
                    lastname=user.last_name,
                    project=project.project_name)
    email_body = '{message} \n -- \n To contact this person, email {user}'.format(message=message, user=user.email)
    send_to_project_owners(project=project, sender=user, subject=email_subject, body=email_body)
    return HttpResponse(status=200)
示例#4
0
def leave_project(request, project_id):
    volunteer_relation = VolunteerRelation.objects.filter(project_id=project_id, volunteer_id=request.user.id).first()
    if request.user.id == volunteer_relation.volunteer.id:
        body = json.loads(request.body)
        message = body['departure_message']
        email_body = '{volunteer_name} is leaving {project_name} for the following reason:\n{message}'.format(
            volunteer_name=volunteer_relation.volunteer.full_name(),
            project_name=volunteer_relation.project.project_name,
            message=message)
        email_subject = '{volunteer_name} is leaving {project_name}'.format(
            volunteer_name=volunteer_relation.volunteer.full_name(),
            project_name=volunteer_relation.project.project_name)
        send_to_project_owners(project=volunteer_relation.project,
                               sender=volunteer_relation.volunteer,
                               subject=email_subject,
                               body=email_body)
        volunteer_relation.update_project_timestamp()
        volunteer_relation.delete()
        return HttpResponse(status=200)
    else:
        raise PermissionDenied()