Пример #1
0
def edit(request, volunteer_id):
    volunteer = get_volunteer_by_id(volunteer_id)
    if volunteer:
        if request.method == 'POST':
            form = VolunteerForm(request.POST, request.FILES, instance=volunteer)
            if form.is_valid():
                #if a resume has been uploaded
                if 'resume_file' in request.FILES:
                    my_file = form.cleaned_data['resume_file']
                    if validate_file(my_file):
                        #delete an old uploaded resume if it exists
                        resume_file = get_volunteer_resume_file(volunteer_id)
                        if resume_file:
                            delete_volunteer_resume(volunteer_id)
                    else:
                        return render(request, 'volunteer/edit.html', {'form' : form, 'id' : volunteer_id,})
                #update the volunteer
                form.save()
                return HttpResponseRedirect(reverse('volunteer:list_volunteers'))
        else:
            #create a form to change an existing volunteer
            form = VolunteerForm(instance=volunteer)
        return render(request, 'volunteer/edit.html', {'form' : form, 'id' : volunteer_id,})
    else:
        return HttpResponseRedirect(reverse('volunteer:error'))
Пример #2
0
def register_volunteer(request):

    registered = False
    organization_list = get_organizations_by_name()

    if organization_list:

        if request.method == 'POST':

            #each form must have it's own namespace (prefix) if multiple forms are to be put inside one <form> tag
            user_form = UserForm(request.POST, prefix="usr")
            volunteer_form = VolunteerForm(request.POST, request.FILES, prefix="vol")

            if user_form.is_valid() and volunteer_form.is_valid():

                if 'resume_file' in request.FILES:
                    my_file = volunteer_form.cleaned_data['resume_file']
                    if not validate_file(my_file):
                        return render(
                            request,
                            'auth/register.html',
                            {'user_form' : user_form, 'volunteer_form' : volunteer_form, 'registered' : registered, 'organization_list' : organization_list,}
                        )

                user = user_form.save();

                user.set_password(user.password)
                user.save()
           
                volunteer = volunteer_form.save(commit=False)
                volunteer.user = user

                #if an organization isn't chosen from the dropdown, then organization_id will be 0
                organization_id = request.POST.get('organization_name')
                organization = get_organization_by_id(organization_id)

                if organization:
                    volunteer.organization = organization

                volunteer.save()

                registered = True
            else:
                print user_form.errors, volunteer_form.errors
        else:
            user_form = UserForm(prefix="usr")
            volunteer_form = VolunteerForm(prefix="vol") 

        return render(
            request,
            'auth/register.html',
            {'user_form' : user_form, 'volunteer_form' : volunteer_form, 'registered' : registered, 'organization_list' : organization_list,}
        )

    else:
        return HttpResponseRedirect(reverse('organization:error'))
Пример #3
0
def create(request):
    if request.method == 'POST':
        form = VolunteerForm(request.POST, request.FILES)
        if form.is_valid():
            my_file = form.cleaned_data['resume_file']
            if validate_file(my_file):
                #save the volunteer
                form.save()
                return HttpResponseRedirect(reverse('volunteer:list_volunteers'))
    else:
        form = VolunteerForm()
    return render(request, 'volunteer/create.html', {'form' : form,})        
Пример #4
0
Файл: views.py Проект: Ads7/vms
def edit(request, volunteer_id):

    volunteer = get_volunteer_by_id(volunteer_id)
    if volunteer:
        user = request.user
        if int(user.volunteer.id) == int(volunteer_id):
            organization_list = get_organizations_ordered_by_name()
            if request.method == 'POST':
                form = VolunteerForm(request.POST, request.FILES, instance=volunteer)
                if form.is_valid():
                    #if a resume has been uploaded
                    if 'resume_file' in 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(request, 'volunteer/edit.html', {'form' : form, 'organization_list' : organization_list, 'volunteer' : volunteer, 'resume_invalid' : True,})
                    
                    volunteer_to_edit = form.save(commit=False)

                    organization_id = 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,)))
                else:
                    print form.errors
                    return render(request, 'volunteer/edit.html', {'form' : form, 'organization_list' : organization_list, 'volunteer' : volunteer,})
            else:
                #create a form to change an existing volunteer
                form = VolunteerForm(instance=volunteer)
                return render(request, 'volunteer/edit.html', {'form' : form, 'organization_list' : organization_list, 'volunteer' : volunteer,})
        else:
            return HttpResponse(status=403)
    else:
        raise Http404
