def logo_update(request, slug): """The purpose of this view is to update the info of the management page""" #verifies if the company exists if not returns a 404 page company =get_object_or_404(Company,slug=slug) logo_form = CompanyLogoForm(instance=company) #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('pictures.html',{'form':logo_form },context_instance=RequestContext(request)) else: logo_form = CompanyLogoForm(request.POST, request.FILES, instance=company) #if is POST Validates the form is well filled and save it redirecting to the company page if logo_form.is_valid(): logo_form.save() # To FIX return HttpResponseRedirect('/company/%s/edit/' % str(slug)) #if not well filled redirect to the original update page and display error else: return render_to_response('pictures.html', {'form': logo_form, 'form_errors': logo_form.errors}, context_instance=RequestContext(request))
def company_edit(request, slug, **kwargs): company = get_object_or_404(Company,slug=slug) #This variable keeps the percentage of completion of the profile. percentage_profile = percentage_completion(company.id) #obtain photos made against company models. # pictures = Picture.objects.filter(company_id=company.id) #If the user is a globaltech employee does not have to check for the company #All globaltech employees have access to modify all the Companies. if request.user : user_id = request.user.id try: contact = Contact.objects.get(user=user_id) if contact.latech_contact or request.user.is_staff or request.user.is_superuser == True: edit= True else: #verify the person does not have access try: #Does the user has permission to modify this claim? permissions = AccessCompanyProfile.objects.get(contact=request.user) if permissions.company.all().filter(name__icontains=company.name) : edit = True else: edit = False except AccessCompanyProfile.DoesNotExist: edit = False except Contact.DoesNotExist: edit =False else: edit = False management = Management.objects.filter(company= company) competitors = Competitors.objects.filter(company=company) certifications = Certification.objects.filter(company=company) customers = Customer.objects.filter(company=company) awards = Award.objects.filter(company=company) offices = Office.objects.filter(company=company) acquisitions = Acquisition.objects.filter(company=company) fundings = Funding.objects.filter(company=company) pictures = Picture.objects.filter(company=company) companylinks = CompanyLink.objects.filter(company=company) # From Company Extended Profile partnerships = Partnership.objects.filter(company=company) alliances = Alliance.objects.filter(company=company) associations = TechnicalAssociation.objects.filter(company=company) expertises = Expertise.objects.filter(company=company) verticals = Vertical.objects.filter(company=company) stories = SuccessStories.objects.filter(company=company) revenues = AnnualRevenue.objects.filter(company=company) milestones = Milestone.objects.filter(company=company) projects = Project.objects.filter(company=company) products = Product.objects.filter(company=company) #Recommendations recommendations = Recommendation.objects.filter(company=company) countries = Country.objects.all().order_by('id') industries = Category.objects.all().order_by('id') # Product Picture Form # product_reference = get_object_or_404(Product, id=request.GET["product_id"], company=company) company_logo_form = CompanyLogoForm(request.POST, request.FILES, instance=company) # image_reference = get_object_or_404(Product, id=id,company=company) # product_picture_form = ProductImgForm(request.POST, request.FILES) # for product in products: # product_picture_form = product_img_update(id=product.request.id, slug=company.slug, request=request) if request.method == 'POST': # if product_picture_form.is_valid(): # product_picture_form = Product(product_image=request.FILES) # product_picture_form.save() if company_logo_form.is_valid(): company_logo_form.save() office_list = [] count = 0 for i in offices: count += 1 if (count)%3==0: office_list.append({"object":i, "ul":True}) else: office_list.append({"object":i}) return render_to_response( "company_edit.html", {'company':company, 'companylinks':companylinks,'pictures':pictures, 'permission': edit, "percentage_profile": percentage_profile, 'management': management,'offices':office_list, 'competitors': competitors,"certifications":certifications, "customers":customers, "awards":awards,"acquisitions":acquisitions, "fundings":fundings, "pictures":pictures, #Offices 'offices':offices, # From Company Extended Profile "expertises":expertises, "verticals":verticals,"stories":stories,"revenues":revenues, "milestones":milestones, "projects":projects, "partnerships":partnerships, "alliances":alliances, "associations":associations,"products":products, # Recommendations "recommendations":recommendations, # Calling All objects from these models to update them in place "countries":countries,"industries":industries, #Picture Form # "product_picture_form":product_picture_form,#'product_reference':product_reference, "company_logo_form":company_logo_form, }, context_instance=RequestContext(request))