Beispiel #1
0
def add_project(request,category_name_slug):
	try:
		cat = Category.objects.get(slug=category_name_slug)
	except Category.DoesNotExist:
		cat = None
	user = request.user.groups.filter(name='company').exists()
	if request.method=='POST':
		form = ProjectForm(request.POST, request.FILES)
		
		if  form.is_valid():
			if cat:  
				project = form.save(commit=False,)
				project.company=request.user.companyprofile.company_name
				project.category = cat
				project.save()

				request.user.companyprofile.project=project
				return category(request, category_name_slug)
			else:
				print form.errors

	else:
		form = ProjectForm()

	context_dict={'form':form, 'category':cat,'category_name': cat.name, 'slug':category_name_slug, 'user':user}

	return render(request, 'projects/add_project_view.html', context_dict)
Beispiel #2
0
def add_project(request, category_name_slug):
    try:
        cat = Category.objects.get(slug=category_name_slug)
    except Category.DoesNotExist:
        cat = None

    if request.method == "POST":
        form = ProjectForm(request.POST, request.FILES)

        if form.is_valid():
            if cat:
                project = form.save(commit=False)
                project.companyprofile = CompanyProfile.objects.get(
                    company_name=request.user.companyprofile.company_name
                )
                project.category = cat

                project.save()

                return category(request, category_name_slug)
            else:
                print form.errors

    else:
        form = ProjectForm()

    context_dict = {"form": form, "category": cat, "category_name": cat.name, "slug": category_name_slug}

    return render(request, "projects/add_project_view.html", context_dict)
Beispiel #3
0
def edit(request, category_name_slug,project_name_slug):
	try:
		cat = Category.objects.get(slug=category_name_slug)
	except Category.DoesNotExist:
		cat = None

	try:
		project = Project.objects.get(slug=project_name_slug)
	except Project.DoesNotExist:
		pass
		
	if request.method=='POST':
		form = ProjectForm(request.POST, request.FILES,instance=project)
		
		if  form.is_valid():
			if cat:  
				project = form.save(commit=False,)
				project.companyprofile=CompanyProfile.objects.get(company_name=request.user.companyprofile.company_name)
				project.category = cat
				
				project.save()

				return category(request, category_name_slug)
			else:
				print form.errors

	else:
		form = ProjectForm()

	context_dict={'form':form, 'category':cat,'category_name': cat.name, 'slug':category_name_slug}
	

	return render(request, 'projects/edit.html',context_dict)