def information(request, task): titleForm = TitleForm() if request.method == 'POST': titleForm = TitleForm(request.POST) if titleForm.is_valid(): print "before lock in information " + str(request.user.id) lock = FileLock("/home/senderma/projects/banalnosti/lockAddTitle") with lock: print "in information " + str(request.user.id) if(len(titleForm.cleaned_data['title'].split()) > 0): print "count information " + str(request.user.id) titleInput = titleForm.cleaned_data['title'] userTitle = Titles.objects.filter(gameID = task.gameID, user = request.user) if(len(userTitle) != 1 or userTitle[0].title != titleInput): Titles.objects.filter(gameID = task.gameID, user = request.user).delete() titlesNew = Titles(user = request.user, title = titleInput, gameID = task.gameID, tourID = -1) titlesNew.save() print "out information " + str(request.user.id) time.sleep(1) if len(Titles.objects.filter(gameID = task.gameID, user = request.user)) > 0: titleYour = Titles.objects.filter(gameID = task.gameID, user = request.user)[0] #для html peoplesInputTitles = map(lambda x: x.user, Titles.objects.filter(gameID = task.gameID)) currentTime = timezone.now() taskNext = Tasks.objects.filter(taskTime__gt = task.taskTime).order_by('taskTime')[0] NUMBER_SEC_REDIRECT = taskNext.taskTime - currentTime NUMBER_SEC_REDIRECT = NUMBER_SEC_REDIRECT.days*60*60*24 + NUMBER_SEC_REDIRECT.seconds + 1 NEXT_PAGE = '/main/' message = "До игры осталось" return render_to_response('info.html', locals(), context_instance=RequestContext(request))
def edit_title(id): """ Edit a title """ check_admin() add_title = False title = Title.query.get_or_404(id) form = TitleForm(obj=title) if form.validate_on_submit(): title.name = form.name.data db.session.commit() flash('You have successfully edited the title.') # redirect to the titles page return redirect(url_for('admin.list_titles')) form.name.data = title.name return render_template('admin/titles/title.html', action="Edit", add_title=add_title, form=form, title_edit=title, title="Edit Title")
def add_title(): """ Add a title to the database """ check_admin() add_title = True form = TitleForm() if form.validate_on_submit(): title = Title(name=form.name.data) try: # add title to the database db.session.add(title) db.session.commit() flash('You have successfully added a new title.') except: # in case title name already exists flash('Error: title name already exists.') # redirect to titles page return redirect(url_for('admin.list_titles')) # load title template return render_template('admin/titles/title.html', action="Add", add_title=add_title, form=form, title="Add Title")
def add_sequencelisting(request): if request.method == 'POST': form = SequenceListingForm(request.POST) title_form = TitleForm(request.POST) if form.is_valid() and title_form.is_valid(): filingDateFromForm = request.POST.get('filingDate') # set to None bc the model does not handle properly empty string from form fd = filingDateFromForm if filingDateFromForm else None sl_instance = SequenceListing.objects.create( fileName=request.POST.get('fileName'), dtdVersion='1', softwareName='prototype', softwareVersion='0.1', productionDate=timezone.now( ), #should be overwritten upon xml export applicantFileReference=request.POST.get( 'applicantFileReference'), IPOfficeCode=request.POST.get('IPOfficeCode'), applicationNumberText=request.POST.get( 'applicationNumberText'), # filingDate = request.POST.get('filingDate'), filingDate=fd, earliestPriorityIPOfficeCode=request.POST.get( 'earliestPriorityIPOfficeCode'), earliestPriorityApplicationNumberText=request.POST.get( 'earliestPriorityApplicationNumberText'), earliestPriorityFilingDate=request.POST.get( 'earliestPriorityFilingDate'), applicantName=request.POST.get('applicantName'), applicantNameLanguageCode=request.POST.get( 'applicantNameLanguageCode'), applicantNameLatin=request.POST.get('applicantNameLatin'), inventorName=request.POST.get('inventorName'), inventorNameLanguageCode=request.POST.get( 'inventorNameLanguageCode'), inventorNameLatin=request.POST.get('inventorNameLatin'), ) sl_instance.save() tcd = title_form.cleaned_data title_instance = Title( sequenceListing=sl_instance, inventionTitle=tcd['inventionTitle'], inventionTitleLanguageCode=tcd['inventionTitleLanguageCode']) title_instance.save() return HttpResponseRedirect( reverse('sequencelistings:edit_seql', args=(sl_instance.pk, ))) else: form = SequenceListingForm() title_form = TitleForm() return render(request, 'sequencelistings/add_sequencelisting.html', { 'form': form, 'title_form': title_form })
def add_sequencelisting(request): if request.method == 'POST': form = SequenceListingForm(request.POST) title_form = TitleForm(request.POST) if form.is_valid() and title_form.is_valid(): filingDateFromForm = request.POST.get('filingDate') # set to None bc the model does not handle properly empty string from form fd = filingDateFromForm if filingDateFromForm else None sl_instance = SequenceListing.objects.create( fileName = request.POST.get('fileName'), dtdVersion = '1', softwareName = 'prototype', softwareVersion = '0.1', productionDate = timezone.now(), #should be overwritten upon xml export applicantFileReference = request.POST.get('applicantFileReference'), IPOfficeCode = request.POST.get('IPOfficeCode'), applicationNumberText = request.POST.get('applicationNumberText'), # filingDate = request.POST.get('filingDate'), filingDate = fd, earliestPriorityIPOfficeCode = request.POST.get('earliestPriorityIPOfficeCode'), earliestPriorityApplicationNumberText = request.POST.get('earliestPriorityApplicationNumberText'), earliestPriorityFilingDate = request.POST.get('earliestPriorityFilingDate'), applicantName = request.POST.get('applicantName'), applicantNameLanguageCode = request.POST.get('applicantNameLanguageCode'), applicantNameLatin = request.POST.get('applicantNameLatin'), inventorName = request.POST.get('inventorName'), inventorNameLanguageCode = request.POST.get('inventorNameLanguageCode'), inventorNameLatin = request.POST.get('inventorNameLatin'), ) sl_instance.save() tcd = title_form.cleaned_data title_instance = Title(sequenceListing = sl_instance, inventionTitle = tcd['inventionTitle'], inventionTitleLanguageCode = tcd['inventionTitleLanguageCode'] ) title_instance.save() return HttpResponseRedirect(reverse('sequencelistings:detail', args=(sl_instance.pk,))) else: form = SequenceListingForm() title_form = TitleForm() return render(request, 'sequencelistings/add_sequencelisting.html', {'form': form, 'title_form': title_form})
def create(request): if request.POST: form = TitleForm(request.POST, request.FILES) if form.is_valid(): form.save() return HttpResponseRedirect('/titles/all') else: form = TitleForm() args = {} args.update(csrf(request)) args['form'] = form return render_to_response('create_title.html', args)
def add_title(request, pk): if request.method == 'POST': form = TitleForm(request.POST) if form.is_valid(): sl = SequenceListing.objects.get(pk=pk) cd = form.cleaned_data title_instance = Title(sequenceListing = sl, inventionTitle = cd['inventionTitle'].encode('utf-8'), inventionTitleLanguageCode = cd['inventionTitleLanguageCode'] ) title_instance.save() return HttpResponseRedirect(reverse('sequencelistings:detail', args=(pk,))) else: form = TitleForm() return render(request, 'sequencelistings/add_title.html', {'form': form, 'pk': pk})
def add_title(request, pk): if request.method == 'POST': form = TitleForm(request.POST) if form.is_valid(): sl = SequenceListing.objects.get(pk=pk) cd = form.cleaned_data title_instance = Title( sequenceListing=sl, inventionTitle=cd['inventionTitle'].encode('utf-8'), inventionTitleLanguageCode=cd['inventionTitleLanguageCode']) title_instance.save() return HttpResponseRedirect( reverse('sequencelistings:edit_seql', args=(pk, ))) else: form = TitleForm() return render(request, 'sequencelistings/add_title.html', { 'form': form, 'pk': pk })
def start(request): id_tour = (cur_time() - time_start()) / (length_game()) time = time_start() temp = request.user.username formTitle = TitleForm() isTitle = False if request.method == 'POST': formTitle = TitleForm(request.POST) if len(Player.objects.filter(name = temp)) == 0: player = Player(name = request.user.username, point = 0) player.save() if formTitle.is_valid(): inputTitle = formTitle.cleaned_data['title'].split() if(len(inputTitle) > 0): VersionTitles.objects.filter(user = request.user).delete() isTitle = formTitle.cleaned_data['title'] title = VersionTitles(user = request.user, title = formTitle.cleaned_data['title'], mark = 0) title.save() list_player = Player.objects.all() namePlayers = [] for player in list_player: namePlayers.append(User.objects.get(username = player.name).first_name + " " + User.objects.get(username=player.name).last_name) NUMBER_SEC_REDIRECT = time - cur_time() return render_to_response('start.html', dict({'message': "До игры осталось", 'NEXT_PAGE': '/write.words/', 'NUMBER_SEC_REDIRECT':NUMBER_SEC_REDIRECT}, **locals()))
def custom_form_view(request): if request.method == 'POST': form = TitleForm(request.POST) if form.is_valid(): # form.save() return redirect('/forms') else: form = TitleForm() time.sleep(2) return render(request, 'forms/form.html', {'form': form.as_p(), 'action': '/forms/custom'})
def model_parameters(request): errormsg = "" if request.method == 'POST': titleform = TitleForm(request.POST) outvarform = OutputVarForm(request.POST) resform = ResultsForm(request.POST) tstepform = TimeStep(request.POST) outstepform = OutStep(request.POST) durform = Duration(request.POST) initcondform = InitConds(request.POST) initcondvalform = InitValue(request.POST) tidalflatsform = TidalFlats(request.POST) opttidalflatsform = OptTidalFlats(request.POST) optliqbndryform = OptLiquidBndry(request.POST) tidaldbform = TidalDatabase(request.POST) autotuneform = AutoTune(request.POST) autotuneoptsform = AutoTuneOpts(request.POST, request.FILES) bottomfric = BottomFric(request.POST) mobilealert = MobileAlert(request.POST) if tstepform.is_valid() and outvarform.is_valid( ) and outstepform.is_valid() and durform.is_valid( ) and initcondform.is_valid() and optliqbndryform.is_valid(): postitems = {} #autotuneoptsform.save() mytitle = request.POST['title'] outvars = request.POST.getlist('outputvar') for key, value in request.POST.items(): print(key, value) postitems[key] = value postitems['meshfile'] = request.session.get('meshfile', None) postitems['bcfile'] = request.session.get('bcfile', None) postitems['outputvar'] = outvars mycasfile = CASFILE(postitems) mycasfile.writeCasfile() if 'autocalib' in postitems: if postitems['autocalib'] == "1": if autotuneoptsform.is_valid(): autotuneoptsform.save() content = request.FILES['obsfldr'] cwd = os.getcwd() dirname = cwd + "\\documents\\" zippath = dirname + str(content) zipobj = zipfile.ZipFile(zippath) zipobj.extractall(dirname) zipobj.close() os.remove(zippath) else: errormsg = "Please fill in all the fields." else: titleform = TitleForm() outvarform = OutputVarForm() resform = ResultsForm() tstepform = TimeStep() outstepform = OutStep() durform = Duration() initcondform = InitConds() initcondvalform = InitValue() tidalflatsform = TidalFlats({'tidalflats': 'YES'}) opttidalflatsform = OptTidalFlats({ 'opttidalflats': '1', 'optnegdepths': '1' }) optliqbndryform = OptLiquidBndry() tidaldbform = TidalDatabase() autotuneform = AutoTune() autotuneoptsform = AutoTuneOpts() bottomfric = BottomFric() mobilealert = MobileAlert() geodata = request.session.get('my_data', None) meshcentre = request.session.get('centre', None) bndrysgeojson = request.session.get('bndrysgeojson') northbndry = json.dumps(bndrysgeojson['northbndry']) southbndry = json.dumps(bndrysgeojson['southbndry']) return render(request, 'runtide/modelforms.html', locals())