def project(request, project_id): project = get_object_or_404(Project, id=project_id) if request.method == 'POST': form = UploadFabFileForm(request.POST, request.FILES) if form.is_valid(): fabfile = request.FILES['file'] content = fabfile.readlines() import_block, tasks = get_source(content) project.import_block = import_block project.save() stage = Stage(name="Imported", project=project) stage.save() stage_user = StageUser(user=request.user, stage=stage) stage_user.save() for task in tasks: task_obj = Task(name=task['name'], body=task['body']) task_obj.save() stage_task = StageTask(task=task_obj, stage=stage) stage_task.save() else: form = UploadFabFileForm() stages = project.stage_set.order_by('name',) deployments = Deploy.objects.filter(stage__in=stages).order_by('-finished_at',)[:3] return {'p': project, 'stages': stages, 'deps': deployments, 'form': form}
def appi_save_stage(request,*,stagename,process): if not stagename or not stagename.strip(): raise APIValueError('stagename','stagename cannot be empty') if not process or not process.strip(): raise APIValueError('process','process cannot be empty') stage = Stage(tagid=next_id(),stagename=stagename,process=process) yield from stage.save() return stage
def formfichestage(request): if request.method == "POST": nom = request.POST['nom'] prenom = request.POST['prenom'] choix_1 = request.POST['choix_1'] choix_2 = request.POST['choix_2'] choix_3 = request.POST['choix_3'] commentaire = request.POST['commentaire'] fiche = Fichestagecrd() fiche.nom = nom fiche.prenom = prenom fiche.choix_1 = Disciplinestagecrd.objects.get(id=choix_1) fiche.choix_2 = Disciplinestagecrd.objects.get(id=choix_2) fiche.choix_3 = Disciplinestagecrd.objects.get(id=choix_3) fiche.commentaires = commentaire fiche.save() intitules = Intitulestage.objects.all() for intitule in intitules: for i in range(1, 9): try: monintitule = request.POST["stage_"+str(intitule.id)+"-"+str(i)] monintitule = monintitule.split("-")[0] print(monintitule) except Exception: continue try: monstage = Stage.objects.get(fiche=fiche, intitule=intitule) except Stage.DoesNotExist: monstage = Stage() monstage.intitule = intitule monstage.fiche = fiche setattr(monstage, monintitule, True) monstage.save() return HttpResponseRedirect('merci.html') params = {} intitules = Intitulestage.objects.all() params.update({'intitules': intitules}) disciplines = Disciplinestagecrd.objects.all() params.update({'disciplines': disciplines}) return render_to_response('forms/fichestageform.html', params)
def stages(jobid): if request.method == 'GET': job = Job.objects(jobid=int(jobid)).first() stages = Stage.objects(job=job) itemLst = [dict(stage.to_mongo()) for stage in stages] return mongodoc_jsonify(items=itemLst) if request.method == 'POST': if request_has_json(): try: job = Job.objects(jobid=int(jobid)).first() reward = Reward.objects(itemid=request.json['reward']).first() model = Stage() model.job = job model.reward = reward model.rewardDesc = reward.itemid model.jobDesc = str(job.jobid) model.stage = request.json['stage'] model.save() model.reload() return mongodoc_jsonify(item=model.to_mongo()) except ValidationError as e: return jsonify(item=str(e))