我们从Python开源项目中,提取了以下49个代码示例,用于说明如何使用pyramid.httpexceptions.HTTPFound()。
def setup_three_view(self): if (PROP.getProperty(self.request, PROP.SITE_SETUP) == True): return HTTPFound(location=self.request.route_path("welcome")) elif (PROP.getProperty(self.request, PROP.VERSION) == None): return HTTPFound(location=self.request.route_path("setup_stageone")) event_date = PROP.getProperty(self.request, PROP.EVENT_DATE) if "submit" in self.request.POST: # Save the event details day = int(float(self.request.POST["event_day"])) month = int(float(self.request.POST["event_month"])) year = int(float(self.request.POST["event_year"])) event_name = self.request.POST["event_name"] min_age = int(float(self.request.POST["min_age"])) self.request.root.properties[PROP.EVENT_DATE] = datetime(year, month, day) self.request.root.properties[PROP.EVENT_NAME] = event_name self.request.root.properties[PROP.MINIMUM_AGE] = min_age return HTTPFound(location=self.request.route_path("setup_done")) return { "event_day": event_date.day, "event_month": event_date.month, "event_year": event_date.year, "event_name": PROP.getProperty(self.request, PROP.EVENT_NAME), "min_age": PROP.getProperty(self.request, PROP.MINIMUM_AGE) }
def api_login_view_do(self): # Get username and password username = self.request.POST["username"].lower() password = self.request.POST["password"] # Check if user exists and is non-raven if not username in self.request.root.users: self.request.session.flash("Your username or password was incorrect", "error") return HTTPFound(location=self.request.route_path("api_login")) user = self.request.root.users[username] if user.profile != None and user.profile.raven_user: self.request.session.flash("Your account appears to be a Raven account, please use the Raven login instead.", "error"); return HTTPFound(location=self.request.route_path("api_login")) # Check password if user.password != salt_password(password, user.password_salt): self.request.session.flash("Your username or password was incorrect", "error") return HTTPFound(location=self.request.route_path("api_login")) # Ok, this all looks ok - lets go! header = remember(self.request, user.__name__) self.request.session["user_id"] = user.__name__ return HTTPFound(location=self.request.route_path('api_token_issue'), headers=header)
def retract_addon_view(self): ticket_type = None addon = None if "tick_code" in self.request.matchdict: types = [x.tick_type for x in self.request.root.ticket_pools.values() if x.tick_type.__name__ == self.request.matchdict["tick_code"]] ticket_type = types[0] if "addon_code" in self.request.matchdict: addon_code = self.request.matchdict["addon_code"] if addon_code in ticket_type.addons: addon = ticket_type.addons[addon_code] else: self.request.session.flash("The requested add-on does not exist and hence was not retracted.", "error") return HTTPFound(location=self.request.route_path("admin_tickets_addons", tick_code=ticket_type.__name__)) addon.unlimited = False addon.total_released = len(addon.allocated) self.request.session.flash('The add-on "%s" has been retracted.' % addon.name, "info") return HTTPFound(location=self.request.route_path("admin_tickets_addons", tick_code=ticket_type.__name__))
def delete_addon_view(self): ticket_type = None addon = None if "tick_code" in self.request.matchdict: types = [x.tick_type for x in self.request.root.ticket_pools.values() if x.tick_type.__name__ == self.request.matchdict["tick_code"]] ticket_type = types[0] if "addon_code" in self.request.matchdict: addon_code = self.request.matchdict["addon_code"] if addon_code in ticket_type.addons: addon = ticket_type.addons[addon_code] else: self.request.session.flash("The requested add-on does not exist and hence was not deleted.", "error") return HTTPFound(location=self.request.route_path("admin_tickets_addons", tick_code=ticket_type.__name__)) addon.__parent__ = None ticket_type.addons.pop(addon.__name__, None) if len(ticket_type.addons) > 0: return HTTPFound(location=self.request.route_path("admin_tickets_addons", tick_code=ticket_type.__name__)) else: return HTTPFound(location=self.request.route_path("admin_tickets"))
def release_ticket_type_view(self): ticket_type = None if "tick_code" in self.request.matchdict: types = [x.tick_type for x in self.request.root.ticket_pools.values() if x.tick_type.__name__ == self.request.matchdict["tick_code"]] ticket_type = types[0] else: return HTTPFound(location=self.request.route_path("admin_tickets")) if "number" in self.request.POST: to_release = int(self.request.POST["number"]) pool = ticket_type.__parent__ for i in range(to_release): new_tick = Ticket() new_tick.__parent__ = pool new_tick.tick_type = ticket_type pool.tickets.append(new_tick) pool.tickets._p_changed = True ticket_type.total_released += to_release return HTTPFound(location=self.request.route_path("admin_tickets")) return { "ticket_type": ticket_type, }
def user_profile_view(self): if not self.request.matchdict["user_id"] in self.request.root.users: self.request.session.flash("Requested user does not exist!", "error") return HTTPFound(location=self.request.route_path("admin_accounts")) user = self.request.root.users[self.request.matchdict["user_id"]] if "action" in self.request.GET: if self.request.GET["action"] == "counttotal": user.total_tickets = len(user.tickets) self.request.session.flash("Recounted the total number of tickets this user has.", "info") elif self.request.GET["action"] == "sendtickets": emailer = GenericEmail(self.request) emailer.compose_and_send( "Event Tickets", """Please find the tickets you have purchased attached as a PDF to this email. Please download and print-out the tickets and bring them with you to the event.""", user.__name__, pdf_attachment=TicketDownload(self.request).user_tickets_pdf(user) ) self.request.session.flash("All tickets have been sent to this user via email.", "info") if user.profile == None: self.request.session.flash("Requested user had not setup a profile, now has a blank profile.", "info") user.profile = UserProfile() user.profile.__parent__ = user return { "chosen_user": user }
def user_add_list_view(self): if not "added_users" in self.request.session: return HTTPFound(location=self.request.route_path("admin_accounts")) users = self.request.session["added_users"] group = self.request.root.users[users.keys()[0]].__parent__ if "type" in self.request.GET and self.request.GET["type"].lower() == "csv": csv = "Username,Password,Group\n,,,\n" for user in users: csv += '%s,%s,%s\n' % (user, users[user], group.name) return Response( body=csv, status=200, content_type="text/csv", content_disposition="attachment" ) return { "usernames": sorted(users.keys()), "users": users, "group": group }
def document_view(self): # Get the document document = self.request.root.properties[self.request.matchdict["doc_code"]] if type(document) is not Document: self.request.session.flash("Document does not exist!", "error") return HTTPFound(location=self.request.route_path("admin_settings")) if "submit" in self.request.POST: document.main_body = self.request.POST["body"] to_remove = [] for point in document.headline_points: to_remove.append(point) for point in to_remove: document.headline_points.remove(point) for highpoint in self.request.params.getall("highpoint"): document.headline_points.append(highpoint) return { "document": document, }
def profile_view(self): # Check agreements if not self.user.purchase_agreement: return HTTPFound(location=self.request.route_path("purchase_agreement_act")) elif not self.user.privacy_agreement: return HTTPFound(location=self.request.route_path("privacy_policy_act")) # Check we have a complete profile if not self.user_details_complete: self.request.session.flash("Some details of your profile appear to be incomplete, please correct these.", "info") return HTTPFound(location=self.request.route_path("user_profile_edit")) # Proceed user = self.user profile = user.profile # Make sure all of our unpurchased tickets have been returned issue = Issuer(self.request.root) try: issue.returnUnpurchasedTickets(user.__name__) except Exception: self.request.session.flash("Had an issue returning unpurchased tickets, please try again.", "error") return {"user": user, "profile": profile,}
def ticket_details_view(self): # Check agreements if not self.user.purchase_agreement: return HTTPFound(location=self.request.route_path("purchase_agreement_act")) elif not self.user.privacy_agreement: return HTTPFound(location=self.request.route_path("privacy_policy_act")) tick_id = self.request.matchdict["tick_id"] ticket = None # Find ticket for tick in self.user.tickets: if tick.__name__ == tick_id: ticket = tick break # Safety if ticket == None: self.request.session.flash("Ticket does not exist.", "error") return HTTPFound(location=self.request.route_path("user_profile")) return { "ticket": ticket }
def ticket_payment_history_view(self): # Check agreements if not self.user.purchase_agreement: return HTTPFound(location=self.request.route_path("purchase_agreement_act")) elif not self.user.privacy_agreement: return HTTPFound(location=self.request.route_path("privacy_policy_act")) tick_id = self.request.matchdict["tick_id"] ticket = None # Find ticket for tick in self.user.tickets: if tick.__name__ == tick_id: ticket = tick break # Safety if ticket == None: self.request.session.flash("Ticket does not exist.", "error") return HTTPFound(location=self.request.route_path("user_profile")) return { "ticket": ticket }
def ticket_download_view(self): # Check agreements if not self.user.purchase_agreement: return HTTPFound(location=self.request.route_path("purchase_agreement_act")) elif not self.user.privacy_agreement: return HTTPFound(location=self.request.route_path("privacy_policy_act")) elif not self.ticket_download_enabled: self.request.session.flash("Ticket download is currently not enabled.", "error") return HTTPFound(location=self.request.route_path("user_profile")) tick_id = self.request.matchdict["tick_id"] ticket = None # Find ticket for tick in self.user.tickets: if tick.__name__ == tick_id: ticket = tick break # Safety if ticket == None: self.request.session.flash("Ticket does not exist.", "error") return HTTPFound(location=self.request.route_path("user_profile")) return { "ticket": ticket }
def privacy_policy_view(self): if not self.user.purchase_agreement: return HTTPFound(location=self.request.route_path("purchase_agreement_act")) elif self.user.privacy_agreement: return HTTPFound(location=self.request.route_path("user_profile")) agreement_doc = PROP_KEYS.getProperty(self.request, PROP_KEYS.PRIVACY_POLICY) if "submit" in self.request.POST: # Verify the checkbox is checked chk_response = ("agreement" in self.request.POST and self.request.POST["agreement"] == "agreed") if chk_response: self.user.privacy_agreement = True return HTTPFound(location=self.request.route_path("user_profile")) else: self.request.session.flash("The form was submitted without you accepting the privacy policy. Please first accept the agreement and then click submit.", "error") return { "document": agreement_doc }
def return_view(self): tick_id = self.request.matchdict["tick_id"] user = self.user ticket = None # Find ticket for tick in user.tickets: if tick.__name__ == tick_id: ticket = tick break # If not found, user doesn't own it! if ticket == None: self.request.session.flash("The requested ticket does not exist.", "error") return HTTPFound(location=self.request.route_path("user_profile")) # Check this is not a purchased ticket if ticket.payment.paid: self.request.session.flash("The requested ticket has already been paid for and cannot be returned.", "error") return HTTPFound(location=self.request.route_path("user_profile")) # If this is their ticket, check they have no others if ticket.guest_info == ticket.owner.profile and len(user.tickets) > 1 and self.guest_details_required: self.request.session.flash("You may not return your own ticket whilst you still hold guest tickets.", "error") return HTTPFound(location=self.request.route_path("user_profile")) return { "ticket" : ticket, }
def generate_corpus_success(self, appstruct): pipeline = self.get_pipeline_components() s = appstruct.copy() s['doc'] = self.document corpus_id = hashed_id(sorted(s.items())) job = queue.enqueue(build_corpus, timeout='1h', args=( pipeline, corpus_id, self.document, appstruct['column'], ), kwargs=appstruct) raise exc.HTTPFound('/job-view/%s/%s/job/%s' % (self.document, corpus_id, job.id))
def update(self): self.execute(None) try: navbars = generate_navbars(self, self.context, self.request) except ObjectRemovedException: return HTTPFound(self.request.resource_url(getSite(), '')) values = {'registration': self.context, 'footer_body': navbars['footer_body'], 'navbar_body': navbars['navbar_body']} result = {} body = self.content(args=values, template=self.template)['body'] item = self.adapt_item(body, self.viewid) item['messages'] = navbars['messages'] item['isactive'] = navbars['isactive'] result.update(navbars['resources']) result['coordinates'] = {self.coordinates: [item]} return result
def update(self): source_oid = self.params('source') targets_oid = self.params('targets') if targets_oid and source_oid: try: if not isinstance(targets_oid, (list, tuple)): targets_oid = [targets_oid] targets = [get_obj(int(t)) for t in targets_oid] source = get_obj(int(source_oid)) if targets and source: result = self.execute( {'source': source, 'targets': targets}) if result and result[0].get('error', False): view_error = ViewError() view_error.principalmessage = _("An error has occurred.") return self.failure(view_error) return HTTPFound( self.request.resource_url(source, '@@index')) except Exception as error: log.warning(error) return HTTPFound(self.request.resource_url(self.context, ''))
def update(self): self.execute(None) try: navbars = generate_navbars(self, self.context, self.request) except ObjectRemovedException: return HTTPFound(self.request.resource_url(getSite(), '')) result = {} user = get_current() values = { 'object': self.context, 'state': get_states_mapping( user, self.context, getattr(self.context, 'state_or_none', [None])[0]), 'navbar_body': navbars['navbar_body'] } body = self.content(args=values, template=self.template)['body'] item = self.adapt_item(body, self.viewid) item['messages'] = navbars['messages'] item['isactive'] = navbars['isactive'] result.update(navbars['resources']) result['coordinates'] = {self.coordinates: [item]} return result
def update(self): self.execute(None) root = getSite() try: navbars = generate_body_sub_actions( self, self.context, self.request) except ObjectRemovedException: return HTTPFound(self.request.resource_url(root, '')) result = {} values = {'object': self.context, 'actions_bodies': navbars['body_actions']} body = self.content(args=values, template=self.template)['body'] item = self.adapt_item(body, self.viewid) result['coordinates'] = {self.coordinates: [item]} return result
def update(self): ad_oid = self.params('ad_oid') try: ad_oid = int(ad_oid) except (ValueError, TypeError): # invalid literal for int() with base 10 ad_oid = None if not ad_oid: return HTTPFound(self.request.resource_url(self.request.root, '')) advertisting = get_obj(ad_oid) if advertisting: setattr(advertisting, 'click', (getattr(advertisting, 'click', 0) + 1)) url = getattr(advertisting, 'advertisting_url', self.request.resource_url(self.request.root)) return HTTPFound(url) return HTTPFound(self.request.resource_url(self.request.root, ''))
def update(self): self.execute(None) result = {} try: navbars = generate_navbars(self, self.context, self.request) except ObjectRemovedException: view = '' perimeter = self.context.perimeter context = getSite() if perimeter: context = perimeter view = '@@index' return HTTPFound(self.request.resource_url(context, view)) values = {'object': self.context, 'navbar_body': navbars['navbar_body']} body = self.content(args=values, template=self.template)['body'] item = self.adapt_item(body, self.viewid) item['messages'] = navbars['messages'] item['isactive'] = navbars['isactive'] result.update(navbars['resources']) result['coordinates'] = {self.coordinates: [item]} return result
def update(self): self.execute(None) result = {} try: navbars = generate_navbars(self, self.context, self.request) except ObjectRemovedException: return HTTPFound(self.request.resource_url(getSite(), '')) values = {'object': self.context, 'navbar_body': navbars['navbar_body']} body = self.content(args=values, template=self.template)['body'] item = self.adapt_item(body, self.viewid) item['messages'] = navbars['messages'] item['isactive'] = navbars['isactive'] result.update(navbars['resources']) result['coordinates'] = {self.coordinates: [item]} return result
def update(self): self.execute(None) result = {} try: navbars = generate_navbars(self, self.context, self.request) except ObjectRemovedException: return HTTPFound(self.request.resource_url(getSite(), '')) history = getattr(self.context, 'annotations', {}).get( 'newsletter_history', []) values = {'object': self.context, 'len_subscribed': len(self.context.subscribed), 'footer_body': navbars['footer_body'], 'navbar_body': navbars['navbar_body']} body = self.content(args=values, template=self.template)['body'] item = self.adapt_item(body, self.viewid) item['messages'] = navbars['messages'] item['isactive'] = navbars['isactive'] result.update(navbars['resources']) result['coordinates'] = {self.coordinates: [item]} return result
def update(self): self.execute(None) try: navbars = generate_navbars(self, self.context, self.request) except ObjectRemovedException: return HTTPFound(self.request.resource_url(getSite(), '')) result = {} values = { 'object': self.context, 'files': self._update_files(), 'filter': repr_filter(getattr(self.context, 'filters', []), self.request), 'navbar_body': navbars['navbar_body'], 'services_body': navbars['services_body']} body = self.content(args=values, template=self.template)['body'] item = self.adapt_item(body, self.viewid) item['messages'] = navbars['messages'] item['isactive'] = navbars['isactive'] result.update(navbars['resources']) result.update(self.requirements) result['coordinates'] = {self.coordinates: [item]} return result
def update(self): self.execute(None) root = getSite() try: navbars = generate_navbars(self, self.context, self.request) except ObjectRemovedException: return HTTPFound(self.request.resource_url(root, '')) result = {} user = get_current() parent = self.context.__parent__ can_access_parent = False if not (parent is root) and can_access(user, parent): can_access_parent = True values = {'object': self.context, 'navbar_body': navbars['navbar_body'], 'can_access_parent': can_access_parent} body = self.content(args=values, template=self.template)['body'] item = self.adapt_item(body, self.viewid) item['messages'] = navbars['messages'] item['isactive'] = navbars['isactive'] result.update(navbars['resources']) result['coordinates'] = {self.coordinates: [item]} return result
def update(self): self.execute(None) root = getSite() try: navbars = generate_navbars(self, self.context, self.request) except ObjectRemovedException: return HTTPFound(self.request.resource_url(root, '')) result = {} values = {'object': self.context, 'navbar_body': navbars['navbar_body']} body = self.content(args=values, template=self.template)['body'] item = self.adapt_item(body, self.viewid) item['messages'] = navbars['messages'] item['isactive'] = navbars['isactive'] result.update(navbars['resources']) result['coordinates'] = {self.coordinates: [item]} return result
def logout(request): from pyramid.security import forget headers = forget(request) from pyramid.httpexceptions import HTTPFound return HTTPFound( location='/', headers=headers )
def login(request): session = DBSession() message = request.params.get('message') username = request.params.get('username') if request.method == 'POST': if username: username = username.lower() # Think now have steam accounts. can have different accounts but same name userq = session.query(User).filter(User.username == username).all() for user in userq: if user.validate_password(request.params.get('password')): headers = remember(request, user.id) user.last_login = datetime.datetime.now() return HTTPFound('/team', headers=headers) else: headers = forget(request) message = "Password did not match stored value for %s" % user.username if not userq: message = "Username not recognised" else: message = 'Oops! SOmething went wrong' headers = forget(request) return_dict = {'message': message, "plus_id": request.registry.settings.get( 'SOCIAL_AUTH_STEAM_KEY' )} return add_other_games(session, request.game, return_dict)
def logout(request): headers = forget(request) return HTTPFound(location='/login', headers=headers)
def change_password(request): session = DBSession() user_id = authenticated_userid(request) new_password = request.params.get('new_password') confirm_new_password = request.params.get('confirm_new_password') old_password = request.params.get('old_password') user = session.query(User).filter(User.id == user_id).first() if not user: params = {"message": "Your username could not be found", "message_type": "change_password"} return HTTPFound(location=request.route_url('account_settings', _query=params)) if not user.validate_password(old_password): params = {"message": "Old password did not match", "message_type": "change_password"} return HTTPFound(location=request.route_url('account_settings', _query=params)) if old_password == "": # this is the case for steam accounts params = {"message": "Change password does not apply to steam logins", "message_type": "failure"} return HTTPFound(location=request.route_url('account_settings', _query=params)) pword_invalid_check = check_invalid_password(new_password, confirm_new_password) if pword_invalid_check: return HTTPFound(location=request.route_url('account_settings', _query=pword_invalid_check)) session.query(User).filter(User.id == user_id).update({User.password: bcrypt.encrypt(new_password)}) params = {"message": "Congratulations! Password successfully changed", "message_type": "success"} return HTTPFound(location=request.route_url('account_settings', _query=params))
def reset_password(request): session = DBSession() guid = request.params.get('guid') user_id = request.params.get('user_id') new_password = request.params.get('new_password') confirm_new_password = request.params.get('confirm_new_password') if not session.query(PasswordReset).filter(PasswordReset.user_id == user_id).first().validate_guid(guid): raise HTTPForbidden() if confirm_new_password != new_password: params = {"message": "Passwords did not match", "message_type": "change_password"} return HTTPFound(location=request.route_url('viewAccount', _query=params)) pword_invalid_check = check_invalid_password(new_password, confirm_new_password) if pword_invalid_check: return HTTPFound(location=request.route_url('login', _query=pword_invalid_check)) session.query(User).filter(User.id == user_id).update({User.password: bcrypt.encrypt(new_password)}) session.query(PasswordReset).filter(PasswordReset.user_id == user_id).delete() params = {"message": "Congratulations! Password successfully changed", "message_type": "success"} return HTTPFound(location=request.route_url('login', _query=params))
def update_email_settings(request): session = DBSession() user_id = authenticated_userid(request) if not user_id: return HTTPFound('/login') new_email = request.params.get('email') contactable = True if request.params.get('emailContact') == "on" else False session.query(User).filter(User.id == user_id).\ update({User.contactable: contactable, User.email: new_email}) params = {"message": "Congratulations! Email settings successfully updated", "message_type": "success"} return HTTPFound(location=request.route_url('account_settings', _query=params)) # @view_config(route_name='home', renderer='../templates/login.mako') # def home(request): # try: # user = get_user(request) # headers = remember(request, user.id) # return HTTPFound("/team", headers=headers) # except: # return HTTPFound("/login") # # return common_context( # # request.registry.settings['SOCIAL_AUTH_AUTHENTICATION_BACKENDS'], # # load_strategy(request), # # user=get_user(request), # # plus_id=request.registry.settings.get( # # 'SOCIAL_AUTH_GOOGLE_PLUS_KEY' # # ), # # )
def done(request): user = get_user(request) headers = remember(request, user.id) return HTTPFound('/team', headers=headers) # return {"user": get_user(request), # "plus_id": request.registry.settings.get( # 'SOCIAL_AUTH_STEAM_KEY' # ), # } # return common_context( # request.registry.settings['SOCIAL_AUTH_AUTHENTICATION_BACKENDS'], # load_strategy(request), # user=get_user(request), # plus_id=request.registry.settings['SOCIAL_AUTH_GOOGLE_PLUS_KEY'], # ) # @view_config(route_name='email_required', renderer='common:templates/home.jinja2') # def email_required(request): # strategy = load_strategy(request) # partial_token = request.GET.get('partial_token') # partial = strategy.partial_load(partial_token) # return common_context( # request.registry.settings['SOCIAL_AUTH_AUTHENTICATION_BACKENDS'], # strategy, # user=get_user(request), # plus_id=request.registry.settings['SOCIAL_AUTH_GOOGLE_PLUS_KEY'], # email_required=True, # partial_backend_name=partial.backend, # partial_token=partial_token # )
def start_setup_view(self): if "properties" in self.request.root.__dict__ and (PROP.getProperty(self.request, PROP.SITE_SETUP) == True): return HTTPFound(location=self.request.route_path("welcome")) return {}
def setup_one_view(self): if (PROP.getProperty(self.request, PROP.SITE_SETUP) == True): return HTTPFound(location=self.request.route_path("welcome")) setup = False if (PROP.getProperty(self.request, PROP.VERSION) != None): print "Database already setup!" else: # Setup the database self.db_run_setup(self.request.root) setup = True return { "setup": setup }
def setup_two_view(self): if (PROP.getProperty(self.request, PROP.SITE_SETUP) == True): return HTTPFound(location=self.request.route_path("welcome")) elif (PROP.getProperty(self.request, PROP.VERSION) == None): return HTTPFound(location=self.request.route_path("setup_stageone")) # Check if the password has already been changed, default is 'password' admin_usr = self.request.root.users["admin"] test_password = salt_password("password", admin_usr.password_salt) if test_password != admin_usr.password: self.request.session.flash("It looks like someone has already changed the default password on the account, if this wasn't you then contact support!", "info") return HTTPFound(location=self.request.route_path("setup_stagethree")) # Get password for admin user and double check if "password_one" in self.request.POST and "password_two" in self.request.POST: pwd_1 = self.request.POST["password_one"] pwd_2 = self.request.POST["password_two"] if len(pwd_1) < 5: self.request.session.flash("The passwords entered are too short, they must be of 5 characters or longer.", "error") return {} elif pwd_1 != pwd_2: self.request.session.flash("The passwords entered do not match.", "error") return {} # Set the administrator password admin_usr.password_salt = Coding().generateUniqueCode() admin_usr.password = salt_password(pwd_1, admin_usr.password_salt) return HTTPFound(location=self.request.route_path("setup_stagethree")) return {}
def setup_done_view(self): if (PROP.getProperty(self.request, PROP.SITE_SETUP) == True): return HTTPFound(location=self.request.route_path("welcome")) elif (PROP.getProperty(self.request, PROP.VERSION) == None): return HTTPFound(location=self.request.route_path("setup_stageone")) self.request.root.properties[PROP.SITE_SETUP] = True return {} # -- Database Setup Functions -- #
def at_front_view(self): if not self.request.root.properties[PROP_KEYS.QUEUE_ENABLED]: return HTTPFound(location=self.request.route_path("welcome")) # Find open slots total_slots = self.request.root.properties[PROP_KEYS.CONCURRENT_NUM] open_slots = total_slots - len(self.request.root.active) # Continue position = Queue(self.request).position(self.request.session["queue_id"]) if position < open_slots: queue_id = self.request.session["queue_id"] items = [x for x in self.request.root.queue if x.queue_id == queue_id] if len(items) <= 0: self.request.session.flash("You are not yet at the front of the queue, please wait.", "info") return HTTPFound(location=self.request.route_path("queue")) else: # Check if there are too many people in "active" state if open_slots <= 0: return HTTPFound(location=self.request.route_path("queue")) # Shift the person from being in queue to being active item = items[0] self.request.root.queue.remove(item) self.request.root.active[item.__name__] = item item.__parent__ = self.request.root.active item.queue_exit_time = item.purchase_entry_time = datetime.now() # Make active self.request.session.pop("queue_id", None) self.request.session["active_id"] = item.__name__ header = remember(self.request, str(item.__name__)) return HTTPFound(location=self.request.route_path('welcome'), headers=header) else: self.request.session.flash("You are not yet at the front of the queue, please wait.", "info") return HTTPFound(location=self.request.route_path("queue"))
def welcome_view(self): # Check whether the site is setup? if not "properties" in self.request.root.__dict__: print "Need to setup site!" return HTTPFound(location=self.request.route_path("setup")) # If queue enabled, deal with it elif not self.has_queued: return HTTPFound(location=self.request.route_path("queue")) # Check queue/active status elif Queue(self.request).timed_out(): return HTTPFound(self.request.route_path("purchase_timeout")) elif "user_id" in self.request.session and self.request.session["user_id"] in self.context.users: return HTTPFound(location=self.request.route_path("branch_flow")) return {}
def welcome_view_do(self): if not self.has_queued: return HTTPFound(location=self.request.route_path("queue")) # Get username and password username = self.request.POST["username"].lower() password = self.request.POST["password"] # Check if user exists and is non-raven if not username in self.request.root.users: self.request.session.flash("Your username or password was incorrect", "error") return HTTPFound(location=self.request.route_path("welcome")) user = self.request.root.users[username] if user.profile != None and user.profile.raven_user: self.request.session.flash("Your account appears to be a Raven account, please use the Raven login instead.", "error"); return HTTPFound(location=self.request.route_path("welcome")) # Check password if user.password != salt_password(password, user.password_salt): self.request.session.flash("Your username or password was incorrect", "error") return HTTPFound(location=self.request.route_path("welcome")) # Ok, this all looks ok - lets go! header = remember(self.request, user.__name__) self.request.session["user_id"] = user.__name__ if user.profile == None: profile = UserProfile() profile.raven_user = False profile.__parent__ = user profile.__name__ = user.__name__ + "-profile" user.profile = profile return HTTPFound(location=self.request.route_path('user_profile_edit'), headers=header) elif None in [user.profile.dob, user.profile.fullname]: return HTTPFound(location=self.request.route_path('user_profile_edit'), headers=header) else: return HTTPFound(location=self.request.route_path('user_profile'), headers=header)
def start_raven_view(self): if not self.has_queued: return HTTPFound(location=self.request.route_path("queue")) self.request.session["raven_route"] = self.request.route_path("branch_raven_flow") return HTTPFound(location=self.request.route_path("raven_first_stage"))
def branch_flow_view(self): user = self.context.users[self.request.session["user_id"]] if user.profile == None or None in [user.profile.dob, user.profile.fullname]: return HTTPFound(location=self.request.route_path('user_profile_edit')) else: return HTTPFound(location=self.request.route_path('user_profile'))
def view_403(self): # Get intended path if not self.user: self.request.session.flash("You will need to login before you can access other parts of the ticketing system.", "info") return HTTPFound(location=self.request.route_path("welcome")) return {}
def api_login_raven_view(self): self.request.session["raven_route"] = self.request.route_path("api_login_raven_return") return HTTPFound(location=self.request.route_path("raven_first_stage"))
def api_login_raven_return_view(self): # Choose raven path, create a user if necessary users = self.context.users.values() raven_obj = self.request.session["raven"] # Should select a single user user = [x for x in users if x.profile != None and x.profile.crsid != None and x.profile.crsid.lower() == raven_obj.raven_crsid.lower()] if len(user) == 0: self.request.session.flash("No account exists for this Raven login", "error") return HTTPFound(location=self.request.route_path("api_login")) else: user = user[0] header = remember(self.request, user.__name__) self.request.session["user_id"] = user.__name__ return HTTPFound(location=self.request.route_path('api_token_issue'), headers=header)
def single_payment_view(self): payments = self.request.root.payments # Get payment if possible if not self.request.matchdict["ref_code"] in self.request.root.payments: return HTTPFound(location=self.request.route_path("admin_payments")) payment = payments[self.request.matchdict["ref_code"]] if "action" in self.request.GET: if self.request.GET["action"] == "recalculate": if payment.method == "stripe": payment.processing = int(payment.item_total * self.stripe_percentage) payment.total = int(payment.item_total * (1 + self.stripe_percentage)) else: payment.processing = 0 payment.total = payment.item_total self.request.session.flash("Recalculated the payment total.", "info") elif self.request.GET["action"] == "emailconfirm": PurchaseConfirmationEmail(self.request).compose_and_send(payment.ref_code) self.request.session.flash("A payment confirmation has been sent via email.", "info") elif self.request.GET["action"] == "sendtickets": emailer = GenericEmail(self.request) emailer.compose_and_send( "Event Tickets", """Please find the tickets you purchased in payment %s attached as a PDF to this email. Please download and print-out the tickets and bring them with you to the event.""" % (payment.ref_code), payment.owner.__name__, pdf_attachment=TicketDownload(self.request).payment_tickets_pdf(payment) ) self.request.session.flash("The tickets in this payment have been sent via email.", "info") return { "payment": payment, }