예제 #1
0
def new_project(request):
    if request.method == 'POST':
        form = ProjectForm(request.POST)
        name = str(request.POST['title'])
        #list=(str(project_api.get_projects_for_user(request.user.id))).replace("<Project: ","").replace(', ','').replace('[','').replace("]",'').split('>')
        #list = project_api.get_projects_for_user(request.user.id).values_list('title',flat=True)
        #print list

        #if name in list:
        if project_api.duplicate_project(request.user,request.POST):
            form.if_dup(1)
        if form.is_valid() :
            project_api.create_project(request.user, request.POST)
            project = form.save(commit=False)
            # return redirect('/req/projects')
            # return empty string and do the redirect stuff in front-end
            return HttpResponse('')

    else:
        form = ProjectForm()

    context = {'projects': project_api.get_projects_for_user(request.user.id),
               'canOwnProject': request.user.has_perm(PERMISSION_OWN_PROJECT),
               'title': 'New Project',
               'form': form, 'action': '/req/newproject', 'button_desc': 'Create Project'}
    return render(request, 'ProjectSummary.html', context)
예제 #2
0
def project_view(request, project_id):
    """
    - return project corresponding to project_id
    - handle project modification form submition
    - raise 404 if project is not found or project doesn't belong to the current user
    """
    if request.user.is_superuser:
        project = get_object_or_404(Project, pk=project_id)
    else:
        project = get_object_or_404(Project, owner=request.user, pk=project_id)
    if request.method == "POST":
        form = ProjectForm(request.POST, instance=project)
        if form.is_valid():
            form.save()
    else:
        form = ProjectForm(instance=project)

    context = {
        'project':
        project,
        'new_application_form':
        NewApplicationForm({'project_id': project.id},
                           prefix='new_application'),
        'project_form':
        form
    }
    return render_response(request, 'project/project_view.html', context)
예제 #3
0
def create(request):
    if request.method == 'POST':

        form = ProjectForm(request.POST)

        if form.is_valid():

            title = form.cleaned_data['title']
            inv_type = form.cleaned_data['investigation_type']
            desc = form.cleaned_data['description']

            body = {
                "name": "idsvc.project",
                "value": {
                    "title": title,
                    "investigation_type": inv_type,
                    "description": desc,
                }
            }
            a = _client(request)
            try:
                response = a.meta.addMetadata(body=body)
            except Exception as e:
                logger.debug('no sir: %s' % e)

            return HttpResponseRedirect('/projects/')
    # else:
    context = {'form': ProjectForm()}

    return render(request, 'ids_projects/create.html', context)
예제 #4
0
파일: views.py 프로젝트: debrice/kaaloo
def project_detail_view(request,id):
    context = {'current':'projects'}
    user = request.user
    project = Project.objects.get_for_user(user=request.user, id=int(id))

    if request.POST:
        form = ProjectForm(instance=project, data=request.POST)
        if form.is_valid():
            form.save()
            context['project_saved'] = True
        context['form'] = form
    else:
        context['form'] = ProjectForm(instance=project)

    context['project'] = project
    context['spectators'] = project.spectators.all().select_related()
    context['owners'] = project.owners.all().select_related()
    context['collaborators'] = project.collaborators.all().select_related()
    context['new_spectators'] = User.objects.filter(profile__contacts__user=request.user).exclude(projects_as_spectator = project).select_related()
    context['new_collaborators'] = User.objects.filter(profile__contacts__user=request.user).exclude(projects_as_collaborator = project).select_related()
    context['is_creator'] = project.is_creator(request.user)
    context['is_admin'] = project.is_admin(request.user)
    context['new_owners'] = User.objects.filter(profile__contacts__user=request.user).exclude(owned_projects = project).select_related()
    context['new_task_form'] = NewTaskForm()
    context['goal_form'] = GoalForm()
    return render_response(request, 'project/project_detail_view.html', context)
예제 #5
0
def addProject(request):
    if request.session.has_key('logged_in'):
        if request.method == 'POST':
            form = ProjectForm(request.POST, request.FILES)
            if form.is_valid():
                cd = form.cleaned_data
                p = Project(name=cd['name'],
                            url=cd["url"],
                            brief=cd['brief'],
                            cleverbits=cd['cleverbits'],
                            desktop_screenshot=cd['desktop_screenshot'],
                            mobile_screenshot=cd['mobile_screenshot'],
                            description=cd['description'])
                p.save()
                success = True
                return render(request, 'new_project.html',
                              {'success': success})
        else:
            form = ProjectForm()
            return render(request, 'new_project.html', {'form': form})
    else:
        return render(request, 'login.html', {
            'user_login': '******',
            'destination': 'addProject'
        })
예제 #6
0
def create_project(request, rfpId):
    context = RequestContext(request)
    user = request.user
    progress_status = 30
    rfp = RfpCampaign.objects.get(pk=rfpId)
    print("RFP is: ")
    print(rfp)
    questions = rfp.get_project_questions()

    if request.method == "POST":
        print(request.POST)
        project = ProjectForm(request.POST, request.FILES, questions=questions)

        if project.is_valid():
            project = Project(**project.cleaned_data)
            project.rfp = rfp
            project.user = user
            project.save()

            if "Next" in request.POST:
                return HttpResponseRedirect(reverse("create_project_budget", args=[project.pk]))
            else:
                return HttpResponseRedirect(reverse("create_project_previous", args=[project.pk]))

    else:
        project = ProjectForm(questions=questions)

    return render_to_response(
        "rfp/create_project.html",
        {"form": project, "user": user, "progress_status": progress_status, "rfp": rfp},
        context,
    )
