def get(self): key = self.request.get("Key") aKey = ndb.Key(urlsafe=key) anArticle = aKey.get() data = {} filters = [] user = getUser() if user: data['LoggedIn'] = True q1 = Tag.query() q1 = q1.filter(Tag.user == user.user_id()) for aFilter in q1: filters.append(aFilter.json()) theProxy = getTags(user, anArticle) if theProxy: if theProxy.score == -1: data['Vote'] = {'Scan': 'No Tag', 'ScanKey': 'Unknown'} else: data['Vote'] = theProxy.json() else: data['Vote'] = {'Scan': 'Unknown', 'ScanKey': 'Unknown'} else: data['LoggedIn'] = False data['Post'] = anArticle.json() url = users.create_logout_url("VoteData?Key=" + key) data['Logout'] = url data['Filter'] = filters template = JINJA_ENVIRONMENT.get_template('Vote.html') self.response.out.write(template.render(data))
def post(self): key = self.request.get("Key") tag = self.request.get("Tag") aKey = ndb.Key(urlsafe=key) anArticle = aKey.get() user = getUser() if user: q1 = Tag.query() q1 = q1.filter(Tag.user == user.user_id()) q1 = q1.filter(Tag.scan == tag) aTag = q1.get() if not aTag: aTag = Tag(scan=str(tag), scanKey=str(tag), user=user.user_id()) aTag.put() self.response.out.write('Create Tag')
def post(self): key = self.request.get("Key") tag = self.request.get("Tag") aKey = ndb.Key(urlsafe=key) anArticle = aKey.get() user = getUser() if user: q1 = Tag.query() q1 = q1.filter(Tag.scan == tag) q1 = q1.filter(Tag.user == user.user_id()) aTag = q1.get() if not aTag: aTag = Tag(scan=str(tag), scanKey=str(tag), user=user.user_id()) aTag.put() q1 = ProxyTag.query() q1 = q1.filter(ProxyTag.tag == aTag.key) q1 = q1.filter(ProxyTag.article == anArticle.key) q1 = q1.filter(ProxyTag.user == user.user_id()) aProxy = q1.get() if aProxy: if aProxy.score == -1: self.response.out.write('Already Updated') return aProxy.key.delete() aProxy = ProxyTag(tag=aTag.key, article=anArticle.key, user=user.user_id(), score=-1).put() queue = taskqueue.Queue(name='default') task = taskqueue.Task(url='/RemoveFromFilter', target='worker', params={ 'article': anArticle.key.urlsafe(), 'tag': aTag.scan, 'user': user.user_id() }) rpc = queue.add_async(task) # Wait for the rpc to complete and return the queued task. task = rpc.get_result() self.response.out.write('Updated') else: self.response.out.write('Not Present')