def test_case_title(self): f = "%s-%s" book_num = self.fake.pyint() register = None case = Case( book_num=book_num, register=register, ) self.assertEqual(case.title(f), f % ('', book_num)) book_num = self.fake.pyint() register = Register( fund=self.fake.pystr()[:5], register=self.fake.pyint(), ) case = Case( book_num=book_num, register=register, ) self.assertEqual(case.title(f), f % (register, book_num)) book_num = None register = Register( fund=self.fake.pystr()[:5], register=self.fake.pyint(), ) case = Case( book_num=book_num, register=register, ) self.assertEqual(case.title(f), f % (register, 1))
def parse_register(r): name = r.name.replace('%s', '').replace('[]', '').strip('_') dim = r.dim if 'dim' in r.__dict__ else 1 retval = Register(r.address_offset, name, r.description, r.size, dim) for f in r.fields: retval.add_field(parse_field(f)) return retval
def fill(): "Fill db with sample data" fake = Factory.create('ru_RU') registers = random.randint(10, 50) for register_id in range(registers): register = Register() register.randomize(fake) print("Record#%d of %d: %s" % (register_id, registers, register)) db.session.add(register) db.session.commit() cases = random.randint(1, 100) for case_id in range(cases): case = Case() case.randomize(fake) case.register = register print("\tRecord#%d of %d: %s" % (register_id, registers, register)) print("\tCase#%d of %d: %s" % (case_id, cases, case)) db.session.add(case) db.session.commit() protocols = random.randint(1, 50) for protocol_id in range(protocols): protocol = Protocol() protocol.randomize(fake) protocol.case = case print("\t\tRecord#%d of %d: %s" % (register_id, registers, register)) print("\t\tCase#%d of %d: %s" % (case_id, cases, case)) print("\t\tProtocol#%d of %d: %s" % (protocol_id, protocols, protocol)) db.session.add(protocol) db.session.commit() decisions = random.randint(1, 20) for decision_id in range(decisions): decision = Decision() decision.randomize(fake) decision.protocol = protocol print("\t\t\tRecord#%d of %d: %s" % (register_id, registers, register)) print("\t\t\tCase#%d of %d: %s" % (case_id, cases, case)) print("\t\t\tProtocol#%d of %d: %s" % (protocol_id, protocols, protocol)) print("\t\t\tDecision#%d of %d: %s" % (decision_id, decisions, decision)) db.session.add(decision) db.session.commit()
def post(self): okey = False errorMessage = '' docData = self.request.get('doctor') deptData = self.request.get('dept') timeData = self.request.get('time') idData = self.request.get('id') firstData = self.request.get('first') phoneData = self.request.get('phone') if len(phoneData) == 0 and bool(firstData.lower() == 'true'): jsDic = { "status" : "2", "message": [{"phone":"Phone Number"}], } self.response.headers['Content-Type'] = 'application/json' self.response.out.write( simplejson.dumps(jsDic) ) return # Check for rest values: doc = Doctor.all().filter('docCode =', docData ).get() dept = Department.all().filter('dptCode =', int(deptData) ).get() if not doc: errorMessage = 'BadDoctorId' elif not dept: errorMessage = 'BadDeptId' elif not timeData: errorMessage = 'MissingTimeInfo' else: clinic = Clinic.all().filter('doctor =', doc).filter('dept =', dept).filter('date =', timeData).get() if not clinic: errorMessage = 'WrongInfo' else: okey = True if okey: # Save the info to the db: reg = Register() reg.doc = doc reg.dept = dept reg.link = clinic.link reg.theId = idData reg.isFirst = bool(firstData.lower() == 'true') reg.phone = phoneData reg.put() self.redirect('/tools/register?key=%s' % str(reg.key()) ) else: jsDic = { "status":"1", "message": errorMessage, } self.response.headers['Content-Type'] = 'application/json' self.response.out.write( simplejson.dumps(jsDic) )
def GET(self): p_model=Register.PostModel() print(session_data['user']) print("hi") if session_data['user']!=None: email=session_data['user']['Email'] data=[] p_model=Register.PostModel() data=p_model.Getpost(email) return render.HomeFeed(data) else: data=[] return render.HomeFeed(data)
def POST(self): file=web.input(pic={}) cwd=os.getcwd() dir="static\uploads\\"+(session_data["user"]["Email"]).split("@")[0] file_dir=os.path.join(cwd,dir) if os.path.exists(file_dir): for f in os.listdir(file_dir): os.remove(file_dir+"\\"+f) if not os.path.exists(file_dir): os.makedirs(file_dir) if "pic" in file: filepath=file["pic"].filename f=open(file_dir+"\\"+filepath,"wb") f.write(file['pic'].file.read()) f.close() model=Register.RegisterModel() data={} data["email"]=session_data["user"]["Email"] data["imagepath"]=dir+"\\"+filepath model.upload_pic(data) data={} data["message"]="Profile Updated Successfully" return render.Setting(data)
def post(self): name = self.request.get('name') surname = self.request.get('surname') email = self.request.get('email') message = self.request.get('message') if "<script>" in message: return self.write("You can't hack me! :)") save = Register(name=name, surname=surname, email=email, message=message) save.put() return self.redirect_to("save-site")
def POST(self): data=web.input() model=Register.PostModel() result=model.DeletePost(data) if result: return "pass" else: return "fail"
def query_by_reg_user_id(self, reg_id, user, status='all'): logger.info('NdbEventDao:: DBHIT: query_by_reg_user_id for %s %s' % (reg_id, user.key)) reg_query = Register.query(ndb.AND(Register.reg_id == reg_id, Register.user_id == user.key )) if status != 'all': status_value = STATUS_DICT.get(status) reg_query = reg_query.filter(status == status_value) register = reg_query.fetch(1) return register[0] if register is not None and len(register) > 0 else None
def POST(self): data=web.input() log_model=Register.LoginModel() message=log_model.login_user(data) if message: session_data['user']=message return message else: return message
def post(self, details_id): message = Register.get_by_id(int(details_id)) message.name = self.request.get("name") message.surname = self.request.get("surname") message.email = self.request.get("email") message.message = self.request.get("message") message.put() return self.redirect("/messages")
def test_register_title(self): f = "%s-%d" fund = self.fake.pystr()[:5] register = self.fake.pyint() case = Register( fund=fund, register=register, ) self.assertEqual(case.title(f), f % (fund, register))
def register_examples(): """List register examples""" register = Register.query() form = RegisterForm() if form.validate_on_submit(): register = Register( rsvp=form.rsvp.data, donation=form.donation.data, user_id=users.get_current_user() ) try: register.put() register_id = register.key.id() flash(u'Example %s successfully saved.' % register_id, 'success') return redirect(url_for('register_examples')) except CapabilityDisabledError: flash(u'App Engine Datastore is currently in read-only mode.', 'info') return redirect(url_for('register_examples')) return render_template('register_gae.html', register=register, form=form)
def view_all_reg_student(): try: with db.DbContext() as connection: cursor = connection.cursor() cursor.execute("select iid,usn,status from register") rows = cursor.fetchall() register_pro_lst = [Register(*row) for row in rows] _view_registered_list(register_pro_lst) except Exception as e: print(str(e))
def POST(self): data=web.input(); data.email=session_data['user']['Email'] data.user=session_data['user']['UserName'] c_model=Register.PostModel() result=c_model.insertComment(data) if result: return "pass" else: return "fail"
def edit_register(register_id): register = Register.get_by_id(register_id) form = RegisterForm(obj=example) if request.method == "POST": if form.validate_on_submit(): register.rsvp = form.data.get('rsvp') register.donation = form.data.get('donation') register.put() flash(u'Example %s successfully saved.' % example_id, 'success') return redirect(url_for('register_examples')) return render_template('edit_register.html', register=register, form=form)
def signup(): form = RegisterForm() if request.method=='POST': user = Register(username = form.username.data, password=form.password.data, email = form.email.data, surname = form.surname.data, name=form.name.data, MiddleName=form.MiddleName.data, birthPlace=form.birthPlace.data, passport=form.passport.data ) db.session.add(user) db.session.commit() return render_template('contact.html', form=form) return render_template('signup.html', form=form)
def signup(): # is user is signed in if session.get('user_id'): return redirect(url_for("logout")) email_flag = False username_flag = False password_flag = False if request.method == "POST": # Accessing username, email, password from the HTML form user_name = request.form['username'] email = request.form['email'] password = request.form['password'] # checking for duplicate email and username password_flag = check_password(password) try: email_flag = check_mail(email) except ValidationError: email_flag = True # validating username try: username_flag = check_username(user_name) except ValidationError: username_flag = True if not username_flag and not email_flag and not password_flag and password_flag != "short": # Entering data into Database (Register table) users = Register(user_name=user_name, email=email, password=password) db.session.add(users) db.session.commit() # Entering data into Database (User table) unique_id = uuid.uuid4().hex[:8] user = Users(email=email, unique_id=unique_id) db.session.add(user) db.session.commit() # Logging in the user login_user(user) return redirect(url_for('dashboard', unique_id=unique_id)) return render_template('sign-up.html', email_flag=email_flag, username_flag=username_flag, password_flag=password_flag)
def register(): print request.method if request.method == 'GET': form = RegisterForm(request.form) return render_template('forms/register.html', form=form) if request.method == 'POST': print "hello" # result = request.form user = Register(request.form['name'], request.form['email'], request.form['password']) # name = request.form['name'] # email = request.form['email'] # password = request.form['password'] print user db.session.add(user) db.session.commit() return redirect(url_for('login'))
def form_to_dao(self, record_id=None): register = None if record_id is not None and len(record_id) > 1: register = self.registerDao.get_record(long(record_id)) else: register = Register() event_id = self.request.get('event_id') event_data = self.eventDao.get_record(long(event_id)) register.reg_id = event_data.key register.reg_type = self.request.get('participant_type') register.user_id = self.user_info.key sel_team = self.request.get_all('team') sel_player = self.request.get_all('player') logger.debug('sel_team: ' + str(sel_team)) logger.debug('sel_player: ' + str(sel_player)) payment = 0 if len(sel_team) > 0: teams = [] teams_count = len(sel_team) logger.debug('Teams Count: ' + str(teams_count)) for x in xrange(teams_count): teams.append(self.teamDao.get_record(sel_team[x]).key) logger.debug('Teams ' + str(teams)) payment += teams_count * constants.REG_PRICE register.team_id = teams if len(sel_player) > 0: players = [] players_count = len(sel_player) logger.debug('Players Count: ' + str(players_count)) for x in xrange(players_count): players.append(self.profileDao.get_record(sel_player[x]).key) logger.debug('Players ' + str(players)) payment += players_count * constants.REG_PRICE register.player_id = players register.payment = payment return register
def registerUser(): try: name = '' emailID = '' country = '' lang1 = '' lang2 = '' lang3 = '' longDesc = '' phoneNum = '' pref1 = '' pref2 = '' pref3 = '' if 'name' in request.form: name = request.form['name'] if 'emailID' in request.form: emailID = request.form['emailID'] if 'phoneNum' in request.form: phoneNum = request.form['phoneNum'] if 'country' in request.form: country = request.form['country'] if 'pref1' in request.form: pref1 = request.form['pref1'] if 'pref2' in request.form: pref2 = request.form['pref2'] if 'pref3' in request.form: pref3 = request.form['pref3'] if 'lang1' in request.form: lang1 = request.form['lang1'] if 'lang2' in request.form: lang2 = request.form['lang2'] if 'lang3' in request.form: lang3 = request.form['lang3'] if 'longDesc' in request.form: longDesc = request.form['longDesc'] registerObj = Register( name, emailID, phoneNum, country, pref1, pref2, pref3, lang1, lang2, lang3, longDesc ) db.session.add(registerObj) db.session.commit() return {'message' : 'Request Posted Successfully'}, 201 except: print (traceback.format_exc()) sys.stdout.flush() return jsonify({'message': 'Unexpected Error occurred when posting request. Please try again'}), 405
def post(self, details_id): message = Register.get_by_id(int(details_id)) message.key.delete() return self.redirect("/messages")
def POST(self): data=web.input() reg_model=Register.RegisterModel() reg_model.insert_user(data) return "pass"
def start(): switch = True while switch: print(""" 1.New Checkout 2.View Today's sale 3.Update Discount by category 4.Exit/Quit """) choice = input("Greetings! Select from the menu:") if choice == "1": in_checkout = True while in_checkout: print(""" 1.Add item Name/Code 2.View stock availability 3.Finish and get bill 4.Exit """) checkout_choice = input("Please enter option:") register_obj = Register() if checkout_choice == '1': print(""" Enter "D" when done Enter "C" if item code needs to be referred """) purchased = [] interrupt = False while not interrupt: code = input("Enter item code:") if code == 'd' or code == 'D': interrupt = True break elif code == 'c' or code == 'C': """ Option for billing person to pause entering code and check item code by its name in case code needs to be referred. """ item_name = input("Enter name to fetch item code:") item_code = Inventory.get_item_code(item_name) print('Item code:', item_code) else: purchased.append(code) prices = Inventory.get_price_list(purchased) register_obj.checkout(purchased, prices) elif checkout_choice == '2': stock = Inventory.get_stock() views.view_stock_availability(stock) elif checkout_choice == '3': """ To avail customer based discount """ print(""" 1.Enter s to check if customer is senior citizen 2.Enter P to check for other privileges 3.Press Enter key to proceed with bill generation without privilege check """) privilege = input('Enter option: ') if privilege == 's': discount_percentage = 30 register_obj.update_discount(discount_percentage) elif privilege == 'p': mobile_num = input( "Enter mobile number to check for special discounts" ) if Customer(mobile_num).checkprevilige(): discount_percentage = 20 register_obj.update_discount(discount_percentage) """ Fetching bill statement and final bill amount """ bill = register_obj.get_bill() views.view_bill(bill) bill_amount = register_obj.get_bill_amount() """ Using polymorphism to make payment using multiple methods, two sample methods used as example """ payment_method = input('1.Cash 2.Card 3.Both') payment_obj = [] if payment_method == '1': payment_obj.append(Cash()) if payment_method == '2': payment_obj.append(Card()) if payment_method == '3': payment_obj.append(Cash()) payment_obj.append(Card()) for option in payment_obj: option.receive_payment(bill_amount) """ Updating total sales and stock quantity once payment succeeds """ Inventory.update_stock(purchased) Store.update_total(bill_amount) in_checkout = False elif checkout_choice == '4': in_checkout = False elif choice == "2": views.view_total_sales(Store.get_total()) elif choice == "3": """ Apply discount to items by category or code (Inventory level discount) """ category = input( "Enter item code or category(to update all items of that category) to apply discount" ) Inventory.update_item_prices(category) elif choice == "4": switch = False print("\n Goodbye") elif choice != "": print("\n Not Valid Choice Try again")
def query_by_user(self, user): logger.info('NdbRegisterDao:: DBHIT: get_all_record ') reg_query = Register.query(Register.status == True, Register.user_id == user.key) return reg_query.fetch()
def get_record(self, record_id): logger.info('NdbRegisterDao:: DBHIT: get_record for %s ' % record_id) return Register.get_by_id(long(record_id))
def GET(self): model=Register.RegisterModel() data=model.getUser() return render.Discover(data)
def POST(self): data=web.input() data.email=session_data['user']['Email'] u_model=Register.RegisterModel() u_model.update_user(data) return "pass"
def get(self): msg = Register.query().fetch() saved = {"msg": msg} return self.render_template("save.html", saved)
def import_yml(input=None): "Import data from db" if input is None: print("No data to import") return else: with open(input, 'r') as infile: try: print("Load from \"%s\"" % (input)) data = yaml.load(infile) version = data.get('version') if version == "1.0.0": print(version) registers = data.get('registers', []) register_lookup = dict() for r in registers: fund = r.get('fund') register = Register.query.filter_by( fund=fund, register=r.get('register')).first() if register is None: register = Register(fund=fund) register.import_yml(r) print("%s:\t%s" % (r.get('fund'), r)) register_lookup[r.get('id')] = register db.session.add(register) db.session.commit() cases = data.get('cases', []) case_lookup = dict() for c in cases: register = register_lookup.get(int(c.get('register'))) case = Case(register=register) case.import_yml(c) print("%s:\t%s" % (register, c)) case_lookup[int(c.get('id'))] = case db.session.add(case) db.session.commit() protocols = data.get('protocols', []) protocol_lookup = dict() for p in protocols: case = case_lookup.get(p.get('case')) protocol = Protocol(case=case) protocol.import_yml(p) print("%s:\t%s" % (case, p)) protocol_lookup[int(p.get('id'))] = protocol db.session.add(protocol) db.session.commit() decisions = data.get('decisions', []) decision_lookup = dict() for d in decisions: protocol = protocol_lookup.get(d.get('protocol')) decision = Decision(protocol=protocol) decision.import_yml(d) print("%s:\t%s" % (protocol, d)) decision_lookup[int(d.get('id'))] = decision db.session.add(decision) db.session.commit() resolutions = data.get('resolutions', []) for r in resolutions: case = case_lookup.get(r.get('case')) decision = decision_lookup.get(r.get('decision')) resolution = Resolution(case=case, decision=decision) resolution.import_yml(r) print("%s, %s:\t%s" % (case, decision, r)) db.session.add(resolution) db.session.commit() print(register_lookup) print(case_lookup) print(protocol_lookup) print("Loaded from \"%s\"" % (input)) except yaml.YAMLError as exc: print(exc)
def POST(self): data=web.input() model=Register.RegisterModel() user= model.getProfile(data.id) return render.Profile(user)
def registration_form(unique_id): review = request.args.get("r") check = request.args.get("c") if check != "True" and review != "True": if Register.query.filter_by(unique_id=unique_id).first() is not None: return redirect(url_for('home')) email = Users.query.filter_by(unique_id=unique_id).first().email if request.method == "POST": file = request.files['office_id'] if 'office_id' in request.files and allowed_file(file.filename): first_name = request.form['first_name'] last_name = request.form['last_name'] email = request.form['email'] employee_id = request.form['employee_id'] if Register.query.filter_by( employee_id=employee_id).first() is not None: flash( 'This employee ID is already registered with some other account.' ) if check == "True": return redirect( url_for("registration_form", unique_id=unique_id, c=True)) return redirect( url_for("registration_form", unique_id=unique_id)) organization_name = request.form['organization_name'] mobile_num = request.form['mobile_num'] if Register.query.filter_by( mobile_num=mobile_num).first() is not None: flash( 'This mobile number is already registered with some other account.' ) if check == "True": return redirect( url_for("registration_form", unique_id=unique_id, c=True)) return redirect( url_for("registration_form", unique_id=unique_id)) image_filename = photos.save(file) static = os.path.join(os.path.curdir, "static") pictures = os.path.join(static, "pictures") image_location = os.path.join(pictures, image_filename) with open(image_location, "rb") as file: url = "https://api.imgbb.com/1/upload" payload = { "key": '00a33d9bbaa2f24bf801c871894e91d4', "image": base64.b64encode(file.read()), } res = requests.post(url, payload) str_name = "" for r in res: str_name += r.decode("utf8") image_filename = json.loads(str_name)['data']['url'] if check == "True": register = Register.query.filter_by( unique_id=unique_id).first() register.approval_cancelled = False register.is_approved = False register.first_name = first_name register.last_name = last_name register.email = email register.employee_id = employee_id register.organization_name = organization_name register.mobile_num = mobile_num register.office_id = image_filename else: register = Register(unique_id=unique_id, first_name=first_name, last_name=last_name, email=email, employee_id=employee_id, organization_name=organization_name, mobile_num=mobile_num, office_id=image_filename) db.session.add(register) db.session.commit() return redirect(url_for('preview', unique_id=unique_id)) if review == "True": return render_template('registration-form.html', email=email, is_cancelled=1) return render_template('registration-form.html', email=email, is_cancelled=0)
def POST(self): data=web.input() data.email=session_data['user']['Email'] p_model=Register.PostModel() p_model.AddPost(data) return "pass"