def createRecord(self, url): # Lookup if exists reverse = self.lookupUrl(url) if reverse: # Return id if exists return reverse else: # Create if not exists, or generate another id newid = utils.generateId(self.deflen) while not self.r.setnx(newid, url): newid = utils.generateId(self.deflen) # Create reverse link self.rr.set(utils.createUrlHash(url), newid) # Return the new id return newid
def ajax_create_dto(request): if request.method == "POST" and request.is_ajax(): dto = DTO( dto_id=generateId(DTO, request.session['branch']), fe=User.objects.get(pk=int(request.POST['fe'])), vehicle=Vehicle.objects.get(pk=int(request.POST['vehicle'])), branch=Branch.objects.get(pk=int(request.session['branch'])) ) dto.save() awbs = list(set(json.loads(request.POST['awbs']))) for awb in awbs: if AWB_Status.objects.get(awb=int(awb)).manifest.category == 'RL': AWB_Status.objects.filter(awb=int(awb)).update(current_dto=dto, status='DTO') awb_history = AWB_History( awb=AWB.objects.get(pk=int(awb)), dto=dto ) awb_history.save() # else: # AWB_Status.objects.filter(awb=int(awb), status__in=['CAN', 'ITR']).update(current_dto=dto, # status='DPR') # awb_history = AWB_History( # awb=AWB.objects.get(pk=int(awb)), # dto=dto # ) # awb_history.save() return HttpResponse(True) else: return HttpResponse(False)
def ajax_create_mts(request): if request.method == "POST" and request.is_ajax(): mts = MTS( mts_id=generateId(MTS, request.session['branch'], request.POST['to_branch']), from_branch=Branch.objects.get(pk=int(request.session['branch'])), to_branch=Branch.objects.get(pk=int(request.POST['to_branch'])), type=str(request.POST['type']) ) mts.save() tbs = json.loads(request.POST['tbs']) for tb in tbs: tb_history = TB_History( tb=TB.objects.get(pk=int(tb)), mts=mts ) tb_history.save() awb_status = AWB_Status.objects.filter(current_tb_id=int(tb), status__in=['TB', 'TBD', 'MTS', 'MTD']) awb_status.update(current_mts=mts, status='MTS') for status in awb_status: awb_history = AWB_History( awb=status.awb, mts=mts ) awb_history.save() return HttpResponse(True) else: return HttpResponse(False)
def ajax_create_tb(request): if request.method == "POST" and request.is_ajax(): tb = TB( tb_id=generateId(TB, request.session['branch'], request.POST['delivery_branch']), origin_branch=Branch.objects.get(pk=request.session['branch']), delivery_branch=Branch.objects.get(pk=request.POST['delivery_branch']), #type=request.POST['type'] ) tb.save() tb_history = TB_History( tb=tb, branch=Branch.objects.get(pk=request.session['branch']) ) tb_history.save() awbs = json.loads(request.POST['awbs']) for awb in awbs: awb_status = AWB_Status.objects.get(awb=int(awb)) if awb_status.status == 'CAN' and awb_status.manifest.category == 'FL': AWB_Status.objects.filter(awb=int(awb)).update(current_tb=tb, status='ITR') awb_history = AWB_History( awb=AWB.objects.get(pk=int(awb)), tb=tb ) awb_history.save() else: AWB_Status.objects.filter(awb=int(awb)).update(current_tb=tb, status='TB') awb_history = AWB_History( awb=AWB.objects.get(pk=int(awb)), tb=tb ) awb_history.save() return HttpResponse(True) else: return HttpResponse(False)
def manualCreate(username, password_hash): u = User() u.username = username u.email = None u.userId = utils.generateId() u.password_hash = password_hash return u
def tq_get(self): cats = tq.keys() cat = random.choice(cats) question = random.choice(tq[cat]) answer_hash = utils.generateId(size=8) memcache.set('ans_' + answer_hash, question['a']) question['category'] = cat question['answer_hash'] = answer_hash self.render('trivia.html', **question)
def manualCreate(white_player, black_player): """constructor for creation from user-input values.""" g = ChessGame() g.id = utils.generateId() g.white_player = white_player g.black_player = black_player g.boardstate = json.loads(open('initialLayout.json', 'r').read()) g.completed = False g.time_started = datetime.now() g.last_move = g.time_started g.time_ended = None g.player_turn = white_player g.winner = None return g
def manualCreate(x_player, o_player): """constructor for creation from user-input values.""" g = TttGame() g.id = utils.generateId() g.x_player = x_player g.o_player = o_player g.boardstate = ['', '', '', '', '', '', '', '', ''] # 9 empty spaces g.completed = False g.time_started = datetime.now() g.last_move = g.time_started g.time_ended = None, g.player_turn = random.choice([x_player, o_player]) g.winner = None return g
def signup(): username = request.form['username'] email = request.form['email'] password = request.form['password'] password_repeat = request.form['password_repeat'] if(password != password_repeat): return ("Your passwords did not match.") usernameTaken = pgdb.userExists(username) if(usernameTaken): return("That username is taken! sorry fam") password_hash = generateHash(password) userid = str(generateId()) pgdb.createUser(username, password_hash, email, userid) pgdb.createStat(userid) session['loggedIn'] = True session['username'] = request.form['username'] return redirect('/')
def payment_update(): postData = request.json rowInsert = prepareData(postData) print 'INSERT IT', rowInsert #Check if ref_id already exist row = BillPayment.query.filter_by(ref_id=rowInsert['ref_id']).first() if row: return jsonify({ "status": "SUCCESS", "data": { "ackID": row.ack_id } }), 202 else: key = generateId() transactionRow = BillPayment(date=rowInsert['date'], amount_paid=rowInsert['amount_paid'], id=rowInsert['id'], ref_id=rowInsert['ref_id'], ack_id=key) db.session.add(transactionRow) db.session.commit() return jsonify({"status": "SUCCESS", "data": {"ackID": key}}), 201
def ajax_create_drs(request): if request.method == "POST" and request.is_ajax(): if 'branch' not in request.session: return HttpResponse('Please select Branch') drs = DRS( drs_id=generateId(DRS, request.session['branch']), fe=User.objects.get(pk=int(request.POST['fe'])), vehicle=Vehicle.objects.get(pk=int(request.POST['vehicle'])), opening_km=request.POST['opening_km'], branch=Branch.objects.get(pk=int(request.session['branch'])) ) drs.save() fl = list(set(json.loads(request.POST['fl']))) rl = list(set(json.loads(request.POST['rl']))) for awb in fl: awb_obj = AWB.objects.get(pk=int(awb)) if awb_obj.category == 'REV': AWB_Status.objects.filter(awb=int(awb)).update(current_drs=drs, status='PP') else: AWB_Status.objects.filter(awb=int(awb)).update(current_drs=drs, status='DRS') awb_history = AWB_History( awb=AWB.objects.get(pk=int(awb)), drs=drs ) awb_history.save() for awb in rl: AWB_Status.objects.filter(awb=int(awb)).update(current_drs=drs, status='PP') awb_history = AWB_History( awb=AWB.objects.get(pk=int(awb)), drs=drs ) awb_history.save() return HttpResponse(True) else: return HttpResponse(False)
def open(self): self.socketId = "socket" + str(utils.generateId())[:8] print("statSocket opened:", str(self.socketId))
def makeContentInfo(self, checkin_json, content, url=None, text=None, photoId=None, reply=False, post=False): assert (reply ^ post), "Must pass exactly one of reply or post" assert (text or photoId) # Avoid posting duplicate content. request = ContentInfo.all() request = request.filter('checkin_id = ', checkin_json['id']) existing_contents = request.fetch(10) for existing_content in existing_contents: # Check that they're the same type of content if existing_content.reply_id and not reply: continue if existing_content.post_id and not post: continue # Check if the content payload is the same if existing_content.content == content: logging.info('Avoided posting duplicate content %s' % content) return existing_content content_id = utils.generateId() checkin_id = checkin_json['id'] content_info = ContentInfo() content_info.content_id = content_id content_info.fs_id = checkin_json['user']['id'] content_info.checkin_id = checkin_id content_info.venue_id = checkin_json['venue']['id'] content_info.content = content access_token = self.fetchAccessToken(content_info.fs_id) client = utils.makeFoursquareClient(access_token) if not url: params = {} else: params = {'contentId' : content_id, 'url' : url} if text: params['text'] = text.encode('utf-8') if photoId: params['photoId'] = photoId logging.info('creating content with params=%s' % params) if post: if CONFIG['local_dev']: content_info.post_id = utils.generateId() else: response_json = client.checkins.addpost(checkin_id, params) content_info.post_id = response_json['post']['id'] elif reply: if CONFIG['local_dev']: content_info.reply_id = utils.generateId() else: response_json = client.checkins.reply(checkin_id, params) reply_id = None if 'replies' in response_json: reply_id = response_json['replies']['id'] elif 'reply' in response_json: # Right now we return "replies" but we should probably return "reply" # adding this so I don't have to do it later in the event we rename reply_id = response_json['reply']['id'] else: logging.error("Could not find reply id in /checkins/reply response: %s" % response_json) content_info.reply_id = reply_id content_info.put() return content_info
def makeContentInfo(self, checkin_json, content, url=None, text=None, photoId=None, reply=False, post=False): assert (reply ^ post), "Must pass exactly one of reply or post" assert (text or photoId) # Avoid posting duplicate content. request = ContentInfo.all() request = request.filter('checkin_id = ', checkin_json['id']) existing_contents = request.fetch(10) for existing_content in existing_contents: # Check that they're the same type of content if existing_content.reply_id and not reply: continue if existing_content.post_id and not post: continue # Check if the content payload is the same if existing_content.content == content: logging.info('Avoided posting duplicate content %s' % content) return existing_content content_id = utils.generateId() checkin_id = checkin_json['id'] content_info = ContentInfo() content_info.content_id = content_id content_info.fs_id = checkin_json['user']['id'] content_info.checkin_id = checkin_id content_info.venue_id = checkin_json['venue']['id'] content_info.content = content if not url: url = self.generateContentUrl(content_id) access_token = self.fetchAccessToken(content_info.fs_id) client = utils.makeFoursquareClient(access_token) params = {'contentId': content_id, 'url': url} if text: params['text'] = text if photoId: params['photoId'] = photoId logging.info('creating content with params=%s' % params) if post: if CONFIG['local_dev']: content_info.post_id = utils.generateId() else: response_json = client.checkins.addpost(checkin_id, params) content_info.post_id = response_json['post']['id'] elif reply: if CONFIG['local_dev']: content_info.reply_id = utils.generateId() else: response_json = client.checkins.reply(checkin_id, params) reply_id = None if 'replies' in response_json: reply_id = response_json['replies']['id'] elif 'reply' in response_json: # Right now we return "replies" but we should probably return "reply" # adding this so I don't have to do it later in the event we rename reply_id = response_json['reply']['id'] else: logging.error( "Could not find reply id in /checkins/reply response: %s" % response_json) content_info.reply_id = reply_id content_info.put() return content_info