Пример #5
0
 def get(self, request):
     user_form = UserForm(prefix="usr")
     volunteer_form = VolunteerForm(prefix="vol")
     return render(
         request, 'registration/signup_volunteer.html', {
             'user_form': user_form,
             'volunteer_form': volunteer_form,
             'registered': self.registered,
             'phone_error': self.phone_error,
             'organization_list': self.organization_list,
         })
Пример #6
0
def edit(request, volunteer_id):

    volunteer = get_volunteer_by_id(volunteer_id)
    if volunteer:
        organization_list = get_organizations_by_name()
        if request.method == 'POST':
            form = VolunteerForm(request.POST, request.FILES, instance=volunteer)
            if form.is_valid():
                #if a resume has been uploaded
                if 'resume_file' in 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:
                            if not delete_volunteer_resume(volunteer_id):
                                return HttpResponseRedirect(reverse('volunteer:error'))
                    else:
                        return render(request, 'volunteer/edit.html', {'form' : form, 'organization_list' : organization_list, 'volunteer' : volunteer,})
                
                volunteer_to_edit = form.save(commit=False)

                organization_id = 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:list'))
            else:
                return render(request, 'volunteer/edit.html', {'form' : form, 'organization_list' : organization_list, 'volunteer' : volunteer,})
        else:
            #create a form to change an existing volunteer
            form = VolunteerForm(instance=volunteer)
            return render(request, 'volunteer/edit.html', {'form' : form, 'organization_list' : organization_list, 'volunteer' : volunteer,})
    else:
        return HttpResponseRedirect(reverse('volunteer:error'))
Пример #7
0
 def get(self, request):
     organization_list = get_organizations_ordered_by_name()
     user_form = UserForm(prefix="usr")
     volunteer_form = VolunteerForm(prefix="vol")
     return render(
         request, 'registration/signup_volunteer.html', {
             'user_form': user_form,
             'volunteer_form': volunteer_form,
             'registered': self.registered,
             'phone_error': self.phone_error,
             'match_error': self.match_error,
             'organization_list': organization_list,
             'country_list': self.country_list,
         })
Пример #8
0
def signup_volunteer(request):

    registered = False
    organization_list = get_organizations_ordered_by_name()

    if organization_list:
        if request.method == "POST":
            # each form must have its own namespace (prefix) if multiple forms
            # are to be put inside one <form> tag
            user_form = UserForm(request.POST, prefix="usr")
            volunteer_form = VolunteerForm(request.POST, request.FILES, prefix="vol")

            if user_form.is_valid() and volunteer_form.is_valid():

                if "resume_file" in request.FILES:
                    my_file = volunteer_form.cleaned_data["resume_file"]
                    if not validate_file(my_file):
                        return render(
                            request,
                            "registration/signup_volunteer.html",
                            {
                                "user_form": user_form,
                                "volunteer_form": volunteer_form,
                                "registered": registered,
                                "organization_list": organization_list,
                            },
                        )

                user = user_form.save()

                user.set_password(user.password)
                user.save()

                volunteer = volunteer_form.save(commit=False)
                volunteer.user = user

                # if an organization isn't chosen from the dropdown,
                # then organization_id will be 0
                organization_id = request.POST.get("organization_name")
                organization = get_organization_by_id(organization_id)

                if organization:
                    volunteer.organization = organization

                volunteer.reminder_days = 1
                volunteer.save()
                registered = True

                messages.success(request, "You have successfully registered!")
                return HttpResponseRedirect(reverse("home:index"))
            else:
                print(user_form.errors, volunteer_form.errors)
                return render(
                    request,
                    "registration/signup_volunteer.html",
                    {
                        "user_form": user_form,
                        "volunteer_form": volunteer_form,
                        "registered": registered,
                        "organization_list": organization_list,
                    },
                )
        else:
            user_form = UserForm(prefix="usr")
            volunteer_form = VolunteerForm(prefix="vol")

        return render(
            request,
            "registration/signup_volunteer.html",
            {
                "user_form": user_form,
                "volunteer_form": volunteer_form,
                "registered": registered,
                "organization_list": organization_list,
            },
        )

    else:
        return render(request, "organization/add_organizations.html")
