示例#1
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']
        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_volunteer(request, application_id):
    if not request.user.is_authenticated():
        return HttpResponse(status=401)

    user = get_request_contributor(request)
    volunteer_relation = VolunteerRelation.objects.get(id=application_id)
    project = volunteer_relation.project

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

    # TODO: Condense common code between this and contact_project_volunteers
    if not user.email_verified or not is_co_owner_or_owner(user, project):
        return HttpResponse(status=403)

    email_subject = '{project}: {subject}'.format(project=project.project_name,
                                                  subject=subject)
    email_template = HtmlEmailTemplate(use_signature=False) \
        .paragraph('\"{message}\" - {firstname} {lastname}'.format(
        message=message,
        firstname=user.first_name,
        lastname=user.last_name)) \
        .paragraph('To reply, email at {email}'.format(email=user.email))
    send_to_project_volunteer(volunteer_relation, email_subject,
                              email_template)
    return HttpResponse(status=200)
def contact_project_volunteers(request, project_id):
    if not request.user.is_authenticated():
        return HttpResponse(status=401)

    user = get_request_contributor(request)

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

    project = Project.objects.get(id=project_id)
    if not user.email_verified or not is_co_owner_or_owner(user, project):
        return HttpResponse(status=403)

    volunteers = VolunteerRelation.get_by_project(project)

    email_subject = '{project}: {subject}'.format(project=project.project_name,
                                                  subject=subject)
    email_template = HtmlEmailTemplate(use_signature=False) \
        .paragraph('\"{message}\" - {firstname} {lastname}'.format(
        message=message,
        firstname=user.first_name,
        lastname=user.last_name)) \
        .paragraph('To reply, email at {email}'.format(email=user.email))
    for volunteer in volunteers:
        # TODO: See if we can send emails in a batch
        # https://docs.djangoproject.com/en/2.2/topics/email/#topics-sending-multiple-emails
        send_to_project_volunteer(volunteer, email_subject, email_template)
    return HttpResponse(status=200)
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)
示例#5
0
def get_first_email_template():
    return HtmlEmailTemplate() \
        .header("You're making a difference at {{project_name}}") \
        .paragraph("We'd like to take this opportunity to thank you for your support since {{volunteer_start_date}}.  "
                   "Your engagement with {{project_name}} is extremely important to us and is much appreciated.") \
        .paragraph("That said, we know you’re busy and just wanted to take this time to remind you that your "
                   "volunteer commitment with {{project_name}} will expire on {{project_end_date}}.") \
        .paragraph("We hope that you’ll take this time to renew your volunteer commitment and remain a part of our community.") \
        .button(url=review_commitment_url, text='REVIEW COMMITMENT')
示例#6
0
def get_second_email_template():
    return HtmlEmailTemplate() \
        .header("You're essential to the success of {{project_name}}") \
        .paragraph("{{first_name}},") \
        .paragraph("We can't thank you enough for all the positive energy you're putting into our tech-for-good "
                   "community, we wouldn't be able to do this without your help!") \
        .paragraph("We think you're a socially-conscious individual with a big heart and recognize that you're "
                   "essential to the success of {{project_name}}.  We hope that you continue adding value to our "
                   "community by taking this time to renew your volunteer commitment at {{project_name}}.") \
        .button(url=review_commitment_url, text='RENEW TODAY')
def reject_project_volunteer(request, application_id):
    volunteer_relation = VolunteerRelation.objects.get(id=application_id)
    if volunteer_operation_is_authorized(request, volunteer_relation):
        body = json.loads(request.body)
        message = body['rejection_message']
        email_template = HtmlEmailTemplate()\
        .paragraph('The project owner of {project_name} has declined your application for the following reason:'.format(project_name=volunteer_relation.project.project_name))\
        .paragraph('\"{message}\"'.format(message=message))
        email_subject = 'Your application to join {project_name}'.format(
            project_name=volunteer_relation.project.project_name)
        send_to_project_volunteer(volunteer_relation=volunteer_relation,
                                  subject=email_subject,
                                  template=email_template)
        update_project_timestamp(request, volunteer_relation.project)
        volunteer_relation.delete()
        return HttpResponse(status=200)
    else:
        raise PermissionDenied()
def demote_project_volunteer(request, application_id):
    volunteer_relation = VolunteerRelation.objects.get(id=application_id)
    if volunteer_operation_is_authorized(request, volunteer_relation):
        volunteer_relation.is_co_owner = False
        volunteer_relation.save()
        update_project_timestamp(request, volunteer_relation.project)
        body = json.loads(request.body)
        message = body['demotion_message']
        email_template = HtmlEmailTemplate()\
        .paragraph('The owner of {project_name} has removed you as a co-owner of the project for the following reason:'.format(
            project_name=volunteer_relation.project.project_name))\
        .paragraph('\"{message}\"'.format(message=message))
        email_subject = 'You have been removed as a co-owner from {project_name}'.format(
            project_name=volunteer_relation.project.project_name)
        send_to_project_volunteer(volunteer_relation=volunteer_relation,
                                  subject=email_subject,
                                  template=email_template)
        return HttpResponse(status=200)
    else:
        raise PermissionDenied()