def form_valid(self, form): volunteer_id = self.kwargs['volunteer_id'] volunteer = get_volunteer_by_id(volunteer_id) organization_list = get_organizations_ordered_by_name() if 'resume_file' in self.request.FILES: my_file = form.cleaned_data['resume_file'] if validate_file(my_file): # delete an old uploaded resume if it exists has_file = has_resume_file(volunteer_id) if has_file: try: delete_volunteer_resume(volunteer_id) except: raise Http404 else: return render( self.request, 'volunteer/edit.html', { 'form': form, 'organization_list': organization_list, 'volunteer': volunteer, 'resume_invalid': True, }) volunteer_to_edit = form.save(commit=False) try: country_name = self.request.POST.get('country') country = Country.objects.get(name=country_name) except ObjectDoesNotExist: country = None volunteer_to_edit.country = country try: state_name = self.request.POST.get('state') state = Region.objects.get(name=state_name) except ObjectDoesNotExist: state = None volunteer_to_edit.state = state try: city_name = self.request.POST.get('city') city = City.objects.get(name=city_name) except ObjectDoesNotExist: city = None volunteer_to_edit.city = city organization_id = self.request.POST.get('organization_name') organization = get_organization_by_id(organization_id) if organization: volunteer_to_edit.organization = organization else: unlisted_org = self.request.POST.get('unlisted_organization') org = create_organization(unlisted_org) volunteer_to_edit.organization = org # update the volunteer volunteer_to_edit.save() return HttpResponseRedirect( reverse('volunteer:profile', args=(volunteer_id, )))
def delete_resume(request, volunteer_id): user = request.user if int(user.volunteer.id) == int(volunteer_id): if request.method == 'POST': try: delete_volunteer_resume(volunteer_id) return HttpResponseRedirect( reverse('volunteer:profile', args=(volunteer_id, ))) except: raise Http404 else: return HttpResponse(status=403)
def delete_resume(request, volunteer_id): user = request.user if int(user.volunteer.id) == int(volunteer_id): if request.method == 'POST': try: delete_volunteer_resume(volunteer_id) return HttpResponseRedirect( reverse('volunteer:profile', args=(volunteer_id, ))) except: raise Http404 else: return HttpResponse(status=403)
def test_delete_volunteer_resume(self): """ Tests delete_volunteer_resume(volunteer_id) """ self.v1.resume_file = "MyResume.pdf" self.v1.save() self.assertTrue(delete_volunteer_resume(self.v1.id)) self.assertFalse(delete_volunteer(1000))
def test_delete_volunteer_resume(self): """ Tests delete_volunteer_resume(volunteer_id) """ self.v1.resume_file="MyResume.pdf" self.v1.save() self.assertTrue(delete_volunteer_resume(self.v1.id)) self.assertFalse(delete_volunteer(100))
def form_valid(self, form): volunteer_id = self.kwargs['volunteer_id'] volunteer = get_volunteer_by_id(volunteer_id) organization_list = get_organizations_ordered_by_name() if 'resume_file' in self.request.FILES: my_file = form.cleaned_data['resume_file'] if validate_file(my_file): # delete an old uploaded resume if it exists has_file = has_resume_file(volunteer_id) if has_file: try: delete_volunteer_resume(volunteer_id) except: raise Http404 else: return render( self.request, 'volunteer/edit.html', { 'form': form, 'organization_list': organization_list, 'volunteer': volunteer, 'resume_invalid': True, }) volunteer_to_edit = form.save(commit=False) organization_id = self.request.POST.get('organization_name') organization = get_organization_by_id(organization_id) if organization: volunteer_to_edit.organization = organization else: unlisted_org = self.request.POST.get('unlisted_organization') org = create_organization(unlisted_org) volunteer_to_edit.organization = org # update the volunteer volunteer_to_edit.save() return HttpResponseRedirect( reverse('volunteer:profile', args=(volunteer_id, )))
def form_valid(self, form): volunteer_id = self.kwargs['volunteer_id'] volunteer = get_volunteer_by_id(volunteer_id) organization_list = get_organizations_ordered_by_name() if 'resume_file' in self.request.FILES: my_file = form.cleaned_data['resume_file'] if validate_file(my_file): # delete an old uploaded resume if it exists has_file = has_resume_file(volunteer_id) if has_file: try: delete_volunteer_resume(volunteer_id) except: raise Http404 else: return render( self.request, 'volunteer/edit.html', { 'form': form, 'organization_list': organization_list, 'volunteer': volunteer, 'resume_invalid': True, }) volunteer_to_edit = form.save(commit=False) organization_id = self.request.POST.get('organization_name') organization = get_organization_by_id(organization_id) if organization: volunteer_to_edit.organization = organization else: volunteer_to_edit.organization = None # update the volunteer volunteer_to_edit.save() return HttpResponseRedirect( reverse('volunteer:profile', args=(volunteer_id, )))
def test_delete_volunteer_resume(self): """ Tests delete_volunteer_resume(volunteer_id) """ u1 = User.objects.create_user('John') v1 = Volunteer( first_name="John", last_name="Doe", address="7 Alpine Street", city="Maplegrove", state="Wyoming", country="USA", phone_number="23454545", email="*****@*****.**", resume_file="MyResume.pdf", user=u1 ) v1.save() self.assertTrue(delete_volunteer_resume(v1.id)) self.assertFalse(delete_volunteer(100))