Пример #9
0
def signup_volunteer(request):

    registered = False
    organization_list = get_organizations_ordered_by_name()

    if organization_list:
        if request.method == 'POST':
            #each form must have it's own namespace (prefix) if multiple forms are to be put inside one <form> tag
            user_form = UserForm(request.POST, prefix="usr")
            volunteer_form = VolunteerForm(request.POST,
                                           request.FILES,
                                           prefix="vol")

            if user_form.is_valid() and volunteer_form.is_valid():

                if 'resume_file' in request.FILES:
                    my_file = volunteer_form.cleaned_data['resume_file']
                    if not validate_file(my_file):
                        return render(
                            request, 'registration/signup_volunteer.html', {
                                'user_form': user_form,
                                'volunteer_form': volunteer_form,
                                'registered': registered,
                                'organization_list': organization_list,
                            })

                user = user_form.save()

                user.set_password(user.password)
                user.save()

                volunteer = volunteer_form.save(commit=False)
                volunteer.user = user

                #if an organization isn't chosen from the dropdown, then organization_id will be 0
                organization_id = request.POST.get('organization_name')
                organization = get_organization_by_id(organization_id)

                if organization:
                    volunteer.organization = organization

                volunteer.save()
                registered = True

                return HttpResponseRedirect(reverse('home:index'))
            else:
                print user_form.errors, volunteer_form.errors
                return render(
                    request, 'registration/signup_volunteer.html', {
                        'user_form': user_form,
                        'volunteer_form': volunteer_form,
                        'registered': registered,
                        'organization_list': organization_list,
                    })
        else:
            user_form = UserForm(prefix="usr")
            volunteer_form = VolunteerForm(prefix="vol")

        return render(
            request, 'registration/signup_volunteer.html', {
                'user_form': user_form,
                'volunteer_form': volunteer_form,
                'registered': registered,
                'organization_list': organization_list,
            })

    else:
        return render(request, 'organization/add_organizations.html')
Пример #10
0
    def post(self, request):
        organization_list = get_organizations_ordered_by_name()
        if organization_list:
            if request.method == 'POST':
                user_form = UserForm(request.POST, prefix="usr")
                volunteer_form = VolunteerForm(
                    request.POST, request.FILES, prefix="vol")

                if user_form.is_valid() and volunteer_form.is_valid():
                    password1 = request.POST.get('usr-password')
                    password2 = request.POST.get('usr-confirm_password')
                    if not match_password(password1, password2):
                        self.match_error = True
                        return render(
                            request, 'registration/signup_volunteer.html', {
                                'user_form': user_form,
                                'volunteer_form': volunteer_form,
                                'registered': self.registered,
                                'phone_error': self.phone_error,
                                'match_error': self.match_error,
                                'organization_list': self.organization_list,
                            })

                    vol_country = request.POST.get('vol-country')
                    vol_phone = request.POST.get('vol-phone_number')
                    if (vol_country and vol_phone):
                        if not validate_phone(vol_country, vol_phone):
                            self.phone_error = True
                            return render(
                                request, 'registration/signup_volunteer.html',
                                {
                                    'user_form': user_form,
                                    'volunteer_form': volunteer_form,
                                    'registered': self.registered,
                                    'phone_error': self.phone_error,
                                    'organization_list':
                                    self.organization_list,
                                })

                    if 'resume_file' in request.FILES:
                        my_file = volunteer_form.cleaned_data['resume_file']
                        if not validate_file(my_file):
                            return render(
                                request, 'registration/signup_volunteer.html',
                                {
                                    'user_form': user_form,
                                    'volunteer_form': volunteer_form,
                                    'registered': self.registered,
                                    'phone_error': self.phone_error,
                                    'organization_list':
                                    self.organization_list,
                                })

                    user = user_form.save()

                    user.set_password(user.password)
                    user.save()

                    volunteer = volunteer_form.save(commit=False)
                    volunteer.user = user

                    # if an organization isn't chosen from the dropdown,
                    # then organization_id will be 0
                    organization_id = request.POST.get('organization_name')
                    organization = get_organization_by_id(organization_id)

                    if organization:
                        volunteer.organization = organization
                    else:
                        unlisted_org = request.POST.get('vol-unlisted_organization')
                        org = Organization.objects.create(name=unlisted_org, approved_status=False)
                        org.save()
                        volunteer.organization = org

                    volunteer.reminder_days = 1
                    volunteer.save()
                    current_site = get_current_site(request)
                    mail_subject = 'Activate your account.'
                    message = render_to_string(
                        'registration/acc_active_email.html', {
                            'user': user,
                            'domain': current_site.domain,
                            'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                            'token': account_activation_token.make_token(user),
                        })
                    to_email = volunteer_form.cleaned_data.get('email')
                    email = EmailMessage(mail_subject, message, to=[to_email])
                    email.send()
                    return render(request, 'home/email_ask_confirm.html')
                else:
                    return render(
                        request, 'registration/signup_volunteer.html', {
                            'user_form': user_form,
                            'volunteer_form': volunteer_form,
                            'registered': self.registered,
                            'phone_error': self.phone_error,
                            'organization_list': self.organization_list,
                        })
        else:
            return render(request, 'home/home.html', {'error': True})
