def post(self): query = self.request.get('query') template_values = bene_util.initTemplate(self.request.uri) template_values['query'] = query if (len(query) != 0): productlist = entities.Product.all() matches = [p for p in productlist if query.lower() in p.name.lower()] template_values['matches'] = matches path = os.path.join(os.path.dirname(__file__), 'searchresult.html') self.response.out.write(template.render(path, template_values)) else: template_values = bene_util.initTemplate(self.request.uri) path = os.path.join(os.path.dirname(__file__), 'searchproduct.html') self.response.out.write(template.render(path, template_values))
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return if bene_query.getCurrentUser( ).isConsumer: # consumers can't access this self.redirect('/') return _producer = bene_query.getCurrentProducer() if _producer == None: # no producer signed up, so ask to sign up self.redirect('/') return template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = _producer.key() template_values['name_old'] = _producer.name template_values['description_old'] = _producer.description template_values['email_public_old'] = _producer.email_public template_values['cropentity'] = _producer path = os.path.join(os.path.dirname(__file__), 'editproducer.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return if bene_query.getCurrentUser().isConsumer: # consumers can't access this self.redirect('/') return _producer = bene_query.getCurrentProducer() if _producer == None: # no producer signed up, so ask to sign up self.redirect('/') return if not _producer.verified: # if producer is not verified self.redirect('/producerhome?%s' % urllib.urlencode({'verify': True})) return template_values = bene_util.initTemplate(self.request.uri) template_values['factories'] = _producer.getFactories() path = os.path.join(os.path.dirname(__file__), 'createworker.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if user: # if user signed in signed_in_user = bene_query.getCurrentUser() if signed_in_user.isProducer: if not bene_query.getCurrentProducer( ): # if producer page doesn't exist, need to create one self.redirect('/createproducer?%s' % urllib.urlencode({ 'redirect': 'producerhome', 'msg': True })) else: # if setup done, then go to home page self.redirect('/producerhome') return else: if not bene_query.getCurrentConsumer(): self.redirect('/createconsumer?%s' % urllib.urlencode({ 'redirect': 'consumerhome', 'msg': True })) return else: self.redirect('/consumerhome') return else: # otherwise, show button for signing in and searching template_values = bene_util.initTemplate(self.request.uri) path = os.path.join(os.path.dirname(__file__), 'home.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return if bene_query.getCurrentUser( ).isConsumer: # consumers can't access this self.redirect('/') return producer = bene_query.getCurrentProducer() if producer == None: # no producer signed up, so ask to sign up self.redirect('/') return # Make a dictionary for template template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = producer.key() template_values['producer'] = producer template_values['product_lines'] = producer.getProductLines() template_values['path'] = "product" template_values['can_edit_local'] = False user = users.get_current_user() if user: if producer.owner == user: template_values['can_edit_local'] = True path = os.path.join(os.path.dirname(__file__), 'viewproducerproducts.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return if bene_query.getCurrentUser().isConsumer: # consumers can't access this self.redirect('/') return producer = bene_query.getCurrentProducer() if producer == None: # no producer signed up, so ask to sign up self.redirect('/') return # Make a dictionary for template template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = producer.key() template_values['producer'] = producer template_values['products'] = producer.getProducts() template_values['can_edit'] = False user = users.get_current_user() if user: if producer.owner == user: template_values['can_edit'] = True path = os.path.join(os.path.dirname(__file__), 'viewproducerproducts.html') self.response.out.write(template.render(path, template_values)) return
def get(self): # Get the id from the get parameter ID = self.request.get("id") if not ID: """ TODO: If no ID sent, default to page with all products? """ self.redirect("/") return # Fetch the data for this product producer = db.get(ID) """ an error in getting the producer will be redirected to exception handler""" # Make a dictionary for template template_values = bene_util.initTemplate(self.request.uri) template_values["id"] = ID template_values["producer"] = producer template_values["factories"] = producer.getFactories() template_values["can_edit"] = False user = users.get_current_user() if user: if producer.owner == user: template_values["can_edit"] = True path = os.path.join(os.path.dirname(__file__), "viewproducerfactories.html") self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect("/?signin=True") return if bene_query.getCurrentUser().isProducer: # producers aren't allowed here self.redirect("/") return _consumer = bene_query.getCurrentConsumer() if _consumer == None: # no consumer page, so create one self.redirect("/") return # Make a dictionary for template name = _consumer.name profile = _consumer.profile template_values = bene_util.initTemplate(self.request.uri) template_values["id"] = _consumer.key() template_values["consumer"] = _consumer template_values["name"] = name template_values["profile"] = profile template_values["can_edit"] = False user = users.get_current_user() if user: if _consumer.owner == user: template_values["can_edit"] = True template_values["edit_link"] = "/editconsumer" path = os.path.join(os.path.dirname(__file__), "viewconsumer.html") self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return if bene_query.getCurrentUser().isProducer: # producers can't access this self.redirect('/') return _consumer = bene_query.getCurrentConsumer() if _consumer == None: # no producer signed up, so ask to sign up self.redirect('/') return template_values = bene_util.initTemplate(self.request.uri) template_values['consumer'] = _consumer _msgs = _consumer.getReceivedMsg() if _msgs: _msgs.reverse() template_values['messages'] = _msgs template_values['num_unread'] = _consumer.has_unread template_values['path'] = 'message' _consumer.has_unread = 0 _consumer.put() path = os.path.join(os.path.dirname(__file__), 'viewinbox.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect("/?signin=True") return if bene_query.getCurrentUser().isConsumer: # consumers can't access this self.redirect("/") return _producer = bene_query.getCurrentProducer() if _producer == None: # no producer signed up, so ask to sign up self.redirect("/") return if not _producer.verified: # if producer is not verified self.redirect("/producerhome?%s" % urllib.urlencode({"verify": True})) return template_values = bene_util.initTemplate(self.request.uri) template_values["factories"] = _producer.getFactories() template_values["workers"] = _producer.getWorkers() template_values["badges"] = entities.Badge.all() path = os.path.join(os.path.dirname(__file__), "createproduct.html") self.response.out.write(template.render(path, template_values)) return
def get(self): ID = self.request.get('id') if not ID: ''' TODO: If no ID sent, default to page with all products? ''' self.redirect('/') return _product = db.get(ID) ''' an error in getting the product will be redirected to exception handler''' # Make a dictionary for template name = _product.name producer = _product.getProducer() workers = _product.getWorkers() factory = _product.getFactory() template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = ID template_values['product'] = _product template_values['name'] = name template_values['producer'] = producer template_values['workers'] = workers template_values['url'] = self.request.url template_values['qr_url'] = self.request.url.replace('view','qr') path = os.path.join(os.path.dirname(__file__), 'viewproductworkers.html') self.response.out.write(template.render(path, template_values)) return
def get(self): ID = bene_util.sanitize(self.request.get('id')) if not ID: ''' TODO: If no ID sent, default to ? ''' self.redirect('/') return _generic = db.get(ID) ''' an error in getting the product will be redirected to exception handler''' if _generic.isUnit: _generic = _generic.getProductConfig() ''' NOTE THAT THIS WORKS FOR BOTH PRODUCT UNITS AND CONFIGS ''' # Make a dictionary for template _productconfig = _generic name = _productconfig.getName() producer = _productconfig.getProducer() template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = ID template_values['name'] = name template_values['producer'] = producer template_values['locations'] = _generic.getLocations() template_values['numloc'] = len(_generic.getLocations()) template_values['path'] = "product" path = os.path.join(os.path.dirname(__file__), 'viewpath.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return if bene_query.getCurrentUser().isConsumer: # consumers can't access this self.redirect('/') return _producer = bene_query.getCurrentProducer() if _producer == None: # no producer signed up, so ask to sign up self.redirect('/') return if not _producer.verified: # if producer is not verified self.redirect('/producerhome?%s' % urllib.urlencode({'verify': True})) return ID = self.request.get('id') if not ID: ''' TODO: If no ID sent, default to ? ''' self.redirect('/') return _worker = db.get(ID) ''' an error in getting the worker will be redirected to exception handler''' if _worker.owner != user: # not 'owner' of worker. I know it sounds very pre-emancipation self.redirect('/producerhome?%s' % urllib.urlencode({'not_owner': True})) return template_values = bene_util.initTemplate(self.request.uri) template_values['name_old'] = _worker.name template_values['profile_old'] = _worker.profile template_values['unique_old'] = _worker.unique _factories_old = [_worker.getFactory()] template_values['factories_old'] = _factories_old template_values['factories'] = [] ''' TODO: Make this more efficient. For some reason, 'factory not in _factories_old' doesn't work ''' _factories = _producer.getFactories() if _factories: for factory in _factories: if factory: add = True if _factories_old: for factory_old in _factories_old: if factory_old: if factory_old.key() == factory.key(): add = False if add: template_values['factories'].append(factory) path = os.path.join(os.path.dirname(__file__), 'editworker.html') self.response.out.write(template.render(path, template_values)) return
def get(self): ID = self.request.get("id") if not ID: """ TODO: if no id is sent, defaults to a page with all producers? """ self.redirect("/") return consumer = db.get(ID) """ an error in getting the consumer will be redirected to exception handler""" # Make a dictionary for template name = consumer.name profile = consumer.profile template_values = bene_util.initTemplate(self.request.uri) template_values["id"] = ID template_values["consumer"] = consumer template_values["name"] = name template_values["profile"] = profile template_values["can_edit"] = False user = users.get_current_user() if user: if consumer.owner == user: template_values["can_edit"] = True template_values["edit_link"] = "/editconsumer" path = os.path.join(os.path.dirname(__file__), "viewconsumer.html") self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return if bene_query.getCurrentUser().isProducer: # producers aren't allowed here self.redirect('/') return _consumer = bene_query.getCurrentConsumer(); if _consumer == None: # no consumer page, so create one self.redirect('/') return # Make a dictionary for template template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = _consumer.key() template_values['consumer'] = _consumer template_values['products'] = _consumer.getProducts() template_values['can_edit_local'] = False user = users.get_current_user() if user: if _consumer.owner == user: template_values['can_edit_local'] = True path = os.path.join(os.path.dirname(__file__), 'viewcloset.html') self.response.out.write(template.render(path, template_values)) return
def get(self): # Get the id from the get parameter ID = self.request.get('id') if not ID: ''' TODO: If no ID sent, default to page with all products? ''' self.redirect('/') return # Fetch the data for this product product = db.get(ID) ''' an error in getting the product will be redirected to exception handler''' _factory = product.getFactory() if _factory and _factory.location: latitude = _factory.location.lat longitude = _factory.location.lon else: latitude = None longitude = None # Make a dictionary for template template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = ID template_values['name'] = product.name template_values['producer'] = product.getProducer() template_values['latitude'] = latitude template_values['longitude'] = longitude template_values['url'] = self.request.url template_values['qr_url'] = self.request.url.replace('view','qr') template_values['factory'] = _factory template_values['badges'] = product.getBadges() template_values['rating'] = product.rating template_values['workers'] = product.getWorkers() if product.picture: template_values['has_image'] = True else: template_values['has_image'] = False template_values['can_edit'] = False user = users.get_current_user() if user: if product.owner == user: template_values['can_edit'] = True template_values['edit_link'] = '/editproduct?%s' % urllib.urlencode({'id': ID}) template_values['in_closet'] = False template_values['add_closet'] = False if user: if bene_query.getCurrentUser().isConsumer: consumer = bene_query.getCurrentConsumer() if consumer: if consumer.hasProduct(product.key()): template_values['in_closet'] = True template_values['rem_closet_link'] = '/removefromcloset?%s' % urllib.urlencode({'id': ID}) else: template_values['add_closet'] = True template_values['add_closet_link'] = '/addtocloset?%s' % urllib.urlencode({'id': ID}) path = os.path.join(os.path.dirname(__file__), 'viewproduct.html') self.response.out.write(template.render(path, template_values)) return
def get(self): # Get the id from the get parameter ID = bene_util.sanitize(self.request.get('id')) if not ID: ''' TODO: If no ID sent, default to? ''' self.redirect('/') return # Fetch the data for this consumer consumer = db.get(ID) ''' an error in getting the consumer will be redirected to exception handler''' # Make a dictionary for template template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = ID template_values['consumer'] = consumer template_values['products'] = consumer.getProducts() template_values['path'] = self.request.path template_values['can_edit_local'] = False user = users.get_current_user() if user: if consumer.owner == user: template_values['can_edit_local'] = True path = os.path.join(os.path.dirname(__file__), 'viewcloset.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return if bene_query.getCurrentUser().isProducer: # producers aren't allowed here self.redirect('/') return _consumer = bene_query.getCurrentConsumer(); if _consumer == None: # no consumer page, so create one self.redirect('/') return # Make a dictionary for template template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = _consumer.key() template_values['consumer'] = _consumer template_values['products'] = _consumer.getProducts() template_values['path'] = self.request.path template_values['can_edit_local'] = False user = users.get_current_user() if user: if _consumer.owner == user: template_values['can_edit_local'] = True path = os.path.join(os.path.dirname(__file__), 'viewcloset.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return if bene_query.getCurrentUser( ).isProducer: # producers aren't allowed here self.redirect('/') return _consumer = bene_query.getCurrentConsumer() if _consumer == None: # no consumer page, so create one self.redirect('/') return template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = _consumer.key() template_values['name_old'] = _consumer.name template_values['profile_old'] = _consumer.profile template_values['email_public_old'] = _consumer.email_public template_values['cropentity'] = _consumer path = os.path.join(os.path.dirname(__file__), 'editconsumer.html') self.response.out.write(template.render(path, template_values)) return '''
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return if bene_query.getCurrentUser( ).isConsumer: # consumers can't access this self.redirect('/') return _producer = bene_query.getCurrentProducer() if _producer == None: # no producer signed up, so ask to sign up self.redirect('/') return template_values = bene_util.initTemplate(self.request.uri) template_values['producer'] = _producer template_values['path'] = "message" __msgs = _producer.getSentMsg() _msgs = [] for _msg in __msgs: _msgs.append(_msg) if _msgs: _msgs.reverse() template_values['messages'] = _msgs path = os.path.join(os.path.dirname(__file__), 'viewoutbox.html') self.response.out.write(template.render(path, template_values)) return
def get(self): # Get the id from the get parameter ID = self.request.get('id') if not ID: ''' TODO: If no ID sent, default to page with all products? ''' self.redirect('/') return # Fetch the data for this producer producer = db.get(ID) ''' an error in getting the producer will be redirected to exception handler''' # Make a dictionary for template template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = ID template_values['producer'] = producer template_values['products'] = producer.getProducts() template_values['can_edit'] = False user = users.get_current_user() if user: if producer.owner == user: template_values['can_edit'] = True path = os.path.join(os.path.dirname(__file__), 'viewproducerproducts.html') self.response.out.write(template.render(path, template_values)) return
def get(self): ID = self.request.get('id') if not ID: ''' TODO: if no id is sent, defaults to a page with all producers? ''' self.redirect('/') return consumer = db.get(ID) ''' an error in getting the consumer will be redirected to exception handler''' # Make a dictionary for template name = consumer.name profile = consumer.profile template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = ID template_values['consumer'] = consumer template_values['name'] = name template_values['profile'] = profile template_values['can_edit'] = False user = users.get_current_user() if user: if consumer.owner == user: template_values['can_edit'] = True path = os.path.join(os.path.dirname(__file__), 'viewconsumer.html') self.response.out.write(template.render(path, template_values)) return
def get(self): ID = bene_util.sanitize(self.request.get('id')) if not ID: ''' TODO: If no ID sent, default to page with all products? ''' self.redirect('/') return _product = db.get(ID) ''' an error in getting the product will be redirected to exception handler''' if _product.isUnit: _product = _product.getProductConfig() # Make a dictionary for template _productconfig = _product name = _product.name producer = _productconfig.getProducer() workers = _productconfig.getWorkers() template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = ID template_values['productconfig'] = _productconfig template_values['name'] = name template_values['producer'] = producer template_values['workers'] = workers template_values['url'] = self.request.url template_values['qr_url'] = self.request.url.replace('view','qr') path = os.path.join(os.path.dirname(__file__), 'viewproductworkers.html') self.response.out.write(template.render(path, template_values)) return
def post(self): query = bene_util.sanitize(self.request.get('query')) template_values = bene_util.initTemplate(self.request.uri) template_values['query'] = query if (len(query) != 0): productlist = entities.ProductLine.all() producerlist = entities.Producer.all() workerlist = entities.Worker.all() locationlist = entities.Location.all() max_results = 10 matchesProduct = [ p for p in productlist if query.lower() in p.name.lower() ] template_values['matchesProduct'] = bene_util.bestMatch( query, matchesProduct)[0:max_results] matchesProducer = [ p for p in producerlist if query.lower() in p.name.lower() ] template_values['matchesProducer'] = bene_util.bestMatch( query, matchesProducer)[0:max_results] matchesWorker = [ p for p in workerlist if query.lower() in p.name.lower() ] template_values['matchesWorker'] = bene_util.bestMatch( query, matchesWorker)[0:max_results] matchesLocation = [ p for p in locationlist if query.lower() in p.name.lower() ] template_values['matchesLocation'] = bene_util.bestMatch( query, matchesLocation)[0:max_results] template_values['allListEmpty'] = False if (not matchesProduct) and (not matchesWorker) and ( not matchesLocation) and (not matchesProducer): template_values['allListEmpty'] = True path = os.path.join(os.path.dirname(__file__), 'searchresult.html') self.response.out.write(template.render(path, template_values)) else: template_values = bene_util.initTemplate(self.request.uri) path = os.path.join(os.path.dirname(__file__), 'searchproduct.html') self.response.out.write(template.render(path, template_values))
def handle_exception(self, exception, debug_mode): if debug_mode: super(ViewProduct, self).handle_exception(exception, debug_mode) else: template_values = bene_util.initTemplate(self.request.uri) path = os.path.join(os.path.dirname(__file__), 'not_found.html') self.response.out.write(template.render(path, template_values)) return
def handle_exception(self, exception, debug_mode): if debug_mode: super(StoreBadgePage, self).handle_exception(exception, debug_mode) else: template_values = bene_util.initTemplate(self.request.uri) path = os.path.join(os.path.dirname(__file__), 'not_found.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return if bene_query.getCurrentUser( ).isConsumer: # consumers can't access this self.redirect('/') return producer = bene_query.getCurrentProducer() if producer == None: # no producer signed up, so ask to sign up self.redirect('/') return # Make a dictionary for template template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = producer.key() template_values['producer'] = producer workers = producer.getWorkers() template_values['workers'] = workers num_workers = 0 if workers: for worker in workers: if worker: num_workers += 1 if num_workers == 0: template_values['no_workers'] = True else: template_values['no_workers'] = False locations = producer.getLocations() template_values['locations'] = locations num_workers_with_loc = 0 if locations: for location in locations: if location: _workers = location.getWorkers() if _workers: for worker in _workers: if worker: num_workers_with_loc += 1 template_values[ 'num_worker_no_location'] = num_workers - num_workers_with_loc template_values['can_edit_local'] = False user = users.get_current_user() if user: if producer.owner == user: template_values['can_edit_local'] = True path = os.path.join(os.path.dirname(__file__), 'viewproducerworkers.html') self.response.out.write(template.render(path, template_values)) return
def get(self): # Get the id from the get parameter ID = bene_util.sanitize(self.request.get('id')) if not ID: ''' TODO: If no ID sent, default to page with all products? ''' self.redirect('/') return # Fetch the data for this product product = db.get(ID) ''' an error in getting the product will be redirected to exception handler''' # Make a dictionary for template template_values = bene_util.initTemplate(self.request.uri) # generic template_values['id'] = ID template_values['name'] = product.name template_values['product'] = product template_values['producer'] = product.getProducer() template_values['rating'] = product.getRating() # urls template_values['url'] = self.request.url template_values['path'] = "product" template_values['qr_url'] = self.request.url.replace('viewproduct','qr') template_values['image_url'] = self.request.url.replace('viewproduct', 'productimage') template_values['comment_url'] = '%s/viewproduct?%s' % (self.request.host_url, urllib.urlencode({'id': ID})) # interactions - producer template_values['can_edit'] = False user = users.get_current_user() if user: if product.owner == user and bene_query.getCurrentUser().isProducer: template_values['can_edit'] = True template_values['edit_link'] = '/editproduct?%s' % urllib.urlencode({'id': ID}) template_values['show_qr'] = True # interactions - consumer template_values['in_closet'] = False template_values['add_closet'] = False if user: if bene_query.getCurrentUser().isConsumer: consumer = bene_query.getCurrentConsumer() if consumer: if consumer.hasProduct(product.key()): template_values['in_closet'] = True template_values['rem_closet_link'] = '/removefromcloset?%s' % urllib.urlencode({'id': ID}) else: template_values['add_closet'] = True template_values['add_closet_link'] = '/addtocloset?%s' % urllib.urlencode({'id': ID}) template_values['num_configs'] = product.numConfigs() template_values['configs'] = product.getConfigs() template_values['num_products'] = product.numProducts() template_values['closet_count'] = product.getClosetCount() path = os.path.join(os.path.dirname(__file__), 'viewproduct.html') self.response.out.write(template.render(path, template_values).decode('utf-8')) return
def get(self): # Get the id from the get parameter ID = bene_util.sanitize(self.request.get('id')) if not ID: ''' TODO: If no ID sent, default to page with all products? ''' self.redirect('/') return # Fetch the data for this product producer = db.get(ID) ''' an error in getting the producer will be redirected to exception handler''' # Make a dictionary for template template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = producer.key() template_values['producer'] = producer workers = producer.getWorkers() template_values['workers'] = workers num_workers = 0 if workers: for worker in workers: if worker: num_workers += 1 if num_workers == 0: template_values['no_workers'] = True else: template_values['no_workers'] = False locations = producer.getLocations() template_values['locations'] = locations num_workers_with_loc = 0 if locations: for location in locations: if location: _workers = location.getWorkers() if _workers: for worker in _workers: if worker: num_workers_with_loc += 1 template_values[ 'num_worker_no_location'] = num_workers - num_workers_with_loc template_values['can_edit_local'] = False user = users.get_current_user() if user: if producer.owner == user: template_values['can_edit_local'] = True path = os.path.join(os.path.dirname(__file__), 'viewproducerworkers.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return if bene_query.getCurrentUser( ).isConsumer: # consumers can't access this self.redirect('/') return _producer = bene_query.getCurrentProducer() if _producer == None: # no producer signed up, so ask to sign up self.redirect('/') return if not _producer.verified: # if producer is not verified self.redirect('/producerhome?%s' % urllib.urlencode({'verify': True})) return ID = bene_util.sanitize(self.request.get('id')) if not ID: ''' TODO: If no ID sent? ''' self.redirect('/') return _productgeneric = db.get(ID) ''' an error in getting the product will be redirected to exception handler''' if _productgeneric.owner != user: # if current user doesn't own product self.redirect('/producerhome?%s' % urllib.urlencode({'not_owner': True})) return template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = ID template_values['path'] = "message" template_values['num_sent'] = _productgeneric.getClosetCount() if _productgeneric.isConfig: template_values['name'] = _productgeneric.getName() template_values['is_config'] = True template_values['config'] = _productgeneric template_values['line'] = _productgeneric.getProductLine() elif _productgeneric.isLine: template_values['name'] = _productgeneric.name template_values['is_line'] = True template_values['line'] = _productgeneric path = os.path.join(os.path.dirname(__file__), 'producermsg.html') self.response.out.write(template.render(path, template_values)) return
def get(self): ID = bene_util.sanitize(self.request.get('id')) if not ID: ''' TODO: if no id is sent, defaults to a page with all workers? ''' self.redirect('/') worker = db.get(ID) ''' an error in getting the worker will be redirected to exception handler''' # Make a dictionary for template name = worker.name location = worker.getLocation() profile = worker.profile picture = worker.getPicture() producer = worker.getProducer() products = worker.getProductLines() if location: if location.location: latitude = location.location.lat longitude = location.location.lon else: latitude = None longitude = None else: latitude = None longitude = None template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = worker.key() template_values['worker'] = worker template_values['name'] = name template_values['picture'] = picture template_values['profile'] = profile template_values['location'] = location template_values['producer'] = producer template_values['products'] = products template_values['latitude'] = latitude template_values['longitude'] = longitude template_values['url'] = self.request.url template_values['path'] = "worker" template_values['can_edit'] = False user = users.get_current_user() if user: if worker.owner == user and bene_query.getCurrentUser().isProducer: template_values['can_edit'] = True template_values[ 'edit_link'] = '/editworker?%s' % urllib.urlencode( {'id': ID}) path = os.path.join(os.path.dirname(__file__), 'viewworker.html') self.response.out.write(template.render(path, template_values)) return
def get(self): ID = self.request.get('id') if not ID: ''' TODO: if no id is sent, defaults to a page with all workers? ''' self.redirect('/') worker = db.get(ID) ''' an error in getting the worker will be redirected to exception handler''' # Make a dictionary for template name = worker.name factory = worker.getFactory() profile = worker.profile picture = worker.getPicture() producer = worker.getProducer() products = worker.getProducts() if factory.location: latitude = factory.location.lat longitude = factory.location.lon else: latitude = None longitude = None template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = ID template_values['name'] = name template_values['picture'] = picture template_values['profile'] = profile template_values['factory'] = factory template_values['producer'] = producer template_values['products'] = products template_values['latitude'] = latitude template_values['longitude'] = longitude template_values['url'] = self.request.url if worker.getPicture(): template_values['has_image'] = True else: template_values['has_image'] = False template_values['can_edit'] = False user = users.get_current_user() if user: if worker.owner == user: template_values['can_edit'] = True template_values['edit_link'] = '/editworker?%s' % urllib.urlencode({'id': ID}) path = os.path.join(os.path.dirname(__file__), 'viewworker.html') self.response.out.write(template.render(path, template_values)) return
def get(self): ID = bene_util.sanitize(self.request.get('id')) if not ID: ''' TODO: If no ID sent, default to page with all locations? ''' self.redirect('/') return location = db.get(ID) ''' an error in getting the location will be redirected to exception handler''' # Make a dictionary for template name = location.name producer = location.getProducer() productlist = location.getProductLines() workers = location.getWorkers() address = location.address if location.location: latitude = location.location.lat longitude = location.location.lon else: latitude = None longitude = None template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = ID template_values['name'] = name template_values['location'] = location template_values['producer'] = producer template_values['products'] = productlist template_values['workers'] = workers template_values['latitude'] = latitude template_values['longitude'] = longitude template_values['url'] = self.request.url template_values['address'] = address template_values['qr_url'] = self.request.url.replace('view', 'qr') template_values['path'] = "location" template_values['can_edit'] = False user = users.get_current_user() if user: if location.owner == user and bene_query.getCurrentUser( ).isProducer: template_values['can_edit'] = True template_values[ 'edit_link'] = '/editlocation?%s' % urllib.urlencode( {'id': ID}) path = os.path.join(os.path.dirname(__file__), 'viewlocation.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to signin first self.redirect('/?signin=True') return if not users.is_current_user_admin(): # need to be admin to create badge self.redirect('/') return # display form to create badge template_values = bene_util.initTemplate(self.request.uri) path = os.path.join(os.path.dirname(__file__), 'createbadge.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return if bene_query.getCurrentUser( ).isConsumer: # consumers can't access this self.redirect('/') return _producer = bene_query.getCurrentProducer() if _producer == None: # no producer signed up, so ask to sign up self.redirect('/') return if not _producer.verified: # if producer is not verified self.redirect('/producerhome?%s' % urllib.urlencode({'verify': True})) return ID = bene_util.sanitize(self.request.get('id')) if not ID: ''' TODO: If no ID sent, default to page with all locations? ''' self.redirect('/') return _location = db.get(ID) ''' an error in getting the location will be redirected to exception handler''' if _location.owner != user: # if not owner of location self.redirect('/producerhome?%s' % urllib.urlencode({'not_owner': True})) return template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = ID template_values['name_old'] = _location.name template_values['address_old'] = _location.address template_values['unique_old'] = _location.unique template_values['description_old'] = _location.description template_values['path'] = "location" template_values['cropentity'] = _location path = os.path.join(os.path.dirname(__file__), 'editlocation.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return if bene_query.getCurrentUser().isConsumer: # consumers can't access this self.redirect('/') return _producer = bene_query.getCurrentProducer() if _producer == None: # no producer signed up, so ask to sign up self.redirect('/') return # Make a dictionary for template name = _producer.name description = _producer.description products = _producer.getProducts() workers = _producer.getWorkers() factories = _producer.getFactories() template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = _producer.key() template_values['name'] = name template_values['description'] = description template_values['factories'] = factories template_values['products'] = products template_values['producer'] = _producer template_values['workers'] = workers template_values['url'] = self.request.url template_values['can_edit'] = False user = users.get_current_user() if user: if _producer.owner == user: template_values['can_edit'] = True template_values['edit_link'] = '/editproducer' if _producer.getPicture(): template_values['has_image'] = True else: template_values['has_image'] = False path = os.path.join(os.path.dirname(__file__), 'viewproducer.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to signin first self.redirect('/?signin=True') return if not users.is_current_user_admin( ): # need to be admin to create badge self.redirect('/') return # display form to create badge template_values = bene_util.initTemplate(self.request.uri) path = os.path.join(os.path.dirname(__file__), 'createbadge.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return if bene_query.getCurrentUser().isProducer: # producers can't do this self.redirect('/') return if bene_query.getCurrentConsumer() != None: # has consumer page self.redirect('/') return template_values = bene_util.initTemplate(self.request.uri) path = os.path.join(os.path.dirname(__file__), 'createconsumer.html') self.response.out.write(template.render(path, template_values)) return
def get(self): ID = self.request.get('id') if not ID: ''' TODO: If no ID sent, default to page with all factories? ''' self.redirect('/') return factory = db.get(ID) ''' an error in getting the factory will be redirected to exception handler''' # Make a dictionary for template name = factory.name producer = factory.getProducer() productlist = factory.getProducts() workers = factory.getWorkers() address = factory.address if factory.location: latitude = factory.location.lat longitude = factory.location.lon else: latitude = None longitude = None template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = ID template_values['name'] = name template_values['producer'] = producer template_values['products'] = productlist template_values['workers'] = workers template_values['latitude'] = latitude template_values['longitude'] = longitude template_values['url'] = self.request.url template_values['address'] = address template_values['qr_url'] = self.request.url.replace('view','qr') template_values['can_edit'] = False user = users.get_current_user() if user: if factory.owner == user: template_values['can_edit'] = True template_values['edit_link'] = '/editfactory?%s' % urllib.urlencode({'id' : ID}) path = os.path.join(os.path.dirname(__file__), 'viewfactory.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return if bene_query.getCurrentUser().isProducer: # producers can't do this self.redirect('/') return if bene_query.getCurrentConsumer() != None: # has consumer page self.redirect('/') return template_values = bene_util.initTemplate(self.request.uri) template_values['email_public_old'] = bene_util.getEmail(user) path = os.path.join(os.path.dirname(__file__), 'createconsumer.html') self.response.out.write(template.render(path, template_values)) return
def get(self): ID = self.request.get('id') if not ID: ''' TODO: if no id is sent, defaults to a page with all producers? ''' self.redirect('/') return producer = db.get(ID) ''' an error in getting the producer will be redirected to exception handler''' # Make a dictionary for template name = producer.name description = producer.description products = producer.getProducts() workers = producer.getWorkers() factories = producer.getFactories() template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = ID template_values['name'] = name template_values['description'] = description template_values['factories'] = factories template_values['products'] = products template_values['producer'] = producer template_values['workers'] = workers template_values['url'] = self.request.url template_values['can_edit'] = False user = users.get_current_user() if user: if producer.owner == user: template_values['can_edit'] = True template_values['edit_link'] = '/editproducer' if producer.getPicture(): template_values['has_image'] = True else: template_values['has_image'] = False path = os.path.join(os.path.dirname(__file__), 'viewproducer.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return if bene_query.getCurrentUser( ).isConsumer: # consumers can't access this self.redirect('/') return _producer = bene_query.getCurrentProducer() if _producer == None: # no producer signed up, so ask to sign up self.redirect('/') return if not _producer.verified: # if producer is not verified self.redirect('/producerhome?%s' % urllib.urlencode({'verify': True})) return template_values = bene_util.initTemplate(self.request.uri) _locations = _producer.getLocations() template_values['locations'] = _locations count = 0 if _locations: for location in _locations: if location: count += 1 if len(location.name) > 10: count += 1 if not count: count = 1 template_values['pathheight'] = count * 40 if count == 0: template_values['no_locations'] = True elif count > 0: template_values['no_locations'] = False template_values['workers'] = _producer.getWorkers() template_values['badges'] = entities.Badge.all() template_values['path'] = "product" path = os.path.join(os.path.dirname(__file__), 'createproduct.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return if bene_query.getCurrentUser().isConsumer: # consumers can't access this self.redirect('/') return _producer = bene_query.getCurrentProducer() if _producer == None: # no producer signed up, so ask to sign up self.redirect('/') return template_values = bene_util.initTemplate(self.request.uri) path = os.path.join(os.path.dirname(__file__), 'producerhome.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # if not signed in self.redirect('/?signin=True') return if bene_query.getCurrentUser().isProducer: # producer can't get to consumer home page self.redirect('/') return _consumer = bene_query.getCurrentConsumer() if _consumer == None: # if consumer page doesn't exist, need to create one self.redirect('/createconsumer?%s' % urllib.urlencode({'redirect': 'consumerhome', 'msg': True})) return # if setup done, then show home page template_values = bene_util.initTemplate(self.request.uri) path = os.path.join(os.path.dirname(__file__), 'consumerhome.html') self.response.out.write(template.render(path, template_values)) return
def get(self): ID = bene_util.sanitize(self.request.get('id')) if not ID: ''' TODO: if no id is sent, defaults to a page with all producers? ''' self.redirect('/') return _producer = db.get(ID) ''' an error in getting the producer will be redirected to exception handler''' # Make a dictionary for template name = _producer.name description = _producer.description product_lines = _producer.getProductLines()[0:4] workers = _producer.getWorkers()[0:4] locations = _producer.getLocations()[0:4] email_public = _producer.email_public template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = _producer.key() template_values['name'] = name template_values['email_public'] = email_public template_values['description'] = description template_values['locations'] = locations template_values['product_lines'] = product_lines template_values['producer'] = _producer template_values['workers'] = workers template_values['url'] = self.request.url template_values['path'] = self.request.path template_values['can_edit'] = False user = users.get_current_user() if user: if _producer.owner == user and bene_query.getCurrentUser( ).isProducer: template_values['can_edit'] = True template_values['edit_link'] = '/editproducer' path = os.path.join(os.path.dirname(__file__), 'viewproducer.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return if bene_query.getCurrentUser().isConsumer: # consumers can't access this self.redirect('/') return _producer = bene_query.getCurrentProducer() if _producer == None: # no producer signed up, so ask to sign up self.redirect('/') return if not _producer.verified: # if producer is not verified self.redirect('/producerhome?%s' % urllib.urlencode({'verify': True})) return ID = self.request.get('id') if not ID: ''' TODO: If no ID sent, default to page with all factories? ''' self.redirect('/') return _factory = db.get(ID) ''' an error in getting the factory will be redirected to exception handler''' if _factory.owner != user: # if not owner of factory self.redirect('/producerhome?%s' % urllib.urlencode({'not_owner': True})) return template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = ID template_values['name_old'] = _factory.name template_values['address_old'] = _factory.address template_values['unique_old'] = _factory.unique path = os.path.join(os.path.dirname(__file__), 'editfactory.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return if bene_query.getCurrentUser( ).isConsumer: # consumers can't access this self.redirect('/') return _producer = bene_query.getCurrentProducer() if _producer == None: # no producer signed up, so ask to sign up self.redirect('/') return template_values = bene_util.initTemplate(self.request.uri) template_values['path'] = self.request.path path = os.path.join(os.path.dirname(__file__), 'producerhome.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if user: # if user signed in signed_in_user = bene_query.getCurrentUser() if signed_in_user.isProducer: if not bene_query.getCurrentProducer(): # if producer page doesn't exist, need to create one self.redirect('/createproducer?%s' % urllib.urlencode({'redirect': 'producerhome', 'msg': True})) else: # if setup done, then go to home page self.redirect('/producerhome') return else: if not bene_query.getCurrentConsumer(): self.redirect('/createconsumer?%s' % urllib.urlencode({'redirect': 'consumerhome', 'msg': True})) return else: self.redirect('/consumerhome') return else: # otherwise, show button for signing in and searching template_values = bene_util.initTemplate(self.request.uri) path = os.path.join(os.path.dirname(__file__), 'home.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # if not signed in self.redirect('/?signin=True') return if bene_query.getCurrentUser( ).isProducer: # producer can't get to consumer home page self.redirect('/') return _consumer = bene_query.getCurrentConsumer() if _consumer == None: # if consumer page doesn't exist, need to create one self.redirect('/createconsumer?%s' % urllib.urlencode({ 'redirect': 'consumerhome', 'msg': True })) return # if setup done, then show home page template_values = bene_util.initTemplate(self.request.uri) path = os.path.join(os.path.dirname(__file__), 'consumerhome.html') self.response.out.write(template.render(path, template_values)) return
def get(self): ID = bene_util.sanitize(self.request.get('id')) if not ID: ''' TODO: if no id is sent, defaults to a page with all producers? ''' self.redirect('/') return consumer = db.get(ID) ''' an error in getting the consumer will be redirected to exception handler''' # Make a dictionary for template name = consumer.name profile = consumer.profile email_public = consumer.email_public template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = ID template_values['consumer'] = consumer _products = consumer.getProducts() if _products: template_values['products'] = _products[0:4] template_values['name'] = name template_values['profile'] = profile template_values['email_public'] = email_public template_values['path'] = self.request.path template_values['can_edit'] = False user = users.get_current_user() if user: if consumer.owner == user: template_values['can_edit'] = True template_values['edit_link'] = '/editconsumer' path = os.path.join(os.path.dirname(__file__), 'viewconsumer.html') self.response.out.write(template.render(path, template_values)) return
def get(self): # Get the id from the get parameter ID = bene_util.sanitize(self.request.get('id')) if not ID: ''' TODO: If no ID sent, default to page with all products? ''' self.redirect('/') return # Fetch the data for this product producer = db.get(ID) ''' an error in getting the producer will be redirected to exception handler''' # Make a dictionary for template template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = ID template_values['producer'] = producer _locations = producer.getLocations() template_values['locations'] = _locations if _locations.get(): template_values['has_locations'] = True else: template_values['has_locations'] = False template_values['path'] = "location" template_values['can_edit_local'] = False user = users.get_current_user() if user: if producer.owner == user and bene_query.getCurrentUser( ).isProducer: template_values['can_edit_local'] = True path = os.path.join(os.path.dirname(__file__), 'viewproducerlocations.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return if bene_query.getCurrentUser().isConsumer: # consumers can't access this self.redirect('/') return _producer = bene_query.getCurrentProducer() if _producer == None: # no producer signed up, so ask to sign up self.redirect('/') return if not _producer.verified: # if producer is not verified self.redirect('/producerhome?%s' % urllib.urlencode({'verify': True})) return template_values = bene_util.initTemplate(self.request.uri) path = os.path.join(os.path.dirname(__file__), 'createlocation.html') template_values['path'] = "location" self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return if bene_query.getCurrentUser().isProducer: # producers aren't allowed here self.redirect('/') return _consumer = bene_query.getCurrentConsumer(); if _consumer == None: # no consumer page, so create one self.redirect('/') return template_values = bene_util.initTemplate(self.request.uri) template_values['name_old'] = _consumer.name template_values['profile_old'] = _consumer.profile path = os.path.join(os.path.dirname(__file__), 'editconsumer.html') self.response.out.write(template.render(path, template_values)) return '''
def get(self): template_values = bene_util.initTemplate(self.request.uri) path = os.path.join(os.path.dirname(__file__), "about.html") self.response.out.write(template.render(path, template_values))
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return if bene_query.getCurrentUser( ).isConsumer: # consumers can't access this self.redirect('/') return _producer = bene_query.getCurrentProducer() if _producer == None: # no producer signed up, so ask to sign up self.redirect('/') return if not _producer.verified: # if producer is not verified self.redirect('/producerhome?%s' % urllib.urlencode({'verify': True})) return ID = bene_util.sanitize(self.request.get('id')) if not ID: ''' TODO: If no ID sent? ''' self.redirect('/') return _productconfig = db.get(ID) ''' an error in getting the product will be redirected to exception handler''' if _productconfig.owner != user: # if current user doesn't own product self.redirect('/producerhome?%s' % urllib.urlencode({'not_owner': True})) return _productline = _productconfig.getProductLine() template_values = bene_util.initTemplate(self.request.uri) template_values['path'] = "product" template_values['product'] = _productline template_values['cropentity'] = _productline template_values['id'] = ID template_values['name_old'] = _productline.name template_values['description_old'] = _productline.description template_values['configname_old'] = _productconfig.config_name template_values['num_products'] = _productconfig.numProducts() template_values['display_amazon'] = _productconfig.displayAmazon template_values['storelink'] = _productconfig.store_link # locations template_values['no_locations'] = True _locations_old = _productconfig.getLocations() if _locations_old: template_values['no_locations'] = False template_values['locations_old'] = _locations_old # workers template_values['no_workers'] = True _workers_old = _productconfig.getWorkers() if _workers_old.get(): template_values['no_workers'] = False template_values['workers_old'] = _workers_old #badges template_values['no_badges'] = True _badges_old = _productconfig.getBadges() if _badges_old: template_values['no badges'] = False template_values['badges_old'] = _badges_old ''' TODO: Find better way to do below. For some reason equality doesn't work implicitly. Need to explicitly check equality of key() ''' template_values['locations'] = [] _locations = _producer.getLocations() count = 0 if _locations: for location in _locations: if location: add = True count += 1 if len(location.name) > 10: count += 1 if _locations_old: for location_old in _locations_old: if location_old: if location_old.key() == location.key(): add = False if add: template_values['locations'].append(location) template_values['no_locations'] = False if not count: count = 1 template_values['pathheight'] = count * 40 template_values['workers'] = [] _workers = _producer.getWorkers() if _workers: for worker in _workers: if worker: add = True if _workers_old: for worker_old in _workers_old: if worker_old: if worker_old.key() == worker.key(): add = False if add: template_values['workers'].append(worker) template_values['no_workers'] = False template_values['badges'] = [] _badges = entities.Badge.all() if _badges: for badge in _badges: if badge: add = True if _badges_old: for badge_old in _badges_old: if badge_old.key() == badge.key(): add = False if add: template_values['badges'].append(badge) template_values['no badges'] = False path = os.path.join(os.path.dirname(__file__), 'editconfig.html') self.response.out.write(template.render(path, template_values)) return
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return if bene_query.getCurrentUser().isConsumer: # consumers can't access this self.redirect('/') return _producer = bene_query.getCurrentProducer() if _producer == None: # no producer signed up, so ask to sign up self.redirect('/') return if not _producer.verified: # if producer is not verified self.redirect('/producerhome?%s' % urllib.urlencode({'verify': True})) return ID = self.request.get('id') if not ID: ''' TODO: If no ID sent? ''' self.redirect('/') return _product = db.get(ID) ''' an error in getting the product will be redirected to exception handler''' if _product.owner != user: # if current user doesn't own product self.redirect('/producerhome?%s' % urllib.urlencode({'not_owner': True})) return _factories_old = _product.getFactories() _workers_old = _product.getWorkers() _badges_old = _product.getBadges() template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = ID template_values['factories_old'] = _factories_old template_values['workers_old'] = _workers_old template_values['badges_old'] = _badges_old template_values['unique_old'] = _product.unique template_values['name_old'] = _product.name ''' TODO: Find better way to do below. For some reason equality doesn't work implicitly. Need to explicitly check equality of key() ''' template_values['factories'] = [] _factories = _producer.getFactories() if _factories: for factory in _factories: if factory: add = True if _factories_old: for factory_old in _factories_old: if factory_old: if factory_old.key() == factory.key(): add = False if add: template_values['factories'].append(factory) template_values['workers'] = [] _workers = _producer.getWorkers() if _workers: for worker in _workers: if worker: add = True if _workers_old: for worker_old in _workers_old: if worker_old: if worker_old.key() == worker.key(): add = False if add: template_values['workers'].append(worker) template_values['badges'] = [] _badges = entities.Badge.all() if _badges: for badge in _badges: if badge: add = True if _badges_old: for badge_old in _badges_old: if badge_old.key() == badge.key(): add = False if add: template_values['badges'].append(badge) path = os.path.join(os.path.dirname(__file__), 'editproduct.html') self.response.out.write(template.render(path, template_values)) return
def get(self): # Get the id from the get parameter ID = bene_util.sanitize(self.request.get('id')) if not ID: ''' TODO: If no ID sent, default to page with all products? ''' self.redirect('/') return # Fetch the data for this product productconfig = db.get(ID) ''' an error in getting the product will be redirected to exception handler''' productline = productconfig.getProductLine() # Make a dictionary for template template_values = bene_util.initTemplate(self.request.uri) # generic template_values['id'] = ID template_values['name'] = productconfig.getName() template_values['is_config'] = True template_values['is_unit'] = False template_values['producer'] = productconfig.getProducer() template_values['rating'] = productconfig.getRoundedRating() template_values['productconfig'] = productconfig template_values['config_key'] = productconfig.key() # urls template_values['url'] = self.request.url template_values['path'] = "product" template_values['qr_url'] = self.request.url.replace('viewpath','qr') template_values['image_url'] = self.request.url.replace('viewconfig', 'productimage') template_values['comment_url'] = '%s/viewproduct?%s' % (self.request.host_url, urllib.urlencode({'id': productline.key()})) # primary location _location = productconfig.getPrimaryLocation() if _location and _location.location: latitude = _location.location.lat longitude = _location.location.lon else: latitude = None longitude = None template_values['latitude'] = latitude template_values['longitude'] = longitude template_values['location'] = _location # worker to display _workers = productconfig.getWorkers() if _workers.get(): template_values['has_workers'] = True workerlist = [] for _worker in _workers: if _worker: workerlist.append(_worker) template_values['has_multiple_workers'] = len(workerlist) > 1 template_values['num_other_workers'] = len(workerlist)-1 template_values['more_than_one_other'] = len(workerlist) > 2 template_values['worker'] = workerlist[randint(0, len(workerlist)-1)] else: template_values['has_workers'] = False # badges _badges = productconfig.getBadges() if _badges: template_values['badges'] = _badges template_values['has_badges'] = True else: template_values['has_badges'] = False # interaction - producer template_values['can_edit'] = False user = users.get_current_user() if user: if productconfig.owner == user and bene_query.getCurrentUser().isProducer: template_values['enable_rating'] = False template_values['can_edit'] = True template_values['edit_link'] = '/editconfig?%s' % urllib.urlencode({'id': productconfig.key()}) template_values['show_qr'] = False # interaction - consumer template_values['in_closet'] = False template_values['add_closet'] = False if user: if bene_query.getCurrentUser().isConsumer: template_values['enable_rating'] = True consumer = bene_query.getCurrentConsumer() if consumer: if consumer.hasProduct(productconfig.key()): template_values['in_closet'] = True template_values['rem_closet_link'] = '/removefromcloset?%s' % urllib.urlencode({'id': ID}) else: template_values['add_closet'] = True template_values['add_closet_link'] = '/addtocloset?%s' % urllib.urlencode({'id': ID}) template_values['num_products'] = productconfig.numProducts() template_values['closet_count'] = productconfig.getClosetCount() num_configs = productline.numConfigs() if num_configs == 1: template_values['last_config'] = True if num_configs > 1: template_values['otherconfig'] = True if (num_configs > 2): template_values['more_than_one_other_config'] = True template_values['num_other_configs'] = num_configs - 1 template_values['config_link'] = '/view?%s' % urllib.urlencode({'id': productline.key()}) if productconfig.displayAmazon: template_values['display_amazon'] = True # Amazon stuff amazon = bottlenose.Amazon("AKIAIT4OSXQMYQB2XLUQ", "RPzfxhl7eEa/NiIcmkNinQ8OG6kTW65M6UrRqFgD", "BeneTag") response = amazon.ItemSearch(Keywords = productline.name + " " + productconfig.getProducer().name, ResponseGroup = "Offers,Images,ItemAttributes,Variations", SearchIndex="All") dom = xml.dom.minidom.parseString(response) totalres = int(dom.getElementsByTagName("TotalResults")[0].firstChild.nodeValue) if totalres > 0: if dom.getElementsByTagName("ItemAttributes"): if dom.getElementsByTagName("ItemAttributes")[0].getElementsByTagName("Title"): product_name = dom.getElementsByTagName("ItemAttributes")[0].getElementsByTagName("Title")[0].firstChild.nodeValue if productline.name in product_name: if productconfig.getProducer().name in product_name: if dom.getElementsByTagName("DetailPageURL"): template_values['AmazonURL'] = dom.getElementsByTagName("DetailPageURL")[0].firstChild.nodeValue if dom.getElementsByTagName("OfferSummary"): if dom.getElementsByTagName("OfferSummary")[0].getElementsByTagName("LowestNewPrice"): if dom.getElementsByTagName("OfferSummary")[0].getElementsByTagName("LowestNewPrice")[0].getElementsByTagName("FormattedPrice"): template_values['price'] = dom.getElementsByTagName("OfferSummary")[0].getElementsByTagName("LowestNewPrice")[0].getElementsByTagName("FormattedPrice")[0].firstChild.nodeValue else: template_values['display_amazon'] = False storeLink = productconfig.store_link if storeLink: template_values['has_store_link'] = True template_values['storeName'] = storeLink.name template_values['storeUrl'] = storeLink.url template_values['storePrice'] = storeLink.price else: template_values['has_store_link'] = False # render path = os.path.join(os.path.dirname(__file__), 'viewconfig.html') self.response.out.write(template.render(path, template_values)) return