def process(self, query, debug=False): results = Query(query).reduce(debug) if debug: print(results) fields = [ "title:(%s)^2" % results["reduced"], "overview:%s" % results["reduced"] ] # fields = [field +": "+ results["reduced"] for field in self.fields["main"]] query = "(" + " OR ".join(fields) + ")" if results["people"]: fields = [ field + ": " + Query.require(results["people"]) for field in self.fields["people"] ] subQuery = "(" + " OR ".join(fields) + ")" query += " OR " + subQuery if results["genres"]: fields = [ "genres.name: " + Query.require(genre) for genre in results["genres"] ] subQuery = "(" + " AND ".join(fields) + ")" query += " AND " + subQuery return query, dict(results["sort"])
def admin_page(): forms = [AddCategoriesForm(), AddManufacturerForm(), AddProductForm()] if request.method == "POST": if forms[0].validate(): img_name = None if request.files: image = request.files["image"] if image and allowed_file(image.filename): image_name = secure_filename(image.filename) image.save( os.path.join( webapp.config["UPLOAD_FOLDER"] + "category_img", image_name)) img_name = image_name data = [ forms[0].Type.data, forms[0].title.data, forms[0].parent_cat.data, forms[0].description.data, img_name, forms[0].status.data, ] Query.CategoryQuery().save_category(data) return render_template( "admin_page.html", title="Mr. Med Admin", forms=forms, landing=".cat_stuff", categories=Query.CategoryQuery().get_all_categories(), ) elif forms[1].validate(): return render_template( "admin_page.html", title="Mr. Med Admin", forms=forms, landing=".manu_stuff", ) elif forms[2].validate(): return render_template( "admin_page.html", title="Mr. Med Admin", forms=forms, landing=".prod_stuff", ) # else: # return render_template("admin_page.html", title="Mr. Med Admin", forms=forms, landing=".add_cat") return render_template( "admin_page.html", title="Mr. Med Admin", forms=forms, landing=".dash_stuff", categories=Query.CategoryQuery().get_all_categories(), )
def login_page(): if current_user.is_authenticated: return redirect(url_for("homepage")) form = LoginForm() if form.validate_on_submit(): if Query.AdminQuery().check_user(form.username.data, form.password.data): Query.AdminQuery().login(form.username.data, form.remember_me.data) else: flash("Username or password doesn't exists.") return redirect(url_for("login_page")) next_page = request.args.get("next") if not next_page or url_parse(next_page).netloc != "": next_page = url_for("homepage") return redirect(next_page) return render_template("login_page.html", title="Login", form=form)
def index(): offsets_1 = [ "'col s3 m3 l3 offset-l2 offset-m2 offset-s2'", "'col s3 m3 l3'", "'col s1 m1 l1'" ] quality = ["1080p", "720p", "480p"] a = Query() headers = a.header_names() pics = a.get_pics(10) anime_names = a.pop_outs() a.no_new_anime(anime_names) schedule = a.schedule() return render_template('index.html', pics=pics, offsets_1=offsets_1, quality=quality, headers=headers, anime_names=anime_names, schedule=schedule)
import pytest import app from app.query import Query from app.config import TestConfig from app.es import ElasticSearch elasticsearch = ElasticSearch(TestConfig) query = Query(elasticsearch) def test_search_lower(): assert (search("emc6") == {"EMC6"}) def test_search_upper(): assert (search("EMC6") == {"EMC6"}) def test_search_mixed(): assert (search("EmC6") == {"EMC6"}) def test_search_empty(): assert (search("") == set()) def test_search_dashes(): assert (search("kccat333") == {"KCCAT333"}) assert (search("kcc-at333") == {"KCC-AT333"}) assert (search("TF") == {"TF"})
def _create_db(self): q = Query() funcs = [func for func in dir(q) if re.search('^create_', func)] for func in funcs: self.cursor.execute(getattr(q, func)()) self.connection.commit()
def tx2csv(self): self.w.write_txs(self.tgt, self.r.get(Query().get_txs()))
def block2csv(self): self.w.write_txs(self.tgt, self.r.get(Query().get_blocks()))
def egsOracle2csv(self): self.w.write_txs(self.tgt, self.r.get(Query().get_egs_oracle()))
def oracle2csv(self): self.w.write_txs(self.tgt, self.r.get(Query().get_oracles()))