def tag_update(id): tag_name = db.tag_select_by_id(id)['name'] form = TagForm(tag_id=id, tag_name=tag_name) if form.validate_on_submit(): if form.tag_submit.data: response = db.tag_update_one(id, form.tag_name.data) if response: flash(response, 'error') else: flash('Successful UPDATE', 'message') return redirect(url_for('tag_update', id=id)) elif form.tag_delete.data: response = db.tag_delete_one(id) if response: flash(response, 'error') else: flash('Successful DELETE', 'message') return redirect(url_for('tag')) flash_validation_errors(form) return render_template('form_tag_update.html', form=form)
def new_tag(): form = TagForm() if form.validate_on_submit(): flash('Tag with name %r created successfully!' % (form.name.data)) new_tag = models.Tag(name=form.name.data) db.session.add(new_tag) db.session.commit() return redirect('/admin/new_tag') return render_template('new_tag.html', title="New Tag - Admin", form=form, user=current_user)
def edit_tag(name): form = TagForm() if form.validate_on_submit(): tag = db.session.query(models.Tag).filter_by(name=name).one() tag.name = form.name.data db.session.commit() flash('Tag with name %r changed to %r successfully!' % (name, form.name.data)) return redirect('/admin') form.name.data = name return render_template('new_tag.html', title="Edit Tag - Admin", form=form, user=current_user)
def addtag(): form = TagForm() if form.validate_on_submit(): tag_content = form.tag_content.data tag = Tag(tag_content=tag_content) form_todo=TodoForm() form_todo.select_tag.choices+=[(tag.tag_content,tag.tag_content)] db.session.add(tag) return redirect(url_for('addtag')) alltags = Tag.query.all() return render_template("addtag.html", alltags=alltags,form=form)
def add_tag(item_id): form = TagForm() if form.validate_on_submit(): addtag = tag(tagged=form.tagged.data, tagger=current_user.get_id(), item_id=item_id) db.session.add(addtag) db.session.commit() flash('Your Tag is submitted. Waiting on Approval', 'Success') return redirect(url_for('home')) return render_template('add_tagging.html', title='New Tag', form=form)
def submit_tag_form(): form = TagForm() #TODO: This conditional seems to always == else if form.validate_on_submit(): return redirect('/success') else: print 'record updating...' print 'Form Data: %s' % request.form.get('name') print 'Form Data: %s' % request.form return render_template('submit.html', form=form)
def edit_tag(t_id): tag = get_tag(t_id) form = TagForm(tag=tag['tag'], parent=tag['parent']) form.set_choices() if form.validate_on_submit(): d = _to_dict(form) update_tag(d, t_id) return redirect(url_for('table_tags')) return render_template(form.template, form=form, name='Редактировать тег')
def add_tag(): form = TagForm() form.set_choices() if form.validate_on_submit(): d = _to_dict(form) try: form.add(d) except: flash("Что-то пошло не так. Вероятно, такой тег уже существует") return redirect(url_for('add_tag')) return redirect(url_for('table_tags')) return render_template(form.template, form=form, name="Add tag")
def edit_tag(tagid): if g.user.is_admin() != 1: flash('This user cannot edit tags!') return redirect(url_for('tags')) page_title = 'Edit tag' tag = Tag.query.get(int(tagid)) form = TagForm(request.form, obj=tag) if request.method == 'POST' and form.validate_on_submit(): # save new data in tag here form.populate_obj(tag) db.session.add(tag) db.session.commit() return redirect(url_for('tags')) return render_template('tag_editor.html', form_action = 'edit_tag', form = form, page_title = page_title)
def tag_edit(id=None): form = TagForm() tag = Tag.query.get_or_404(id) if form.validate_on_submit(): data = form.data tag_num = Tag.query.filter_by(name=data["tag_name"]).count() if tag.name != data["tag_name"] and tag_num == 1: flash("标签名称已经存在!", "err") return redirect(url_for("admin.tag_edit", id=id)) tag.name = data["tag_name"] db.session.add(tag) db.session.commit() flash("修改标签成功!", "ok") #return redirect(url_for("admin.tag_edit",id=id)) return redirect(url_for("admin.tag_list", page=1)) return render_template("admin/tag_edit.html", form=form, tag=tag)
def tag_new(): form = TagForm() if form.validate_on_submit(): response = db.tag_insert_one(form.tag_name.data) if response: flash(response, 'error') else: flash('Successful INSERT', 'message') return redirect(url_for('tag_new')) flash_validation_errors(form) return render_template('form_tag_new.html', form=form)
def tag_add(): form = TagForm() if form.validate_on_submit(): data = form.data tag_num = Tag.query.filter_by(name=data["tag_name"]).count() if tag_num == 1: flash("标签名称已经存在!", "err") return redirect(url_for("admin.tag_add")) tag = Tag(name=data["tag_name"]) db.session.add(tag) db.session.commit() flash("添加标签成功!", "ok") #return redirect(url_for("admin.tag_add")) return redirect(url_for("admin.tag_list", page=1)) #return jsonify(code=200, status=0, message='ok', data={}) return render_template("admin/tag_add.html", form=form)
def edit_tag(tagid): if g.user.is_admin() != 1: flash('This user cannot edit tags!') return redirect(url_for('tags')) page_title = 'Edit tag' tag = Tag.query.get(int(tagid)) form = TagForm(request.form, obj=tag) if request.method == 'POST' and form.validate_on_submit(): # save new data in tag here form.populate_obj(tag) db.session.add(tag) db.session.commit() return redirect(url_for('tags')) return render_template('tag_editor.html', form_action='edit_tag', form=form, page_title=page_title)
def tag_add(): form = TagForm() if form.validate_on_submit(): data = form.data tag = Tag.query.filter_by(name=data["name"]).count() if tag == 1: flash("名称已经存在!", "err") return redirect(url_for('admin.tag_add')) tag = Tag( name=data["name"] ) db.session.add(tag) db.session.commit() flash("添加标签成功! ", 'info') return redirect(url_for("admin.tag_add")) return render_template("admin/tag_add.html", form=form)
def add_tag(): if g.user.is_admin() != 1: flash('This user cannot add tags!') return redirect(url_for('tags')) form = TagForm(request.form) page_title = 'Add new tag' if request.method == 'POST' and form.validate_on_submit(): tag = Tag() form.populate_obj(tag) try: db.session.add(tag) db.session.commit() except IntegrityError, exc: reason = exc.message if reason.find('unique constraint'): flash('Tag name already found in the database') db.session.rollback() return redirect(url_for('add_tag')) flash('Tag saved successfully') return redirect(url_for('tags'))
def add_tag(): if g.user.is_admin() != 1: flash('This user cannot add tags!') return redirect(url_for('tags')) form = TagForm(request.form) page_title = 'Add new tag' if request.method == 'POST' and form.validate_on_submit(): tag = Tag() form.populate_obj(tag) try: db.session.add(tag) db.session.commit() except IntegrityError, exc: reason = exc.message if reason.find('unique constraint'): flash('Tag name already found in the database') db.session.rollback() return redirect(url_for('add_tag')) flash('Tag saved successfully') return redirect(url_for('tags'))
def edit_tag(tag_id=None): form = TagForm() tag = None title = "tag " if tag_id is not None: tag = Tag.query.filter(Tag.id == tag_id).first() if tag is None: tag = Tag() if request.method == 'POST': if form.validate_on_submit(): tag_id = update_tag(form, tag) return redirect(url_for("posts.edit_tag", tag_id=tag_id)) if request.method == "GET": form = TagForm( id=tag.id, tag_name=tag.tag_name, category=tag.category, ) title = tag.tag_name return render_template('edit_tag.html', title=title, form=form)
def tag_edit(id=None): form = TagForm() tag = Tag.query.get_or_404(int(id)) # 如果是请求的话填充信息 if request.method == "GET": form.name.data = tag.name if form.validate_on_submit(): data = form.data tag_count = Tag.query.filter_by(name=data["name"]).count() if tag_count == 1 and Tag.name != data.get("name"): flash("标签已经存在,请重新输入!", "err") return redirect(url_for("admin.tag_edit", id=id)) tag.name = data.get("name") db.session.add(tag) db.session.commit() flash("修改标签成功! ", 'info') return redirect(url_for("admin.tag_add", id=tag.id)) return render_template("admin/tag_edit.html", form=form, tag=tag)
def query(): # Initialise variables // move out of function and make them global? query=None answer=None analysis=None tokens = [] alert=None log=None asks = 444 tag=None tags = Tag(None) all_tags = [] tag_list = [] query_tags =[] remaining_tags = [] existing_query=None title="" question = request.args.get('question', '') tabs = {"results":"", "sparql":"", "meta":"", "talk":""} # Initialise form variables form = QuestionForm() tag_form = TagForm() # Get NLTK DATA PATH for tokenizing analysis if os.path.isdir("C:/Users/edanw_000/My Programming libraries/ntlk/"): NLTK_DATA_PATH = ["C:/Users/edanw_000/My Programming libraries/ntlk/"] elif os.path.isdir("/home/edanweis/webapps/oi3/oi3"): NLTK_DATA_PATH = ["/home/edanweis/webapps/oi3/oi3"] else: answer = "no NLTK found" # Checks if the GET value exists if question: # Analyse question. analysis = quepy.nltktagger.run_nltktagger(urllib.unquote(question), NLTK_DATA_PATH) tokens_length = len(analysis) for child in analysis: token = {} token["token"] = str(child.token) token["POS"] = str(child.pos) token["lema"]= str(child.lemma) token["prob"]= str(child.prob) tokens.append(token) # Answer question quepy_process = functions.quepyProcess(question) # Process the quesiton with Quepy query, answer = quepy_process[0], quepy_process[1] # assign results to variables. existing_query = Query.query.filter_by(sparql_id = query.sparql_id).first() tabs['results'] = "active" # check if this sparql query is in the database if existing_query: query = existing_query existing_query.asks += 1 db.session.commit() else: query = Query( sparql_id = query.sparql_id, sparql_code = query.sparql_code, question = query.question, errors = query.errors, votes = query.votes, tags = query.tags, timestamp = query.timestamp, asks = 1, success = query.success ) db.session.add(query) db.session.commit() title = query.question tag_list = [str(child.name) for child in Query.query.filter_by(sparql_id = query.sparql_id).first().tags] tag_list = [x+" x "+str(Tag.query.filter_by(name=x).first().tag_cnt) for x in tag_list] if tag_list is None: tag_list = [] # Save tags from form if request.method == 'POST': if tag_form.validate_on_submit(): tabs['results'], tabs['talk'] = "", "active" tag_list = [str(child.name) for child in Query.query.filter_by(sparql_id = query.sparql_id).first().tags] tag_list = [x+" x "+str(Tag.query.filter_by(name=x).first().tag_cnt) for x in tag_list] form_tags = tag_form.tag.data.split(",") tag_form.tag.data = '' insert_tags = [tag for tag in form_tags if tag not in tag_list] tag_list += [str(tag) for tag in insert_tags if tag !=""] for child in insert_tags: tag = Tag(child) if len(child) >2 and child != "": existing_query.tags += [tag] db.session.commit() query_tags = [str(child.name) for child in Tag.query.all()] remaining_tags = functions.removeDuplicates([x for x in query_tags if x not in tag_list]) # Log the query for user logs. (this is doubling up with talk page?) log = Log(nlq=query.question, sparql=query.sparql_code, timestamp=query.timestamp, success=query.success, author=g.user) db.session.add(log) db.session.commit() # all_tags = Tag.query.all() # tags = [ tag.name for tag in db.session.query(Tag).order_by(Tag.name) ] # else: # alert = "Try again" return render_template('query.html', all_tags=all_tags, tag_form = tag_form, form = form, query=query, user=g.user, answer=answer, alert=alert, log=log, tag=tag, tag_list = tag_list, query_tags = query_tags, remaining_tags = remaining_tags, existing_query = existing_query, title= title, now=datetime.utcnow(), tab=tabs, analysis=tokens)
def home(): if user.authenticated == False: return redirect(url_for("login")) itemstodisplay = [] ''' add public content to "itemstodisplay" ''' publiccontentitems = con.execute( "SELECT * FROM contentitem WHERE is_pub = 1") for publiccontentitem in publiccontentitems: wasadded = False for i in range(0, len(itemstodisplay)): if publiccontentitem["post_time"] < itemstodisplay[i]["post_time"]: itemstodisplay.insert(i, publiccontentitem) wasadded = True if wasadded == False: itemstodisplay.append(publiccontentitem) ''' now add items from your friend group to "itemstodisplay" ''' groupcontentitems = con.execute( "SELECT * FROM contentitem WHERE email_post IN " "(SELECT owner_email FROM belong WHERE email = %s);", [user.getEmail()]) for groupcontentitem in groupcontentitems: wasadded = False for i in range(0, len(itemstodisplay)): if groupcontentitem["post_time"] < itemstodisplay[i]["post_time"]: itemstodisplay.insert(i, groupcontentitem) wasadded = True if wasadded == False: itemstodisplay.append(groupcontentitem) ''' now handle tagged people ''' tags = {} for itemtodisplay in itemstodisplay: tagged = con.execute( f"SELECT email_tagged FROM tag WHERE status = 'True' AND item_id = {itemtodisplay['item_id']};" ) tags[itemtodisplay["item_id"]] = [] for taggee_email in tagged: tags[itemtodisplay["item_id"]].append(taggee_email) ''' now ratings ''' ratings = {} for itemtodisplay in itemstodisplay: rating = con.execute( f"SELECT emoji FROM rate WHERE item_id = {itemtodisplay['item_id']};" ) ratings[itemtodisplay["item_id"]] = [] for r in rating: ratings[itemtodisplay["item_id"]].append(r) user.setitemsicansee(itemstodisplay) form = TagForm(request.form) if request.method == "POST" and form.validate_on_submit(): email_taggee = request.form["email_taggee"] item_id = request.form["item_id"] if email_taggee == user.getEmail(): con.execute( f"INSERT INTO tag VALUES ('{email_taggee}', '{email_taggee}', {item_id}, 'True', '2016-07-07 00:01:01');" ) else: con.execute( f"INSERT INTO tag VALUES ('{email_taggee}', '{user.getEmail()}', {item_id}, 'False', '2016-07-07 00:01:01');" ) return render_template('home.html', itemstodisplay=itemstodisplay, tags=tags, ratings=ratings, form=form)