예제 #7
0
def update_project(request, pid):
    try:
        proj = Project.objects.get(pk=int(pid))
    except:
        return HttpResponseRedirect("/resume/project/")

    if request.method == 'GET':
        form = populate_default_form(proj)
        pics = Pics.objects.filter(project=proj.id)
        tech = Tech.objects.filter(project=proj.id)
        return render(
            request, "resume_view/update.html", {
                "form": form,
                "pics": pics,
                "tech": tech,
                "idslash": "{0}/".format(pid),
                "btntext": "Update"
            })
    elif request.method == 'POST':
        form = ProjectForm(request.POST)
        if form.is_valid():
            proj = copy_project_details(form, proj)
            proj.save()
            return HttpResponseRedirect("/resume/project/{0}/".format(proj.id))
        pics = Pics.objects.filter(project=proj.id)
        tech = Tech.objects.filter(project=proj.id)
        return render(
            request, "resume_view/update.html", {
                "form": form,
                "pics": pics,
                "tech": tech,
                "idslash": "{0}/".format(pid),
                "btntext": "Update"
            })
예제 #8
0
def manage_project(request):
    if request.method == "GET":
        form = ProjectForm()
        return render(
            request, "resume_view/update.html", {
                "form": form,
                "pics": None,
                "tech": None,
                "idslash": "",
                "btntext": "Save"
            })
    # no fall through
    if request.method == "POST":
        form = ProjectForm(request.POST)
        if form.is_valid():
            proj = copy_project_details(form, Project())
            proj.save()
            return HttpResponseRedirect("/resume/project/{0}/".format(proj.id))
        else:
            return render(
                request, "resume_view/update.html", {
                    "form": form,
                    "pics": None,
                    "tech": None,
                    "idslash": "",
                    "btntext": "Save"
                })
예제 #9
0
파일: views.py 프로젝트: tovmeod/anaf
def project_add_typed(request, project_id, response_format='html'):
    """Project add to preselected parent project"""

    parent_project = None
    if project_id:
        parent_project = get_object_or_404(Project, pk=project_id)
        if not request.user.profile.has_permission(parent_project, mode='x'):
            parent_project = None

    if request.POST:
        if 'cancel' not in request.POST:
            project = Project()
            form = ProjectForm(
                request.user.profile, project_id, request.POST, instance=project)
            if form.is_valid():
                project = form.save()
                project.set_user_from_request(request)
                return HttpResponseRedirect(reverse('projects_project_view', args=[project.id]))
        else:
            return HttpResponseRedirect(reverse('projects'))
    else:
        form = ProjectForm(request.user.profile, project_id)

    context = _get_default_context(request)
    context.update({'form': form, 'project': parent_project})

    return render_to_response('projects/project_add_typed', context,
                              context_instance=RequestContext(request), response_format=response_format)
예제 #10
0
def new_project(request):
    if request.method == 'POST':
        form = ProjectForm(request.POST)
        name = str(request.POST['title'])
        #list=(str(project_api.get_projects_for_user(request.user.id))).replace("<Project: ","").replace(', ','').replace('[','').replace("]",'').split('>')
        #list = project_api.get_projects_for_user(request.user.id).values_list('title',flat=True)
        #print list

        #if name in list:
        if project_api.duplicate_project(request.user, request.POST):
            form.if_dup(1)
        if form.is_valid():
            project_api.create_project(request.user, request.POST)
            project = form.save(commit=False)
            # return redirect('/req/projects')
            # return empty string and do the redirect stuff in front-end
            return HttpResponse('')

    else:
        form = ProjectForm()

    context = {
        'projects': project_api.get_projects_for_user(request.user.id),
        'canOwnProject': request.user.has_perm(PERMISSION_OWN_PROJECT),
        'title': 'New Project',
        'form': form,
        'action': '/req/newproject',
        'button_desc': 'Create Project'
    }
    return render(request, 'ProjectSummary.html', context)
예제 #11
0
파일: views.py 프로젝트: joinEF/people
def edit_project(request, project_id=None):
    # http://wiki.ddenis.com/index.php?title=Django,_add_and_edit_object_together_in_the_same_form

    if project_id:
        print "exists"
        project = get_object_or_404(Project, pk=project_id)
        if request.user not in project.users.all():
            return HttpResponseForbidden()
    else:
        print "doesn't exist"
        project = Project()

    if request.method == "POST":

        form = ProjectForm(request.POST, instance=project)

        if form.is_valid():

            form.save()

            return HttpResponseRedirect(project.get_absolute_url())

    else:

        form = ProjectForm(instance=project)

    if project_id:
        template_name = "edit_project.html"
    else:
        template_name = "new_project.html"

    return render(request, template_name, {"form": form, "project": project})