Пример #11
0
    def post(self, request):
        organization_list = get_organizations_ordered_by_name()
        if organization_list:
            if request.method == 'POST':
                user_form = UserForm(request.POST, prefix="usr")
                volunteer_form = VolunteerForm(request.POST,
                                               request.FILES,
                                               prefix="vol")

                if user_form.is_valid() and volunteer_form.is_valid():
                    password1 = request.POST.get('usr-password')
                    password2 = request.POST.get('usr-confirm_password')
                    if not match_password(password1, password2):
                        self.match_error = True
                        return render(
                            request, 'registration/signup_volunteer.html', {
                                'user_form': user_form,
                                'volunteer_form': volunteer_form,
                                'registered': self.registered,
                                'phone_error': self.phone_error,
                                'match_error': self.match_error,
                                'organization_list': self.organization_list,
                            })

                    vol_country = request.POST.get('vol-country')
                    vol_phone = request.POST.get('vol-phone_number')
                    if (vol_country and vol_phone):
                        if not validate_phone(vol_country, vol_phone):
                            self.phone_error = True
                            return render(
                                request, 'registration/signup_volunteer.html',
                                {
                                    'user_form': user_form,
                                    'volunteer_form': volunteer_form,
                                    'registered': self.registered,
                                    'phone_error': self.phone_error,
                                    'organization_list':
                                    self.organization_list,
                                })

                    if 'resume_file' in request.FILES:
                        my_file = volunteer_form.cleaned_data['resume_file']
                        if not validate_file(my_file):
                            return render(
                                request, 'registration/signup_volunteer.html',
                                {
                                    'user_form': user_form,
                                    'volunteer_form': volunteer_form,
                                    'registered': self.registered,
                                    'phone_error': self.phone_error,
                                    'organization_list':
                                    self.organization_list,
                                })

                    user = user_form.save()

                    user.set_password(user.password)
                    user.save()

                    volunteer = volunteer_form.save(commit=False)
                    volunteer.user = user

                    # if an organization isn't chosen from the dropdown,
                    # then organization_id will be 0
                    organization_id = request.POST.get('organization_name')
                    organization = get_organization_by_id(organization_id)

                    if organization:
                        volunteer.organization = organization
                    else:
                        unlisted_org = request.POST.get(
                            'vol-unlisted_organization')
                        org = Organization.objects.create(
                            name=unlisted_org, approved_status=False)
                        org.save()
                        volunteer.organization = org

                    volunteer.reminder_days = 1
                    volunteer.save()
                    current_site = get_current_site(request)
                    mail_subject = 'Activate your account.'
                    message = render_to_string(
                        'registration/acc_active_email.html', {
                            'user': user,
                            'domain': current_site.domain,
                            'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                            'token': account_activation_token.make_token(user),
                        })
                    to_email = volunteer_form.cleaned_data.get('email')
                    email = EmailMessage(mail_subject, message, to=[to_email])
                    email.send()
                    return render(request, 'home/email_ask_confirm.html')
                else:
                    return render(
                        request, 'registration/signup_volunteer.html', {
                            'user_form': user_form,
                            'volunteer_form': volunteer_form,
                            'registered': self.registered,
                            'phone_error': self.phone_error,
                            'organization_list': self.organization_list,
                        })
        else:
            return render(request, 'home/home.html', {'error': True})
