def handle(self, *args, **options): if not settings.VOLUNTEER_RENEW_REMINDER_PERIODS: print( 'Please set VOLUNTEER_RENEW_REMINDER_PERIODS before running volunteer_renewal_reminders' ) return now = timezone.now() from civictechprojects.models import VolunteerRelation volunteer_applications = VolunteerRelation.objects.all() for volunteer_relation in volunteer_applications: if volunteer_relation.is_up_for_renewal(now): if now > volunteer_relation.projected_end_date: if volunteer_relation.is_approved: # Don't send conclusion emails if volunteer wasn't approved send_volunteer_conclude_email( volunteer_relation.volunteer, volunteer_relation.project.project_name) notify_project_owners_volunteer_concluded_email( volunteer_relation) volunteer_relation.delete() elif volunteer_relation.is_approved: # Don't send reminders if volunteer isn't approved email_template = get_reminder_template_if_time( now, volunteer_relation) if email_template: send_reminder_email(email_template, volunteer_relation) volunteer_relation.re_enroll_reminder_count += 1 volunteer_relation.re_enroll_last_reminder_date = now volunteer_relation.save()
def conclude_volunteering_with_project(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) if not user.id == volunteer_relation.volunteer.id: return HttpResponse(status=403) send_volunteer_conclude_email(user, volunteer_relation.project.project_name) body = json.loads(request.body) volunteer_relation.delete() notify_project_owners_volunteer_concluded_email(volunteer_relation, body['message']) return HttpResponse(status=200)