예제 #12
0
def edit_project(request, projectId):
    context = RequestContext(request)
    user = request.user
    project = Project.objects.get(pk=projectId)
    project_dict = model_to_dict(project)
    user_is_owner(user, project)
    redirect = get_redirect_url(request)

    if request.method == "POST":
        p = ProjectForm(request.POST, request.FILES, questions=project.rfp.get_project_questions())

        if p.is_valid():
            p_data = p.cleaned_data
            p_update = Project.objects.update_or_create(user=user, id=project.id, defaults=p_data)
            proj = p_update[0]
            proj_save = proj.save()

            return HttpResponseRedirect(redirect)

    else:
        p = ProjectForm(initial=project_dict, questions=project.rfp.get_project_questions())

    context_dict = {"project": project, "user": user, "form": p}

    return render_to_response("rfp/edit_project.html", context_dict, context)
예제 #13
0
def create(request):
    if request.method == 'POST':

        form = ProjectForm(request.POST)

        if form.is_valid():

            title = form.cleaned_data['title']
            inv_type = form.cleaned_data['investigation_type']
            desc = form.cleaned_data['description']

            body = {
                "name":"idsvc.project",
                "value": {
                    "title":title,
                    "investigation_type":inv_type,
                    "description":desc,
                }
            }
            a = _client(request)
            try:
                response = a.meta.addMetadata(body=body)
            except Exception as e:
                logger.debug('no sir: %s' % e)

            return HttpResponseRedirect('/projects/')
    # else:
    context = {
        'form': ProjectForm()
    }

    return render(request, 'ids_projects/create.html', context)
예제 #14
0
def create_project(request,rfpId):
    context = RequestContext(request)
    user = request.user
    progress_status = 30
    rfp = RfpCampaign.objects.get(pk = rfpId)
    print ('RFP is: ')
    print (rfp)
    questions = rfp.get_project_questions()

    if request.method == 'POST':
        print (request.POST)
        project = ProjectForm(request.POST,request.FILES,questions = questions)

        if project.is_valid():
            project = Project(**project.cleaned_data)
            project.rfp = rfp
            project.user = user
            project.save()

            if "Next" in request.POST:
                return HttpResponseRedirect(reverse('create_project_budget', args=[project.pk]))
            else:
                return HttpResponseRedirect(reverse('create_project_previous', args=[project.pk]))

    else:
        project = ProjectForm(questions = questions)

    return render_to_response('rfp/create_project.html',{'form' : project, 'user' : user, 'progress_status' : progress_status, 'rfp' : rfp}, context)
예제 #15
0
파일: views.py 프로젝트: shawnchin/bbotui
def project_edit(request, pid, template_name='project_new.html'):
    """
    Edit an existing project
    """
    namedup = None
    project = get_object_or_404(request.user.project_set, id=pid)
    if request.method == "POST":
        form = ProjectForm(request.POST, instance=project)
        if form.is_valid():
            try:
                form.save()
                url = reverse('bbotweb_project_show', kwargs={'pid':project.id})
                return HttpResponseRedirect(url)
            except IntegrityError:
                msg = _("You already have a %s with the same name (%s).")
                messages.error(request, msg % (_("project"), project.name)); 
                namedup = True
    else:
        form = ProjectForm(instance=project)
    
    return render_to_response(template_name, {
        'form' : form,
        'project' : project,
        'namedup' : namedup,
    }, context_instance=RequestContext(request))
예제 #16
0
파일: views.py 프로젝트: i-k-i/tolk
def create_project(request):
    user = request.user
    if request.POST:
        form = ProjectForm(request.POST, request.FILES)
        if form.is_valid():
            c = form.save(commit=False)
            c.author = user
            c.save()
            #            import pdb; pdb.set_trace()
            project = Project.objects.get(id=c.id)
            ## permissions
            if not project.public:
                group = '{}_pr_workers'.format(c.id)
                group = Group.objects.create(name=group)
                group.save()
            else:
                group = Group.objects.get(name='workers')
#            import pdb; pdb.set_trace()
            for i in worker_perms['project']:
                assign_perm(i, group, project)
            for i in prcreator_perms:
                assign_perm(i, user, project)
            user.groups.add(group)
            loger(auth.get_user(request), 'created project',c.name, project=project)
            return HttpResponseRedirect('/projector/all')
    else:
        form = ProjectForm()
     #   import pdb; pdb.set_trace()
        #form['deadline'] = '111'

    args = {}
    args['username'] = auth.get_user(request).username
    args.update(csrf(request))
    args['form'] = form
    return render_to_response('create_project.html',args)
예제 #17
0
def edit_project(request,projectId):
    context = RequestContext(request)
    user = request.user
    project = Project.objects.get( pk = projectId )
    project_dict = model_to_dict(project)
    user_is_owner(user,project)
    redirect = get_redirect_url(request)

    if request.method == 'POST':
        p = ProjectForm(request.POST,request.FILES,questions = project.rfp.get_project_questions())

        if p.is_valid():
           p_data = p.cleaned_data
           p_update = Project.objects.update_or_create(user = user, id = project.id, defaults = p_data)
           proj = p_update[0]
           proj_save = proj.save()

           return HttpResponseRedirect(redirect)

    else:
        p = ProjectForm(initial=project_dict, questions=project.rfp.get_project_questions())

    context_dict={'project' : project,'user' : user,'form' : p}

    return render_to_response('rfp/edit_project.html',context_dict,context)
예제 #18
0
파일: views.py 프로젝트: Bryukh/spygit
def pep_view(request, **view_args):
    if request.method == 'GET':
        form = ProjectForm(request.GET)

        if form.is_valid():
            run_pep8(form.cleaned_data['url'], form.path, form.name, form.rev)
            return HttpResponseRedirect('/%s/%s' % (form.name, form.rev))

    return __show_home(form)
