Example #1
0
def picture_update(request, slug, id):
    """The purpose of this view is to update the info of the customer page"""
    #verifies if the company exists if not returns a 404 page
    company =get_object_or_404(Company,slug=slug)
    picture_reference = get_object_or_404(Picture, id=id,company=company)
    picture_form = PictureForm(instance=picture_reference)

    #verifies the person has access to the company or is an incubator employee
    edit = validate_user_company_access_or_redirect(request,company)

    #if the request is GET presents info, 
    if request.method == 'GET':
        return render_to_response('picture_form.html',{'form':picture_form, 'info': picture_reference},context_instance=RequestContext(request))
    else:
        picture_form = PictureForm(request.POST, instance=picture_reference)
        #if is POST Validates the form is well filled and save it redirecting to the company page 
        if picture_form.is_valid():
            picture_form.save(commit = False)

            return HttpResponseRedirect('/company/'+str(slug))
        #if not well filled redirect to the original update page and display error
        else:
            return render_to_response('picture_form.html', 
                {'form': picture_form, 'form_errors': picture_form.errors, 'info': picture_reference},
                context_instance=RequestContext(request))
Example #2
0
def picture_create(request, slug):
    """The purpose of this function is to create  new customers item associated with a created company"""
    #verifies if the company exists if not returns a 404 page
    company =get_object_or_404(Company,slug=slug)
    edit = validate_user_company_access_or_redirect(request,company)
    #if the request is GET presents empty form
    if request.method == 'GET':

        picture_form = PictureForm()
        return render_to_response('picture_form.html', {'form': picture_form, 'company':company},
            context_instance=RequestContext(request))
     
    else:
        picture_form = PictureForm(request.POST, request.FILES)
        #if is POST Validates the form is well filled and save it redirecting to the company page
        if picture_form.is_valid():
            pf = picture_form.save(commit=False)
            pf.company = company
            pf.save()
            return HttpResponseRedirect('/company/'+str(slug))

        #if not well filled redirect to the original create and display error
        else:
            return render_to_response('picture_form.html', 
                {'form': picture_form, 'form_errors': picture_form.errors, 'company':company},
                context_instance=RequestContext(request))