def record(request): if request.POST: errors = [] if 'name' in request.POST: tutor = Tutor.objects.filter(name=request.POST['name']) if not tutor: tutor = Tutor.objects.create( name=request.POST['name'] ) tutor.save() tutor = Tutor.objects.get(name=request.POST['name']) form = LogForm(request.POST) if form.is_valid(): log = Log.objects.create( tutor=tutor, date=datetime.strptime( request.POST['date'].encode('utf-8'), "%m/%d/%Y" ), hours_worked=request.POST['hours_worked'] ) log.save() success = True form = LogForm() return render(request, 'home.html', {'form': form, 'errors': errors, 'success': success}) else: return render(request, 'home.html', {'form': form, 'errors': errors}) else: errors.append({"Please provide your name"}) return redirect(home)
def addLog(request): # If user is logged in if request.user.is_authenticated(): # And submitted the form if request.method == 'POST': # Get form info form = LogForm(request.POST) if form.is_valid(): # Save the log without commit so its not saved in database log = form.save(commit=False) log.user = request.user # Get info grom FormSet, our created log as instance lift_formset = LiftFormSet(request.POST, instance=log) if lift_formset.is_valid(): # Finally save the log log.save() # Save formset attached to log lift_formset.save() return HttpResponseRedirect('/myliftinglog/') # if user did not submit form, render the form else: form = LogForm() lift_formset = LiftFormSet(instance=Log()) return render_to_response('addlog.html', {'form': form, 'formset': lift_formset} , context_instance=RequestContext(request)) else: return HttpResponseRedirect('/myliftinglog/register')
def LogViewTemplate(request): if request.method == 'POST': tmp = LogForm(request.GET) if tmp.is_valid(): return HttpResponseRedirect('/thanks/') else: tmp = LogForm() return render(request, 'logger.html', { 'form': tmp })
def login(): forms = LogForm() if forms.validate_on_submit(): if forms.email.data == '*****@*****.**' and forms.password.data == '123456789': flash(f'You have been logged in!', 'success') return redirect(url_for('home')) else: flash(f'Login Unsuccesful! Please check your email id and password', 'danger') return render_template('login.html', title='Login', form=forms)
def login(): form = LogForm() if form.validate_on_submit(): if form.email.data == "*****@*****.**" and form.password.data == "password": flash('You have been logged in!', 'success') return redirect(url_for('home')) else: flash('Login unsuccessful', 'danger') return render_template('login.html', title='Login', form=form)
def SaveLogFromTemplate(request): if request.method == "POST": form = LogForm(request.POST) if form.is_valid(): cleaned = form.cleaned_data path = cleaned['usr_filepath'] message = cleaned['message'] GeneralLogger(message=message, usr_filepath=path, sys_time=timezone.now()).save() return render(request, 'log-template-submit-thank.html', {}) else: print(form.errors) return HttpResponse('<h3>Some error occurred while rendering the form</h3>')
def upload_log(request): if request.method == 'POST': form = LogForm(request.POST, request.FILES) if form.is_valid(): player_id = form.cleaned_data['player'] log_file = request.FILES['file'] parse_log(player_id, log_file) return HttpResponse() else: return HttpResponseBadRequest() return render(request, 'upload_log.html', {'form': LogForm()})
def login(): loginForm = LogForm() if loginForm.validate_on_submit(): userData = [loginForm.username.data, loginForm.password.data] if data_manipulation.login_data_check(userData): session['username'] = loginForm.username.data return render_template('login.html', form=loginForm, username=session.get('username')) else: flash('Nombre de usuario o contraseña erroneas') return redirect('/login') return render_template('login.html', form=loginForm, username=session.get('username'))
def post(self, request): form = LogForm(request.POST, request.FILES) if form.is_valid(): filename = os.path.join(settings.MEDIA_ROOT, request.FILES['log'].name) utils.save_uploaded_file(filename, request.FILES['log']) nlp = NexuizLogParser(get_known_player_nicks('nexuiz_log_parser.players.PLAYERS')) nlp.parse_logs([filename.encode('ascii')]) output = nlp.output(output='html') temp_template = os.path.join(settings.PROJECT_ROOT, 'onlineparser', 'templates', self.template_name) with open(temp_template, 'w') as dest: dest.write(output.decode('utf-8', 'ignore')) return render_to_response(self.template_name, {}, context_instance=RequestContext(request)) return render_to_response('parser.html', {'form': form}, context_instance=RequestContext(request))
def log_view(request, cluster_id): session = request.session owner_id = session.get('owner_id') cluster = get_object_or_404(Cluster, pk=cluster_id, owner_id=owner_id) if request.method == 'POST': form = LogForm(request.POST) if form.is_valid(): pass # c_d = form.cleaned_data #verbose = c_d.get('verbose') #TODO: handled if/else verbose else: form.errors['non_field_errors'] = "Unexpected value posted" else: form = LogForm() try: log_entries = get_log_entries(cluster_id, owner_id) except IOError: log_entries = '' return render_to_response('aws_log.html', { 'cluster': cluster, 'log_entries': log_entries, 'form': form }, context_instance=RequestContext(request))
def record(request): if request.POST: errors = [] if 'name' in request.POST: tutor = Tutor.objects.filter(name=request.POST['name']) if not tutor: tutor = Tutor.objects.create(name=request.POST['name']) tutor.save() tutor = Tutor.objects.get(name=request.POST['name']) form = LogForm(request.POST) if form.is_valid(): log = Log.objects.create( tutor=tutor, date=datetime.strptime( request.POST['date'].encode('utf-8'), "%m/%d/%Y"), hours_worked=request.POST['hours_worked']) log.save() success = True form = LogForm() return render(request, 'home.html', { 'form': form, 'errors': errors, 'success': success }) else: return render(request, 'home.html', { 'form': form, 'errors': errors }) else: errors.append({"Please provide your name"}) return redirect(home)
def login(): form=LogForm() if request.method=="POST": email=form.email.data password=form.password.data user=User.query.filter_by(email=email).first() if not user: flash("This user does not exist") return redirect(url_for('login')) if user and check_password_hash(user.password,password): login_user(user) return redirect(url_for('get_all_posts')) else: flash("Password is not correct") return redirect(url_for("login")) return render_template("login.html",form=form)
def login(): form = LogForm() return render_template('login.html', title='Login', form=form)
def home(request): form = LogForm() return render(request, 'home.html', {'form': form})