예제 #19
0
파일: views.py 프로젝트: Lopic/urtest
def new_project(request):
    if request.method == 'POST':
        form = ProjectForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/projects/')
    else:
        form = ProjectForm()
    return render_to_response('new_project.html',{'form': form})
예제 #20
0
def create_project(request, template="create_project.html"):
    user = get_object_or_404(User, pk=request.user.pk)
    form = ProjectForm(request.POST or None, initial={"user": user})
    if request.method == "POST" and form.is_valid():
        new_project = form.save()
        print new_project
        return redirect("enterprise.projects")
    context = {"form": form, "title": _("Create Project"), "enterprise": request.session["company"]}
    return render(request, template, context)
예제 #21
0
def add(request):
    if request.method == "POST":
        form = ProjectForm(data=request.POST)
        if form.is_valid():
            form.save()
            return redirect("core:home")
    else:
        form = ProjectForm()
    return render_to_response("add.html", {"form": form}, context_instance=RequestContext(request))
예제 #22
0
파일: views.py 프로젝트: jpihl/plotato
def create_project(request):
    """ Create a new Project.

    """
    form = ProjectForm(request.POST or None)
    if form.is_valid():
        new_project = form.save()
        return redirect(details_project, project_id=new_project.key)
    return render_to_response('form.html', {'form': form},
                              context_instance=RequestContext(request))
예제 #23
0
파일: views.py 프로젝트: rap12/wdwebapp
def add_project(request):
	if request.method == 'GET':
		form = ProjectForm()
	elif request.method == 'POST':
		form = ProjectForm(request.POST)
		if form.is_valid():
			form.save()
	return render_to_response ('devcup/add_project.html', {
		'form': form,
	}, context_instance = RequestContext(request))
예제 #24
0
def  Projects_form(webdata,request):
    forms = ProjectForm(webdata)
    if forms.is_valid():
        try:
            if create_dir(webdata['project_url']):
                forms.save()
                return HttpResponseRedirect(reverse('confd:project_list'))
            else:
                return render(request, 'confd/apply_project.html', {'forms': forms, 'errmsg': '项目创建失败'})
        except:
            return render(request, 'confd/apply_project.html', {'forms': forms, 'errmsg': '项目创建失败'})
예제 #25
0
파일: views.py 프로젝트: jpihl/plotato
def create_project(request):
    """ Create a new Project.

    """
    form = ProjectForm(request.POST or None)
    if form.is_valid():
        new_project = form.save()
        return redirect(details_project, project_id=new_project.key)
    return render_to_response('form.html',
                              {'form': form},
                              context_instance=RequestContext(request))
예제 #26
0
def project_details(request):
    vars = {}
    vars['template'] = 'content/project-details.html'
    vars['previous'] = '/'
    vars['next']     = '/import-gui'
    vars['redirect'] = vars['next'] 
    vars['path'] = request.session.get('path',djos.project_path())
    #vars['debug']    = True
    form = ProjectForm(initial={'path': vars['path'], 
                                'language1': 'English',
                                'language2': 'English',
                                'language3': 'English'}
                       )
    
    # submitting
    if request.method == 'POST':
        prev_title = request.session.get('title', False)
        curr_title = request.POST.get('title')
        
        # this title already in db?
        try: # yes
            p = Project.objects.get(title=curr_title)
            form = ProjectForm(request.POST, instance=p) # load form (from db)
        except: #no
            post2 = request.POST.copy() # immutable so copy before changing
            post2['date_created']=datetime.datetime.now()
            form = ProjectForm(post2) # create form

        if form.is_valid():  
            form.save()
            request.session['title'] = form.cleaned_data['title']
            request.session['path'] = form.cleaned_data['path']
            request.session['fullpath'] = request.session.get('path','Error') + os.sep + request.session.get('title','Error')
            return HttpResponseRedirect(vars['redirect'])
    # displaying
    elif request.session.get('title', False): # old
        try:
            p = Project.objects.get(title=request.session['title'])
            form = ProjectForm(instance=p)
        except ObjectDoesNotExist:
            vars['errors'] = {'Missing title': 'I could not find this title for some reason! Please enter a different title.'}
            request.session.pop('title')
            request.session.pop('path')
            request.session.pop('fullpath')
        except MultipleObjectsReturned:
            vars['errors'] = {'Too many titles': 'There were too many projects with this name. That should not happen. Please enter a different title.'}
            request.session.pop('title')
            request.session.pop('path')
            request.session.pop('fullpath')
        except:
            vars['errors'] = {'oops': 'I received some unexpected, unknown error. You might want to report this.'}
    else: # new
        pass
    return render_to_response(vars['template'], {'form': form, 'vars': vars})
예제 #27
0
파일: views.py 프로젝트: djf604/viewer
def new_project(request):
    if request.method == 'POST':
        pform = ProjectForm(request.POST, instance=Project())
        if pform.is_valid():
            pform.save()
        return HttpResponseRedirect('/viewer/project/')
    else:
        pform = ProjectForm(instance=Project())
        context = {'project_form': pform}
        context.update(csrf(request))
        return render_to_response('viewer/project/new_project.html', context,
                                  context_instance=RequestContext(request))