Пример #12
0
def edit(request, volunteer_id):

    volunteer = get_volunteer_by_id(volunteer_id)
    if volunteer:
        user = request.user
        if int(user.volunteer.id) == int(volunteer_id):
            organization_list = get_organizations_ordered_by_name()
            if request.method == 'POST':
                form = VolunteerForm(request.POST,
                                     request.FILES,
                                     instance=volunteer)
                if form.is_valid():
                    #if a resume has been uploaded
                    if 'resume_file' in 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(
                                request, 'volunteer/edit.html', {
                                    'form': form,
                                    'organization_list': organization_list,
                                    'volunteer': volunteer,
                                    'resume_invalid': True,
                                })

                    volunteer_to_edit = form.save(commit=False)

                    organization_id = 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, )))
                else:
                    print form.errors
                    return render(
                        request, 'volunteer/edit.html', {
                            'form': form,
                            'organization_list': organization_list,
                            'volunteer': volunteer,
                        })
            else:
                #create a form to change an existing volunteer
                form = VolunteerForm(instance=volunteer)
                return render(
                    request, 'volunteer/edit.html', {
                        'form': form,
                        'organization_list': organization_list,
                        'volunteer': volunteer,
                    })
        else:
            return HttpResponse(status=403)
    else:
        raise Http404
Пример #13
0
    def post(self, request):
        organization_list = get_organizations_ordered_by_name()
        if organization_list:
            if request.method == 'POST':
                user_form = UserForm(request.POST, prefix="usr")
                volunteer_form = VolunteerForm(
                    request.POST, request.FILES, prefix="vol")

                if user_form.is_valid() and volunteer_form.is_valid():

                    vol_country = request.POST.get('vol-country')
                    vol_phone = request.POST.get('vol-phone_number')
                    if (vol_country and vol_phone):
                        if not validate_phone(vol_country, vol_phone):
                            self.phone_error = True
                            return render(
                                request, 'registration/signup_volunteer.html',
                                {
                                    'user_form': user_form,
                                    'volunteer_form': volunteer_form,
                                    'registered': self.registered,
                                    'phone_error': self.phone_error,
                                    'organization_list':
                                    self.organization_list,
                                })

                    if 'resume_file' in request.FILES:
                        my_file = volunteer_form.cleaned_data['resume_file']
                        if not validate_file(my_file):
                            return render(
                                request, 'registration/signup_volunteer.html',
                                {
                                    'user_form': user_form,
                                    'volunteer_form': volunteer_form,
                                    'registered': self.registered,
                                    'phone_error': self.phone_error,
                                    'organization_list':
                                    self.organization_list,
                                })

                    user = user_form.save()

                    user.set_password(user.password)
                    user.save()

                    volunteer = volunteer_form.save(commit=False)
                    volunteer.user = user

                    # if an organization isn't chosen from the dropdown,
                    # then organization_id will be 0
                    organization_id = request.POST.get('organization_name')
                    organization = get_organization_by_id(organization_id)

                    if organization:
                        volunteer.organization = organization

                    volunteer.reminder_days = 1
                    volunteer.save()
                    registered = True

                    messages.success(request,
                                     'You have successfully registered!')
                    return HttpResponseRedirect(reverse('home:index'))
                else:
                    print(user_form.errors, volunteer_form.errors)
                    return render(
                        request, 'registration/signup_volunteer.html', {
                            'user_form': user_form,
                            'volunteer_form': volunteer_form,
                            'registered': self.registered,
                            'phone_error': self.phone_error,
                            'organization_list': self.organization_list,
                        })
        else:
            return render(request, 'home/home.html', {'error': True})