def match(data): matched_user = User.find_closest_rating(data['choice'], data['rating'], data['username']) if matched_user.is_authenticated: print("He is online!") new_question = Question(data['question'], "", current_user.name, data['choice']) new_question.save() for value in data['tags']: if value is not None: print(value) new_tag = Tag(value) new_tag.save() new_question_tag = Question_tag(new_question.id, new_tag.id) new_question_tag.save() chat_id = str(uuid.uuid1()) print("NEW CHAT ID IS {}".format(chat_id)) print("You are {}".format(matched_user.name)) print("I am {}".format(current_user.name)) emit('question_match', { 'question': data['question'], 'user_id': current_user.id, 'matched_user_id': matched_user.id, 'chat_id': chat_id }, room=matched_user.room_id) else: flash('No matches available. Try again!') print("No luck today!")
def get(self, tags=""): cellar_id = None cellar = Cellar() res_web = cellar.GetWebCellar() if "success" in res_web: cellar_id = res_web["success"] page = int(self.get_argument("page", "1")) ajax = int(self.get_argument("ajax", 0)) tags = tags.replace("_", " ").lower() tags_arr = tags.split(",") items = 0 tallas = [] tag = Tag() res = tag.GetItemsByTags(cellar_id, tags_arr) if "success" in res: items = int(res["success"]) res = tag.GetProductsByTags(cellar_id, tags_arr, page, 16) tags_visibles = tag.ListVisibleTags(tags_arr) if "success" in tags_visibles: tags = tags_visibles["success"] product = Product() tallas_res = product.getAllSizes() if "success" in tallas_res: tallas = tallas_res["success"] if "success" in res: if ajax == 0: self.render("store/index.html", data=res["success"], items=items, page=page, tags=tags, tags_arr=tags_arr, tag=",".join(tags_arr), tallas=tallas) else: self.render("store/ajax_productos.html", data=res["success"], items=items, tag=",".join(tags_arr), page=page) else: self.render("beauty_error.html", message=res["error"])
def tag_create(): json = request.get_json() tag = json['name'] url = json['url'] newTag = Tag(tag=tag, url=url) newTag = ctrTag.create(newTag) if newTag is None: return jsonify({}), 404 else: return jsonify(newTag.serialize()), 201
def testCreate( self ): Tag( tag="ios" ).put() Tag( tag="perl" ).put() Tag( tag="javascript" ).put() self.assertEqual( Tag.count(), 3 ) Tag( tag="ruby" ).put() self.assertNotEqual( Tag.count(), 3 ) self.assertEqual( Tag.count(), 4 )
def post(self): cellar = Cellar() res_web = cellar.GetWebCellar() cellar_id = None if "success" in res_web: cellar_id = res_web["success"] product = Product() page = int(self.get_argument("page", "1")) ajax = int(self.get_argument("ajax", 0)) lista = product.GetList(cellar_id, page, 16) items = 0 tags = {} tallas = [] response = product.GetItems(cellar_id) if "success" in response: items = response["success"] tag = Tag() tags_visibles = tag.ListVisibleTags() if "success" in tags_visibles: tags = tags_visibles["success"] tallas_res = product.getAllSizes() if "success" in tallas_res: tallas = tallas_res["success"] banners = {} banners["nuevo"] = self.jsonToObject(self.get_argument("nuevo", "")) banners["sale"] = self.jsonToObject(self.get_argument("sale", "")) banners["tienda"] = self.jsonToObject(self.get_argument("tienda", "")) banners["background"] = self.jsonToObject( self.get_argument("background", "")) tag = self.get_argument("tag", "") self.render("preview/index.html", data=lista, items=items, page=page, tags=tags, tags_arr=[tag], tag=tag, tallas=tallas, banners=banners)
def post(self, tag_id): session = getSession() root = ET.fromstring(self.request.body) name = root.attrib['name'] pt = session.query(Tag).filter(Tag.id == int(tag_id)).one() if not self.get_mpdao().own(self.get_secure_cookie('username'), pt.mpid): raise tornado.web.HTTPError(401) t = Tag(name.encode('utf-8'), pt.mpid) t.parent = pt session.add(t) session.commit() self.set_header('Content-Type', 'text/xml; charset=utf-8') self.write('<tag id="%s" name="%s"/>' % (tag_id, name))
def get(self): cellar = Cellar() res_web = cellar.GetWebCellar() cellar_id = None if "success" in res_web: cellar_id = res_web["success"] product = Product() page = int(self.get_argument("page", "1")) ajax = int(self.get_argument("ajax", 0)) lista = product.GetList(cellar_id, page, 16) items = 0 tags = {} tallas = [] response = product.GetItems(cellar_id) if "success" in response: items = response["success"] tag = Tag() tags_visibles = tag.ListVisibleTags() if "success" in tags_visibles: tags = tags_visibles["success"] tallas_res = product.getAllSizes() if "success" in tallas_res: tallas = tallas_res["success"] if ajax == 0: self.render("store/index.html", data=lista, items=items, page=page, tags=tags, tags_arr=None, tag="tienda", tallas=tallas) else: self.render("store/ajax_productos.html", data=lista, items=items, page=page, tags=tags, tags_arr=None, tag="tienda", tallas=tallas)
def get(self, zsite_tag_id, n=1): tag = ZsiteTag.mc_get(zsite_tag_id) zsite_id = self.zsite_id user_id = self.current_user_id cid = self.cid is_self = zsite_id == user_id n = int(n) total = zsite_tag_cid_count(zsite_tag_id, cid) page, limit, offset = page_limit_offset( '/tag/%s'%zsite_tag_id + self.page_template, total, n, PAGE_LIMIT ) if n != 1 and offset >= total: return self.redirect(self.page_template[:-3]) po_list = Po.mc_get_list(po_id_list_by_zsite_tag_id_cid(zsite_tag_id, cid, limit, offset)) self.render( cid=cid, is_self=is_self, total=total, li=po_list, page=page, tag_name=Tag.get(tag.tag_id), back_a='/tag/%s'%zsite_tag_id )
def getList(self, pagenum, limit, name, search, adi_tag=None): self.connect() listTags = [] try: if (limit > self.__maxLimit): limit = self.__maxLimit if (limit < 1): limit = 1 page = (pagenum - 1) * limit query_a = "" if adi_tag is not None and adi_tag.getId() is not None: query_a = "AND adi_tag = {0}".format(adi_tag.getId()) query_b = "" if search == "unassociated": query_b = "AND adi_tag IS NULL" elif search == "associated": query_b = "AND adi_tag IS NOT NULL" query = "SELECT * FROM Tag WHERE tag LIKE \'{0}\' {1} {2} LIMIT {3},{4}".format( "%" + name + "%", query_a, query_b, page, limit) self.cursor.execute(query) results = self.cursor.fetchall() for row in results: tag = Tag(row=row) listTags.append(tag) except Error as err: print(err) self.disconnect() return listTags
def publish_article(cls, user_name, id, title, tags, is_published): article = Article.select().get(id) article.title = title article.is_published = is_published tags = list(set(tags)) tag_existed = Tag.select().filter(Tag.label.in_(tags)).all() for t in tag_existed: if t.user_name is None: t.user_name = user_name t.update() for t in list( set(tags).difference(set([tag.label for tag in tag_existed]))): Tag(user_name=user_name, label=t).insert() article.tags = json.dumps(tags) article.update() return True
def get_tags(self): from model.tagtoevent import TagToEvent from model.tag import Tag query = Tag.select(Tag.name)\ .join(TagToEvent, on=(Tag.id == TagToEvent.tag_id))\ .where(TagToEvent.event_id == self.id) return [tag.name for tag in query]
def init_db(): session = Session() file = open('example.json', 'r', encoding='utf-8') data = json.load(file) file.close() for user in data['Users']: item = User(username=user['username']) session.add(item) for section in data['Sections']: item = Section(title=section['title']) session.add(item) for post in data['Posts']: item = Post(title=post['title'], section_id=post['section_id'], user_id=post['user_id'], description=post['description']) session.add(item) for tag in data['Tags']: item = Tag(name=tag['name'], post_id=tag['post_id']) session.add(item) session.commit() session.close()
def _crete_new_tag(self, tag=None): assert tag is not None if tag not in self._tags_cache: new_tag = Tag.create(name=tag, description='') self._tags_cache[tag] = new_tag else: new_tag = self._tags_cache[tag] return new_tag
def add_tag(self, tag_name): from model.tag import Tag from model.tagtoevent import TagToEvent if any(tte.tag.name == tag_name for tte in self.tags): return tag = Tag.get_tag(tag_name) tag_to_event = TagToEvent(tag = tag, event = self) tag_to_event.save(force_insert=True)
def get_initial_tag_list(number=10): tags = Tag.objects(recommended_ranking=TagRecommendRanking.STAR5.value) if len(tags) <= 0: tags = [] else: tags = list(map(lambda t: t.name, tags)) current_app.logger.info('get tag list:') current_app.logger.info(tags) return tags
def entry_list_by_tag(tag): result = [] tag_id = Tag.id_by_value(tag) if tag_id: r_li = db.query("select entry_id from Relationship where tag_id=%s order by id", tag_id) id_li = [r.entry_id for r in r_li] for id in id_li: entry = db.get('select * from Entry where id=%s', id) result.append(entry) return map(Entry, result)
def get_days(): global graph filter_include = request.args.get('include') == "true" tag_ids = [ Tag.get_tag(tag).id for tag in json.loads(request.args.get('tags')) ] if graph is None or graph.outdated(filter_include, tag_ids): graph = CalendarGraph(filter_include, tag_ids) return jsonify(graph.to_dict())
def get_tags(app_id, name): url_tags = 'http://store.steampowered.com/app/%s' % (app_id) response_tags = urlfetch.fetch(url_tags, deadline=60).content tags = [] glance_tags = bs(response_tags).find("div", {"class": "glance_tags"}) if glance_tags: tag_elements = glance_tags.findAll("a", {"class": "app_tag"}) for tag_element in tag_elements: tag = tag_element.string.strip() tags.append(tag) Tag(key_name=tag).put() Game(key_name=str(app_id), name=name, tags=tags).put()
def post(self, mpid_str): mpid = int(mpid_str) if not self.get_mpdao().own(self.get_secure_cookie('username'), mpid): raise tornado.web.HTTPError(401) root = ET.fromstring(self.request.body) name = root.attrib['name'] session = getSession() t = Tag(name.encode('utf-8'), mpid) session.add(t) session.commit() self.set_header('Content-Type', 'text/xml; charset=utf-8') self.write('<tag id="%d" name="%s"/>' % (t.id, name))
def getById(self, id): self.connect() tag = None try: query = "SELECT * FROM Tag WHERE id = {0}".format(id) self.cursor.execute(query) row = self.cursor.fetchone() if row is not None: tag = Tag(row=row) except Error as err: print(err) self.disconnect() return tag
def get(self, id, n=1): tag = ZsiteTag.mc_get(id) if tag is None: return self.redirect('/') if tag.zsite_id != self.zsite_id: tag_zsite = Zsite.mc_get(tag.zsite_id) return self.redirect('%s/tag/%s'%(tag_zsite.link, id)) self.render( tag_name=Tag.get(tag.tag_id), zsite_tag_id=id )
def getByTagName(self, name): self.connect() tag = None try: query = ("SELECT * " "FROM Tag " "WHERE tag = %(name)s") data = {'name': name} self.cursor.execute(query, data) row = self.cursor.fetchone() if row is not None: tag = Tag(row=row) except Error as err: print(err) self.disconnect() return tag
def add(cls, user_name, label): exist = Tag.select().filter(Tag.user_name == user_name, Tag.label == label).first() is None if not exist: raise ServerException(f'{label} 已存在') tag = Tag(user_name=user_name, label=label) tag.insert() return Tag.select().filter(Tag.user_name == user_name, Tag.label == label).one().id
def get_events(): time = request.args.get('time') before = request.args.get('before') == 'true' try: date = datetime.datetime.fromtimestamp(float(time) / 1000.0) except OSError: date = datetime.datetime.min filter_include = request.args.get('include') == "true" tag_ids = [ Tag.get_tag(tag).id for tag in json.loads(request.args.get('tags')) ] filter_query = fn.EXISTS(TagToEvent.select().where( TagToEvent.tag.in_(tag_ids) & (TagToEvent.event == Event.id))) if not filter_include: filter_query = ~filter_query n = 100 if any(tag_ids): if before: query = Event.select().where((Event.time < date) & filter_query).order_by( Event.time.desc())[:n] else: query = Event.select().where((Event.time > date) & filter_query).order_by( Event.time)[:n] else: if before: query = Event.select().where(Event.time < date).order_by( Event.time.desc())[:n] else: query = Event.select().where(Event.time > date).order_by( Event.time)[:n] result = [to_dict(event) for event in query] if before: result = reversed(result) return jsonify(list(result))
def get(self, category, name, color): category = category.replace("_", "&") name = name.replace("_", "&") color = color.replace("_", "&") tag = self.get_argument("tag", "") id_bodega = cellar_id cellar = Cellar() res_cellar = cellar.GetWebCellar() if "success" in res_cellar: id_bodega = res_cellar["success"] # sku = self.get_argument("sku","") prod = Product() response_obj = prod.GetProductCatNameColor(category, name, color) if "error" in response_obj: self.render("beauty_error.html", message="Producto no encontrado, error:{}".format( response_obj["error"])) else: tallas_disponibles = [] prod.size_id = sorted(prod.size_id, reverse=True) for s in prod.size_id: kardex = Kardex() response_obj = kardex.FindKardex(prod.sku, id_bodega, s) if "success" in response_obj: # print kardex.balance_units if kardex.balance_units > 0: _size = Size() _size.id = s res_name = _size.initById() if "success" in res_name: tallas_disponibles.append({ "id": _size.id, "name": _size.name, "stock": kardex.balance_units }) elif debugMode: print res_name["error"] elif debugMode: print response_obj["error"] prod.size = tallas_disponibles[::-1] vote = Vote() res = vote.GetVotes(prod.id) votos = 0 prod_name = prod.name try: prod_name = name.split("&")[0] except: pass # print "prod_name:{}".format(prod_name) combinaciones = prod.GetCombinations(id_bodega, prod_name) tag = Tag() res_tags = tag.GetTagsByProductId(prod.id) if "success" in res_tags: relacionados = prod.GetRandom(id_bodega, res_tags["success"]) if "success" in res: votos = res["success"] self.render("store/detalle-producto.html", data=prod, combinations=combinaciones, related=relacionados, votos=votos, tag=tag)
def delete(cls, tag_id): tag = Tag.select().get(tag_id) if tag is None: raise ServerException('tag不存在') tag.delete() return True
def init_tag(): for id, name in TAG: Tag.set(id, name)
def testBasic( self ): a = Tag( tag="ios" ) self.isNotNone( a ) self.assertEqual( "ios", a.tag ) self.assertEqual( Tag.count(), 0 )
def list_tags(): result = [] for tag in Tag.all(): result.append(tag.to_dict()) return jsonify(result), 201
def user_tag(cls, user_name): tags = Tag.select().filter(Tag.user_name == user_name).all() return [tag.get_json() for tag in tags]
def testFetch( self ): Tag( tag="ruby" ).put() Tag( tag="javascript" ).put() Tag( tag="perl" ).put() self.assertEqual( Tag.count(), 3 ) self.assertEqual( len( Tag.all_tags() ), 3 )
def _fill_cache_with_existing_tags(self): tag = Tag() tags = tag.select() for tg in tags: self._tags_cache[tg.name] = tg