예제 #28
0
def create_project(request):

    if request.method == 'POST':
        form=ProjectForm(request.POST)
        if form.is_valid():
            form.save()    
            return HttpResponseRedirect("/account/")
    else:
  
            form=ProjectForm()

    return  render(request, 'PyBugs/create_project.html', {'form': form,}) 
예제 #29
0
def new_project(request):
    if request.method == 'POST':
        pform = ProjectForm(request.POST, instance=Project())
        if pform.is_valid():
            pform.save()
        return HttpResponseRedirect(reverse('manage_project'))
    else:
        pform = ProjectForm(instance=Project())
        context = {'project_form': pform}
        context.update(csrf(request))
        return render_to_response('viewer/project/new_project.html', context,
                                  context_instance=RequestContext(request))
예제 #30
0
def add_project(request):
    if request.method == "POST":
        form = ProjectForm(request.POST, user=request.user)
        if form.is_valid():
            form.save(request)
            messages.success(request, 'Project created successfully.')
            return HttpResponseRedirect(reverse('my_projects'))
    else:
        form = ProjectForm()
    return render_to_response('authenticated/project/add_project.html',
                              locals(),
                              context_instance=RequestContext(request))
예제 #31
0
def add_project(request):
    if request.method == "POST":
        form = ProjectForm(request.POST, user=request.user)
        if form.is_valid():
            form.save(request)
            messages.success(request, "Project created successfully.")
            return HttpResponseRedirect(reverse("my_projects"))
    else:
        form = ProjectForm()
    return render_to_response(
        "authenticated/project/add_project.html", locals(), context_instance=RequestContext(request)
    )
예제 #32
0
def manage_projects(request):
    if 'pick' in request.GET:
        return _pick_project(request, request.GET['pick'])
    
    if request.method == 'POST':
        form = ProjectForm(request.POST)
        if form.is_valid():
            project = form.save()
            return _pick_project(request, project)
    else:
        form = ProjectForm()
    return {'projects': Project.objects.all(), 'form': form}
예제 #33
0
def save_project(request):
   if request.method == 'POST': 
      form = ProjectForm(request.POST) 
      if form.is_valid(): 
         newProject = Project.objects.get(pk=form.cleaned_data['id'])
         save_project_from_form(newProject, form)
         return HttpResponseRedirect('/sms/projects') 
   else:
       form = ProjectForm()

   return render_to_response('sms/edit_project.html',
                             {'form': form },
                             context_instance=RequestContext(request))
예제 #34
0
파일: views.py 프로젝트: lig/picket_classic
def add_project(request):
    
    if request.method == 'POST':
        projectForm = ProjectForm(request.POST)
        if projectForm.is_valid():
            project = projectForm.save()
            request.user.message_set.create(message=_('Project created'))
            return redirect(project.get_absolute_url())
    else:
        projectForm = ProjectForm()
    
    return direct_to_template(request, 'picket/admin/project_add.html',
        {'project_form': projectForm,})
예제 #35
0
def server_type_edit(request, uuid):
    """修改项目"""
    Server_Type = Project.objects.all()
    business_name = Project.objects.get(uuid=uuid)
    uf = ProjectForm(instance=business_name)
    if request.method == 'POST':
        uf = ProjectForm(request.POST, instance=business_name)
        if uf.is_valid():
            myform = uf.save()
            return render_to_response('assets/server_type_edit_ok.html',
                                      locals(),
                                      context_instance=RequestContext(request))
    return render(request, 'assets/server_type_edit.html', locals())
예제 #36
0
파일: views.py 프로젝트: Seppala/Learness
def createProject(request):
    #un = User.__unicode__(request.user)
    #user = get_object_or_404(User, username = un)
    if request.method == 'POST': # If the form has been submitted...
        user = Project(owner = request.user)
        form = ProjectForm(request.POST, instance = user) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            new_project = form.save()           
            return HttpResponseRedirect('/flow/') # Redirect after POST
    else:
        form = ProjectForm() # An unbound form
        variables = RequestContext(request, { 'form': form })
        return render_to_response('flow/createproject.html', variables)
예제 #37
0
def edit_project(request, id):
    project = get_object_or_404(Project, id=id)
    # TODO: check if user is owner
    if request.method == "POST":
        form = ProjectForm(request.POST, instance=project, user=request.user)
        if form.is_valid():
            form.save(request)
            messages.success(request, "Project edited successfully.")
            return HttpResponseRedirect(reverse("project_detail", kwargs={"id": id}))
    else:
        form = ProjectForm(instance=project)
    return render_to_response(
        "authenticated/project/edit_project.html", locals(), context_instance=RequestContext(request)
    )
예제 #38
0
def new_project(request):
    project_form = ProjectForm()
    if request.method == 'POST':
        project_form = ProjectForm(request.POST)        
        if project_form.is_valid():
            project = project_form.save()
            return render_to_response(
                'project_saved.html',
                {'project': project}
            )
    return render_to_response(
        'edit_project.html',
        {'project_form': project_form}
    )
