def tagging(): if not users.is_admin(): return render_template("forbidden.html", message="Sinulla ei ole oikeutta nähdä tätä sivua") restaurants_list = restaurants.get_list() tags_list = tags.get_tags() if request.method == "GET": return render_template("tags.html", tags=tags_list, restaurants=restaurants_list) if request.method == "POST": written_tag = request.form["tag"] list_tag = request.form["existing_tag"] if is_empty(written_tag) and is_empty(list_tag): return render_template("tags.html", errormessage="Et lisännyt tägiä", tags=tags_list, restaurants=restaurants_list) elif not is_empty(written_tag) and not is_empty(list_tag): return render_template("tags.html", errormessage="Lisää yksi tägi kerrallaan", tags=tags_list, restaurants=restaurants_list) else: tag_to_be_added = "" if is_empty(written_tag): tag_to_be_added = list_tag else: tag_to_be_added = written_tag if len(tag_to_be_added) > 50: return render_template("tags.html", errormessage="Tägi on liian pitkä. Sen tulee olla alle 50 merkkiä", tags=tags_list, restaurants=restaurants_list) if "selected_restaurants" in request.form: restaurants_to_be_added = request.form.getlist("selected_restaurants") check_csfr(request.form["csrf_token"], users.get_csrf()) tags.add_tags(restaurants_to_be_added, tag_to_be_added) else: return render_template("tags.html", errormessage="Et antanut ravintoloita", tags=tags_list, restaurants=restaurants_list) return redirect("/")
def add_tags_to_case(): """Adds a tag to a specific case""" case_id = request.form.get('case_id') tags = request.form.get('new_tags') # #nix any spaces # tags = tags.replace(" ", "") #split up the emails tags = tags.split(", ") for tag in tags: add_tags(tag, case_id) return "Tags were added successfully"
def test_add_dry_run(self): posts = [os.path.join('posts', post) for post in os.listdir('posts')] tags = 'test_nikola' new_tags = add_tags(self._site, tags, posts, dry_run=True) new_parsed_tags = self._parse_new_tags(posts[0]) self.assertTrue('test_nikola' in new_tags) self.assertEquals(set(new_parsed_tags), set(DEMO_TAGS))
def test_add(self): posts = [os.path.join('posts', post) for post in os.listdir('posts')] tags = 'test_nikola' new_tags = add_tags(self._site, tags, posts) new_parsed_tags = self._parse_new_tags(posts[0]) self.assertTrue('test_nikola' in new_tags[0]) self.assertEqual(set(new_tags[0]), set(new_parsed_tags))
def test_add_dry_run(self): posts = [os.path.join('posts', post) for post in os.listdir('posts')] tags = 'test_nikola' new_tags = add_tags(self._site, tags, posts, dry_run=True) new_parsed_tags = self._parse_new_tags(posts[0]) self.assertTrue('test_nikola' in new_tags[0]) self.assertEquals(set(new_parsed_tags), set(DEMO_TAGS))
def classify_questions(questions): tags.add_tags(questions) psets.add_psets(questions)