def sendmail(req): if req.method == 'POST': mf = ModifyForm(req.POST) if mf.is_valid(): username = mf.cleaned_data['username'] if User.objects.filter(username=username): a = User.objects.get(username=username) b = a.userinfo_set.all()[0] email = b.email message = ''.join(random.sample(string.ascii_letters + string.digits, 4)) req.session['validate'] = message req.session['username'] = username title = "修改银翼网盘密码验证邮件!." # message = 'Hello! This is a message!' sender = '*****@*****.**' mail_list = [email, ] send_mail( subject=title, message=message, from_email=sender, recipient_list=mail_list, fail_silently=False, connection=None ) return HttpResponseRedirect('/online/validate/') else: error = '该用户名不存在' return render_to_response('modify_new.html', {'error': error}, context_instance=RequestContext(req)) else: mf = ModifyForm() return render_to_response('modify_new.html', context_instance=RequestContext(req))
def sendmail(req): if req.method == 'POST': mf = ModifyForm(req.POST) if mf.is_valid(): username = mf.cleaned_data['username'] if User.objects.filter(username=username): a = User.objects.get(username=username) b = a.userinfo_set.all()[0] email = b.email message = ''.join( random.sample(string.ascii_letters + string.digits, 4)) req.session['validate'] = message req.session['username'] = username title = "修改银翼网盘密码验证邮件!." # message = 'Hello! This is a message!' sender = '*****@*****.**' mail_list = [ email, ] send_mail(subject=title, message=message, from_email=sender, recipient_list=mail_list, fail_silently=False, connection=None) return HttpResponseRedirect('/online/validate/') else: error = '该用户名不存在' return render_to_response('modify_new.html', {'error': error}, context_instance=RequestContext(req)) else: mf = ModifyForm() return render_to_response('modify_new.html', context_instance=RequestContext(req))
def modify(todolist_id): form_t = TodoListForm() form_m = ModifyForm() todolist = TodoList.query.get_or_404(todolist_id) if form_m.validate_on_submit(): #???????????????? #此处要用正则才能取得所需数据 # content=re.findall(regex,str(form_m.content))[0] # todolist.content=u'%s' % content #如果使用下面这句代码替代上述2句,提交的结果是一个html标记 #todolist.content = u'%s' % str(form_m.content) #????????????????? todolist.content = request.form['content'] db.session.add(todolist) db.session.commit() return redirect(url_for('index')) #todolists=TodoList.query.all() page_index = request.args.get('page', 1, type=int) query = TodoList.query.order_by(TodoList.create_time.desc()) pagination = query.paginate(page_index, per_page=10, error_out=False) todolists = pagination.items return render_template('index.html', todolists=todolists, form=form_t, form_m=form_m, pagination=pagination)
def modify_post(request, **kwargs): """ This view allows you to modify a post. You may delete the post from this page. You can also view or delete comments from this post. """ pk = kwargs["pk"] if request.method == "GET": my_post = PostModel.objects.get(id=pk) post_form = ModifyForm(instance=my_post) return render_to_response( "posts/modify.html", {"form": post_form, "pk": pk}, context_instance=RequestContext(request) ) else: my_post = PostModel.objects.get(id=pk) post_form = ModifyForm(request.POST, instance=my_post) if post_form.is_valid(): delete_post = post_form.cleaned_data["delete_post"] if delete_post: my_post.delete() return HttpResponseRedirect("/posts/") else: post_form.save() return HttpResponseRedirect("/posts/%(pk)s/" % locals()) else: return render_to_response( "posts/modify.html", {"form": post_form, "pk": pk, "errors": post_form.errors}, context_instance=RequestContext(request), )
def modify(): """Processes new-found movie form data and adds it to database""" form = ModifyForm() if form.validate_on_submit(): movie = form.name.data # Get movie data and put it to our database rotten_url = 'http://api.rottentomatoes.com/api/public/v1.0/movies/{!s}.json?apikey={!s}'.format(movie, ROTTEN_KEY) req = urllib2.Request(rotten_url, headers={'Accept-Encoding': 'gzip, identity'}) conn = urllib2.urlopen(req) movie = conn.read() try: if conn.headers['content-encoding'] == 'gzip': movie = zlib.decompress(movie, 16+zlib.MAX_WBITS) except KeyError: pass movie = json.loads(movie) description = movie['synopsis'] genres = movie['genres'] # Put all genres in a string final = "" counter = 1 for genre in genres: final += genre if len(genres) > 1 and counter < len(genres): final += ', ' counter += 1 genres = final # Rest of the stuff ratings = movie['ratings'] ratings = ratings.get('audience_score') posters = movie['posters'] posters = posters.get('thumbnail') movie = movie['title'] ticketid = form.id.data # Just dump it to database querymovie = Movie.query.filter_by(id = ticketid).first() querymovie.status = 2 querymovie.description = description querymovie.genres = genres querymovie.ratings = ratings querymovie.posters = posters querymovie.name = movie db.session.commit() flash(movie+' added!') items = Movie.query.filter_by(status = 1).all() return render_template('modify.html', form = form, items = items)
def modify(): form = ModifyForm() if request.method == 'POST': if form.validate() == False: return render_template('modify.html', form=form) else: user_mod = User.query.filter_by(username = session['username']).first() #user_mod = User(form.username.data, form.homefolder.data, form.shelltype.data, form.sudopr.data) #user_mod.username = form.username.data user_mod.homefolder = form.homefolder.data user_mod.shelltype = form.shelltype.data user_mod.sudopr = form.sudopr.data db.session.commit() return redirect(url_for('profile'))
def change_paste(id): if request.method == "GET": pasteList = PasteText.query.filter_by(id=id).first_or_404() form = ModifyForm() form.content.data = pasteList.content return render_template("modify.html", form=form) else: form = ModifyForm() if form.validate_on_submit(): pasteList = PasteText.query.filter_by(id=id).first_or_404() pasteList.content = form.content.data pasteList.status = form.status.data db.session.commit() flash("You have modify a pasteList") else: flash(form.errors) return redirect(url_for("show_paste_list"))
def modify(request, data={}): if request.user.is_authenticated(): logedUser = request.user if request.method == 'POST': form = ModifyForm(request.POST, request.FILES) if form.is_valid(): user = UserData.objects.get(pk=logedUser.id) for attr, value in form.cleaned_data.iteritems(): if value: setattr(user, attr, value) user.save() return HttpResponseRedirect(reverse('thanks')) else: user = model_to_dict(UserData.objects.get(pk=logedUser.id)) form = ModifyForm(initial=user) return render(request, 'modify.html', {'form': form}) else: return HttpResponseRedirect(reverse('error'))
def modify_artwork(request, **kwargs): """ This view allows you to modify the attributes associated with a piece of artwork. You may delete a piece of artwork from this page. You can also view/delete comments associated with this image. """ pk = kwargs["pk"] my_art = ArtworkModel.objects.get(id=pk) # pk is the primary key of the art model we want to change if request.method == 'GET': # If this is a GET request, we should prepopulate a form with the artwork information. modify_form = ModifyForm(instance=my_art) # modify_form = populate_modify_form(my_art) return render_to_response("artwork/modify.html", {"form":modify_form, "pk": pk}, context_instance=RequestContext(request)) else: # If this is a POST request, we should take the form data handed to us #with the changed form information and resave it. modify_form = ModifyForm(request.POST, request.FILES, instance=my_art) if modify_form.is_valid(): # If the delete checkbox is selected, delete it # Hopefully this deletes the comments associated with the image as well. if modify_form.cleaned_data['delete_art']: my_art.delete() return HttpResponseRedirect("http://www.deathweasel.net/artwork/") else: modify_form.save() return HttpResponseRedirect("http://www.deathweasel.net/artwork/%s/" % (pk,)) else: # Recycle the form. return render_to_response("artwork/modify.html", {"form":modify_form, "pk": pk}, context_instance=RequestContext(request))
def erecord(): status = request.args.get('status') allnum = db.session.query(Erecord).count() nsolvenum = db.session.query(Erecord).filter( Erecord.solve == False).count() nverifynum = db.session.query(Erecord).filter( Erecord.verify == False).count() oknum = db.session.query(Erecord).filter(Erecord.verify == True).filter( Erecord.mender != '').filter(Erecord.solve == True).count() nobody = db.session.query(Erecord).filter(Erecord.mender == '').count() print status if status == '2': results = db.session.query(Erecord).filter( Erecord.verify == False).order_by(-Erecord.id) elif status == '3': results = db.session.query(Erecord).filter( Erecord.solve == False).order_by(-Erecord.id) elif status == '4': results = db.session.query(Erecord).filter( Erecord.verify == True).filter(Erecord.mender != '').filter( Erecord.solve == True).order_by(-Erecord.id) elif status == '5': results = db.session.query(Erecord).filter( Erecord.mender == '').order_by(-Erecord.id) else: results = db.session.query(Erecord).order_by(-Erecord.id) form = ModifyForm() if form.validate_on_submit(): return redirect(url_for('admin.emodify', id=form.id.data)) return render_template('admin/erecord.html', results=results, form=form, nsolvenum=nsolvenum, nverifynum=nverifynum, oknum=oknum, allnum=allnum, nobody=nobody)
def record(): results = db.session.query(Record).order_by(-Record.id) form = ModifyForm() if form.validate_on_submit(): return redirect(url_for('admin.modify', id=form.id.data)) return render_template('admin/record.html', results=results, form=form)
def comment(): comment = db.session.query(Comment).order_by(-Comment.id) form = ModifyForm() if form.validate_on_submit(): return redirect(url_for('admin.commentmodify', id=form.id.data)) return render_template('admin/comment.html', form=form, comment=comment)
def admin_modify_user(username): if not session.get('loggedin') or session.get('role') != 0: return redirect(url_for('login')) form = ModifyForm() if request.method == 'POST': #insert email = form.email.data password = form.password.data if password != '': password_hash = generate_password_hash(password, method='sha256') sql_query = '''UPDATE departments SET dept_email = %s, password = %s where dept_name = %s ''' try: cursor = db.cursor() cursor.execute(sql_query, ( email, password_hash, username, )) cursor.close() db.commit() except Exception as e: db.rollback() print("Error while modifying user", e) else: flash(f'Modified user {username}.', 'success') else: sql_query = '''UPDATE departments SET dept_email = %s where dept_name = %s ''' try: cursor = db.cursor() cursor.execute(sql_query, ( email, username, )) cursor.close() db.commit() except Exception as e: db.rollback() print("Error while modifying user", e) else: flash(f'Modified user {username}.', 'success') for dep in dept: if dep[1] == username: dep[2] = email return redirect(url_for('admin_list_users')) cursor = db.cursor() cursor.execute( 'SELECT dept_id,dept_name,dept_email FROM departments where dept_name = %s', (username, )) departments_data = cursor.fetchone() cursor.close() form.username.data = username form.email.data = departments_data[2] return render_template('admin_modify_user.html', form=form, logout=url_for('logout'), back=url_for('admin_list_users'))