예제 #39
0
def updateProject(request):

  proj_name = request.session["project_name"]
  if request.method == 'POST':
    
    if 'UpdateProject' in request.POST:
      proj_update = get_object_or_404(Project,project_name=proj_name)
      form = ProjectForm(data= request.POST or None,instance=proj_update)
      if form.is_valid():
        newproj = form.save(commit=False)
        if newproj.user_id == request.user.id or request.user.is_superuser:
          if newproj.project_name != proj_name:
            messages.error ("Cannot change the project name.  MySQL cannot rename databases.")
          else:
            newproj.save()
            messages.success(request, 'Sucessfully updated project ' + proj_name)
        else:
          messages.error(request,"Cannot update.  You are not owner of this project or not superuser.")
        del request.session["project_name"]
        return HttpResponseRedirect(get_script_prefix()+'ocpuser/projects')
      else:
        #Invalid form
        context = {'form': form}
        return render_to_response('updateproject.html',context,context_instance=RequestContext(request))
    elif 'backtoprojects' in request.POST:
      return HttpResponseRedirect(get_script_prefix()+'ocpuser/projects')
    else:
      #unrecognized option
      messages.error(request,"Unrecognized Post")
      return HttpResponseRedirect(get_script_prefix()+'ocpuser/pojects')
      
  else:
    #Get: Retrieve project and display update project form.
    if "project_name" in request.session:
      proj = request.session["project_name"]
    else:
      proj = ""
    project_to_update = Project.objects.filter(project_name=proj)
    data = {
      'project_name': project_to_update[0].project_name,
      'project_description':project_to_update[0].project_description,
      'dataset':project_to_update[0].dataset_id,
      'public':project_to_update[0].public,
      'host':project_to_update[0].host,
      'kvengine':project_to_update[0].kvengine,
      'kvserver':project_to_update[0].kvserver,
    }
    form = ProjectForm(initial=data)
    context = {'form': form}
    return render_to_response('updateproject.html',context,context_instance=RequestContext(request))
예제 #40
0
def edit_project(request, id):
    project = get_object_or_404(Project, id=id)
    #TODO: check if user is owner
    if request.method == "POST":
        form = ProjectForm(request.POST, instance=project, user=request.user)
        if form.is_valid():
            form.save(request)
            messages.success(request, 'Project edited successfully.')
            return HttpResponseRedirect(
                reverse('project_detail', kwargs={'id': id}))
    else:
        form = ProjectForm(instance=project)
    return render_to_response('authenticated/project/edit_project.html',
                              locals(),
                              context_instance=RequestContext(request))
예제 #41
0
def edit_project(request, projectID):
    project = project_api.get_project(projectID)
    if request.method == 'POST':
        form = ProjectForm(request.POST, instance=project)
        if form.is_valid():
            project = form.save(commit=True)
            return redirect('/req/projects')
    else:
        form = ProjectForm(instance=project)
        
    context = {'projects' : project_api.get_projects_for_user(request.user.id),
               'canOwnProject' : request.user.has_perm(PERMISSION_OWN_PROJECT),
               'title' : 'Edit Project',
               'form' : form, 'action' : '/req/editproject/' + projectID, 'desc' : 'Save Changes'}
    return render(request, 'ProjectSummary.html', context )
예제 #42
0
파일: views.py 프로젝트: nmasur/creationdex
def newproject(request):
	basic = get_basic(request)
	if request.method == 'POST':
		form = ProjectForm(request.user, request.POST, request.FILES)
		if form.is_valid():
			obj = form.save(commit=False)
			obj.user = request.user
			obj.save()
			form.save_m2m()
			return HttpResponseRedirect('/project?id=' + str(obj.id))
	else:
		proj = Project()
		proj.user = request.user
		form = ProjectForm(request.user, instance=proj)
	return render(request, 'newproject.html', {'form': form, 'basic': basic})
예제 #43
0
파일: views.py 프로젝트: idiles/taskapp
def index(request):
    projects = Project.objects.filter(creator=request.user).all()
    
    form = ProjectForm()
    
    if request.method == 'POST':
        project = Project(creator=request.user, slug='_')
        form = ProjectForm(request.POST, instance=project)
        if form.is_valid():
            project = form.save()
            request.notifications.add(_(u'Project successfully created'))
            return redirect(reverse('tasks:index'))
        
    return direct_to_template(request, 'tasks/project_index.html', 
        dict(projects=projects, form=form))
예제 #44
0
def project(request):
    user = request.user
    bio = Bio.objects.get(user=user)
    if request.method == 'POST':
        form = ProjectForm(request.POST)
        if form.is_valid():
            project = form.save(commit=False)
            project.bio = bio
            project.save()
            return redirect('skills')
        else:
            HttpResponse('please fill the form')
    else:
        form = ProjectForm()
    return render(request, 'skills/projects.html', {'form': form})
예제 #45
0
def new_project(request):
    if request.method == 'POST':
        form = ProjectForm(request.POST)
        if form.is_valid():
            project_api.create_project(request.user, request.POST)
            project = form.save(commit=False)
            return redirect('/req/projects')
    else:
        form = ProjectForm()
        
    context = {'projects' : project_api.get_projects_for_user(request.user.id),
               'canOwnProject' : request.user.has_perm(PERMISSION_OWN_PROJECT),
               'title' : 'New Project',
               'form' : form, 'action' : '/req/newproject' , 'desc' : 'Create Project' }
    return render(request, 'ProjectSummary.html', context )
예제 #46
0
def edit_project(request, project_id):
    if request.method == 'POST':
        p = Project.objects.get(pk=project_id)
        updated_form = ProjectForm(request.POST, instance=p)
        if updated_form.is_valid():
            updated_form.save()
            return HttpResponseRedirect(reverse('manage_project'))
    else:
        proj_obj = Project.objects.get(pk=project_id)
        pform = ProjectForm(instance=proj_obj)
        context = {'project_form': pform, 'name': proj_obj.name,
                   'pk': proj_obj.pk}
        context.update(csrf(request))
        return render_to_response('viewer/project/edit_project.html',
                                  context,
                                  context_instance=RequestContext(request))
예제 #47
0
파일: project.py 프로젝트: zhonghua001/sbdb
def project_add(request):
    temp_name = "appconf/appconf-header.html"
    if request.method == 'POST':
        form = ProjectForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('project_list'))
    else:
        form = ProjectForm()

    results = {
        'form': form,
        'request': request,
        'temp_name': temp_name,
    }
    return render(request, 'appconf/project_base.html', results)
예제 #48
0
def new_project(request):
    if request.method == 'POST':
        form = ProjectForm(request.POST)
        if form.is_valid():
            project_api.create_project(request.user, request.POST)
            project = form.save(commit=False)
            # return redirect('/req/projects')
            # return empty string and do the redirect stuff in front-end
            return HttpResponse('')
    else:
        form = ProjectForm()
        
    context = {'projects' : project_api.get_projects_for_user(request.user.id),
               'canOwnProject' : request.user.has_perm(PERMISSION_OWN_PROJECT),
               'title' : 'New Project',
               'form' : form, 'action' : '/req/newproject' , 'button_desc' : 'Create Project' }
    return render(request, 'ProjectSummary.html', context )
예제 #49
0
def edit_project(request, projectID):
    project = project_api.get_project(projectID)
    if request.method == 'POST':
        form = ProjectForm(request.POST, instance=project)
        if form.is_valid():
            project = form.save(commit=True)
            # return redirect('/req/projects')
            # return empty string and do the redirect stuff in front-end
            return HttpResponse('')
    else:
        form = ProjectForm(instance=project)
        
    context = {'projects' : project_api.get_projects_for_user(request.user.id),
               'canOwnProject' : request.user.has_perm(PERMISSION_OWN_PROJECT),
               'title' : 'Edit Project',
               'form' : form, 'action' : '/req/editproject/' + projectID, 'button_desc' : 'Save Changes'}
    return render(request, 'ProjectSummary.html', context )
예제 #50
0
파일: views.py 프로젝트: jpihl/plotato
def edit_project(request, project_id):
    """ Edit Project.

    """
    project = get_object_or_404(Project, pk=project_id)
    if request.method == "POST":
        form = ProjectForm(request.POST, instance=project)
    else:
        form = ProjectForm(instance=project)
    if form.is_valid():  # All validation rules pass
        form.save()
        messages.add_message(request, messages.INFO,
                             'The project has been successfully modified.')
        return redirect(details_project, project_id=project.key)

    return render_to_response('form.html', {'form': form},
                              context_instance=RequestContext(request))
예제 #51
0
파일: views.py 프로젝트: dcbishop/rust-ci
def add_project(request):
    if request.method == 'POST':
        form = ProjectForm(request.POST)

        if form.is_valid():
            package = form.cleaned_data['package']
            username = form.cleaned_data['username']
            repository = form.cleaned_data['repository']
            branch = form.cleaned_data['branch']
            cargo_support = form.cleaned_data['cargo_support']
            categories = form.cleaned_data['categories']

            repo = travisclient.get_repo(username, repository)

            if not repo:
                error_message = 'Unable to get Travis CI repo: {}/{}'.\
                    format(username, repository)
                return index(request, error_message)

            project = Project(package=package,
                              username=username,
                              repository=repository,
                              branch=branch,
                              cargo_support=cargo_support)

            if ('description' in repo and repo['description']):
                project.description = repo['description']
            else:
                project.description = ''
            project.save()

            # Set categories
            project.categories = categories
            project.save()

            return authenticate_with_github(request, project.id, 'add_project')

    else:
        form = ProjectForm(initial={'branch': 'master'})

    context = {
        'title': private_settings.APP_TITLE,
        'form': form,
        'categories': ProjectCategory.objects.all()
    }
    return render(request, 'ppatrigger/project_form.html', context)
예제 #52
0
def add_project(request):
	# REMEMBER TO HANDLE UNAUTHENTICATED USERS
	if request.method == 'POST':
		projectForm = ProjectForm(request.POST)
		if projectForm.is_valid() and request.user.is_authenticated():
			project = projectForm.save(commit = False) 
			project.creator = request.user
			project.soundCloud = getIFrameSrc(projectForm.cleaned_data['soundCloud'])
			project.is_active = True
			project.save()
			projectForm.save_m2m()
			return HttpResponseRedirect('profile/' + request.user.username)
		else: 
			return render(request, 'addProject.html', {'projectForm': projectForm})
	else: 
		projectForm = ProjectForm()
		return render(request, 'addProject.html', {'projectForm': projectForm})
예제 #53
0
def server_type_add(request):
    """添加项目"""
    if request.method == 'POST':  # 验证post方法
        init = request.GET.get("init", False)
        uf = ProjectForm(request.POST)
        if uf.is_valid():
            project_name = uf.cleaned_data['service_name']
            if Project.objects.filter(service_name=project_name):
                emg = u'添加失败, 此项目 %s 已存在!' % project_name
                return my_render('assets/server_type_add.html', locals(),
                                 request)
            uf.save()
            if not init:
                return HttpResponseRedirect("/assets/server/type/list/")
    else:
        uf = ProjectForm()
    return render(request, 'assets/server_type_add.html', locals())
예제 #54
0
파일: project.py 프로젝트: zhonghua001/sbdb
def project_edit(request, project_id):
    project = Project.objects.get(id=project_id)
    temp_name = "appconf/appconf-header.html"
    if request.method == 'POST':
        form = ProjectForm(request.POST, instance=project)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('project_list'))
    else:
        form = ProjectForm(instance=project)

    results = {
        'form': form,
        'project_id': project_id,
        'request': request,
        'temp_name': temp_name,
    }
    return render(request, 'appconf/project_base.html', results)
예제 #55
0
파일: views.py 프로젝트: pombredanne/ceeq
def project_edit(request, project_id):
    project = get_object_or_404(Project, pk=project_id)

    if request.method == "POST":
        form = ProjectForm(request.POST, instance=project)
        if form.is_valid():
            project = form.save()
            #messages.success(request, "Projects info has been saved.")
            return redirect(project_detail, project.id)
        else:
            messages.error(request, "Correct errors in the form.")
            context = RequestContext(request, {
                'form': form,
                'project': project,
                'superuser': request.user.is_superuser,
                'version_names': ['All Versions']
            })
            return render(request, 'proj/project_detail/project_detail.html', context)
    else:
        return redirect(projects)
예제 #56
0
def addproject(request):
	if request.POST:
		#files = upload_receive(request)
		form = ProjectForm(request.POST, request.FILES)
		if form.is_valid():
			f2 = form.save(commit=False)
			f2.save()
			return HttpResponseRedirect('/blog/viewprojects/')
		else:
			args = {}
			args.update(csrf(request))
			args['form']=form
			args['error']='Some error in form'
			return render_to_response('addproject.html',args)
				
	else:
		args = {}
		args.update(csrf(request))
		args['form'] = ProjectForm()
		return render_to_response('addproject.html',args)
예제 #57
0
def add_project(request):

    user = User.objects.get(username=request.user)

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

            model_instance = form.save(commit=False)
            model_instance.user = user
            model_instance.save()

            message = 'Thanks for adding a project!'

            context = {'message': message}
            return render(request, "thanks.html", context)
    else:
        form = ProjectForm()

    context = {'form': form}

    return render(request, "add_project.html", context)
예제 #58
0
def edit_project(request, project_id):
	if not request.user.is_authenticated(): 
		return render(request, 'test.html')
	
	# get the object 
	try:
		project = Project.objects.get(id = project_id)
	except :
		raise Http404
	 
	if request.method == 'POST':
		projectForm = ProjectForm(request.POST, instance = project)
		if projectForm.is_valid() and request.user.is_authenticated():
			project = projectForm.save(commit = False)
			project.user = request.user
			project.save()
			projectForm.save_m2m()
			return HttpResponseRedirect('/profile/' + request.user.username)
		else:
			return render(request, 'editProject.html', {'projectForm': projectForm})
	else:
		projectForm = ProjectForm(instance = project)
		return render(request, 'editProject.html', {'projectForm': projectForm})
예제 #59
0
def add_project(request):
    if request.method == 'POST':
        form = ProjectForm(request.POST)
        if form.is_valid():
            project = Project(owner=request.user,
                              title=form.cleaned_data['title'],
                              description=form.cleaned_data['description'],
                              nr_of_workers=form.cleaned_data['nr_of_workers'],
                              end_date=form.cleaned_data['end_date'])
            project.save()
            for s in form.cleaned_data['skills']:
                skill, created = Skill.objects.get_or_create(name=s.lower())
                if created:
                    skill.save()
                project.skills.add(skill)
                project.save()
            # print project.skills
        return redirect(reverse_lazy('projects_index'))
    else:
        form = ProjectForm()
        context_dict = {'form': form}
        return render(request, 'custom_projects/add_project.html',
                      context_dict)
예제 #60
0
def create_project_previous(request,projectId):
    context = RequestContext(request)
    user = request.user
    progress_status = 30
    project = Project.objects.get(id = projectId)
    rfp = RfpCampaign.objects.get(id = project.rfp.id)
    project_dict = model_to_dict(project)
    questions = rfp.get_project_questions()

    if request.method == 'POST':
        print (request.POST)
        #form = ProjectForm(request.POST,request.FILES, questions = questions)
        form = ProjectForm(request.POST, questions = questions)

        if form.is_valid():
            form_data = form.cleaned_data
            form_data.pop('document')

            print(form_data)
            proj_update = Project.objects.update_or_create(user = user, id = project.id, defaults=form_data)
            proj = proj_update[0]

            if request.FILES:
                proj.document = request.FILES['document']

            project = proj.save()

            if "Next" in request.POST:
                return HttpResponseRedirect(reverse('create_project_budget', args=[proj.pk]))
            else:
                return HttpResponseRedirect(reverse('create_project_previous', args=[proj.pk]))

    else:
        form = ProjectForm(initial= project_dict,questions = questions)

    return render_to_response('rfp/create_project_previous.html',{'form' : form, 'user' : user, 'progress_status' : progress_status, 'project' : project}, context)