def doesSimilarProductExist(product_add): ''' DON'T USE THIS. Use doesProductExist() ''' # checks for same product name producer = bene_query.getCurrentProducer() if producer: products = bene_query.getCurrentProducer().getProducts().filter('name =', product_add.name) for product in products: if product: return True return False
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): 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 post(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: # already has a producer page self.redirect('/') return _name = self.request.get('name') _picture = self.request.get('picture') _description = self.request.get('description') p = entities.Producer(name = _name, email=bene_util.getEmail(user), owner=user, description=_description, verified=False) p.addPicture(_picture) p.put() self.redirect('/') 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): 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 post(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 _factory.name = self.request.get('name') _factory.address = self.request.get('address') _unique_save = _factory.unique _factory.unique = self.request.get('unique') if bene_util.doesFactoryExist(_factory) and _unique_save != _factory.unique : # if factory with same unique exists self.redirect('/editfactory?%s' % (urllib.urlencode({'id' : ID, 'repeatedit' : True}))) return _picture = self.request.get('picture') _factory.addPicture(_picture) _location = self.request.get('location') fields = _location.split(',') if len(fields) == 2: try: lat = float(fields[0]) lon = float(fields[1]) gp = db.GeoPt(lat, lon) except ValueError: gp = None else: gp = None _factory.location = gp _factory.put() self.redirect('/viewfactory?%s' % urllib.urlencode({'id': ID})) return
def post(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 _name = bene_util.sanitize(self.request.get('name')) _description = bene_util.sanitize(self.request.get('description')) _picture = self.request.get('picturedata') _email_public = self.request.get('email') _producer.name = _name _producer.description = _description _producer.email_public = _email_public _producer.addPicture(_picture) _producer.put() self.redirect('/myprofile') 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['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.urldecode(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 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 ? ''' self.redirect('/') return _worker = db.get(ID) ''' an error in getting the worker will be redirected to exception handler''' db.delete(ID) self.redirect('/myworkers') return
def post(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 _name = self.request.get('name') _description = self.request.get('description') _picture = self.request.get('picture') _producer.name = _name _producer.description = _description _producer.addPicture(_picture) _producer.put() self.redirect('/viewproducer?%s' % urllib.urlencode({'id': _producer.key()})) 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 post(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: # already has a producer page self.redirect('/') return _name = bene_util.sanitize(self.request.get('name')) _picture = self.request.get('picturedata') _description = bene_util.sanitize(self.request.get('description')) _email_public = self.request.get('email') p = entities.Producer(name=_name, email=bene_util.getEmail(user), email_public=_email_public, owner=user, description=_description, verified=False) p.addPicture(_picture) p.put() self.redirect('/producerhome?%s' % urllib.urlencode({'verifyone': True})) 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 post(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 _name = self.request.get('name') _factory = self.request.get('factory') _workers = self.request.get_all('workers') _badges = self.request.get_all('badges') _picture = self.request.get('picture') _unique = self.request.get('unique') p = entities.Product(name=_name, unique=_unique, owner=user) p.addPicture(_picture) if _factory: p.addFactory(db.get(_factory)) p.addProducer(_producer) for _badge in _badges: p.addBadge(_badge) if bene_util.doesProductExist(p): # already exists self.redirect('/createproduct?%s' % urllib.urlencode({'repeat': True})) return p.put() # add product to workers if _workers: key = p.key() for _worker in _workers: if _worker: worker = db.get(_worker) worker.addProduct(key) worker.put() if self.request.get('more'): # want to add more self.redirect('/createproduct?%s' % urllib.urlencode({'added': True})) return # otherwise redirect to product page self.redirect('/mobilepage?%s' % urllib.urlencode({'id' : p.key()}))
def post(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 _name = self.request.get('name') _address = self.request.get('address') _location = self.request.get('location') _unique = self.request.get('unique') _picture = self.request.get('picture') fields = _location.split(',') if len(fields) == 2: try: lat = float(fields[0]) lon = float(fields[1]) gp = db.GeoPt(lat, lon) except ValueError: gp = None else: gp = None f = entities.Factory(name=_name, address=_address, location=gp, unique=_unique, owner=user) f.addProducer(_producer) f.addPicture(_picture) if bene_util.doesFactoryExist(f): self.redirect('/createfactory?%s' % urllib.urlencode({'repeat': True})) return f.put() if self.request.get('more'): # want to add more self.redirect('/createfactory?%s' % urllib.urlencode({'added': True})) return # otherwise redirect to factory page self.redirect('/viewfactory?%s' % urllib.urlencode({'id' : f.key()}))
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 doesSimilarFactoryExist(factory_add): ''' DON'T USE THIS. Use doesFactoryExist() ''' # checks for same factory name producer = bene_query.getCurrentProducer() if producer: factories = producer.getFactories().filter('name = ', factory_add.name) for factory in factories: if factory : return True return False
def doesExactProductExist(product_add): ''' DON'T USE THIS. Use doesProductExist() ''' if product_add.unique: producer = bene_query.getCurrentProducer() if producer: products = producer.getProducts().filter('unique =', product_add.unique) for product in products: if product: return True return False
def doesSimilarWorkerExist(worker_add): ''' DON'T USE THIS. Use doesWorkerExist() ''' # checks for same worker name producer = bene_query.getCurrentProducer() if producer: workers = producer.getWorkers().filter('name =', worker_add.name) for worker in workers: if worker: return True return False
def post(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 _text = bene_util.sanitize(self.request.get('text')) msg = entities.MessageFromProducer( text=_text, sender=_producer, receiver=_productgeneric, num_receivers=_productgeneric.getClosetCount()) msg.put() msg_key = msg.key() _consumers = _productgeneric.getConsumers() if _consumers: for _consumer in _consumers: if _consumer: _consumer.addReceivedMsg(msg_key) _consumer.has_unread += 1 _consumer.put() self.redirect('/myoutbox') return
def post(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) if not _worker: # doesn't exist template_values = {} path = os.path.join(os.path.dirname(__file__), 'not_found.html') self.response.out.write(template.render(path, template_values)) return 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 _worker.name = self.request.get('name') _worker.profile = self.request.get('profile') _unique_save = _worker.unique _worker.unique = self.request.get('unique') if bene_util.doesWorkerExist(_worker) and _unique_save != _worker.unique: # if worker already exists self.redirect('/editworker?%s' % (urllib.urlencode({'id' : ID, 'repeatedit' : True}))) return _factory = self.request.get('factory') if _factory: _worker.factory = db.get(_factory) _picture = self.request.get('picture') _worker.addPicture(_picture) _worker.put() self.redirect('/viewworker?%s' % urllib.urlencode({'id': ID})) 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): user = users.get_current_user() if not user: # need to sign in self.redirect(users.create_login_url(self.request.uri)) return producer = bene_util.sanitize(self.request.get('producer')) consumer = bene_util.sanitize(self.request.get('consumer')) u = bene_query.getCurrentUser() if not u: # no user exists if producer and not consumer: # make person a producer only in most restricted case u = entities.User(email=bene_util.getEmail(user), owner=user, isConsumer=False, isProducer=True) u.put() self.redirect('/createproducer') return else: # all other cases, make consumer u = entities.User(email=bene_util.getEmail(user), owner=user, isConsumer=True, isProducer=False) u.put() self.redirect('/createconsumer') return if producer and not consumer: # signed in producer if u.isConsumer: # if previously signed in as consumer u.isConsumer = False u.isProducer = True u.put() if bene_query.getCurrentProducer( ) == None: # no producer page, so create one self.redirect('/createproducer') return else: # already has producer page, so redirect self.redirect('/producerhome') return else: # signed in consumer if u.isProducer: # if previously signed in as producer u.isConsumer = True u.isProducer = False u.put() if bene_query.getCurrentConsumer( ) == None: # no consumer page, so create on self.redirect('/createconsumer') return else: # already has consumer page, so redirect self.redirect('/consumerhome') return
def post(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 _worker.name = self.request.get('name') _worker.profile = self.request.get('profile') _unique_save = _worker.unique _worker.unique = self.request.get('unique') if bene_util.doesWorkerExist(_worker) and _unique_save != _worker.unique: # if worker already exists self.redirect('/editworker?%s' % (urllib.urlencode({'id' : ID, 'repeatedit' : True}))) return _factory = self.request.get('factory') if _factory: _worker.factory = db.get(_factory) _picture = self.request.get('picture') _worker.addPicture(_picture) _worker.put() self.redirect('/viewworker?%s' % urllib.urlencode({'id': ID})) return
def post(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 _productline = db.get(ID) ''' an error in getting the product will be redirected to exception handler''' if _productline.owner != user: # if current user doesn't own product self.redirect('/producerhome?%s' % urllib.urlencode({'not_owner': True})) return # edit product line _picture = self.request.get('picturedata') _name = bene_util.sanitize(self.request.get('name')) _description = bene_util.sanitize(self.request.get('description')) if _name != _productline.name or _description != _productline.description or _picture: _name_save = _productline.name _productline.name = _name _productline.description = _description if bene_util.doesSimilarProductLineExist(_productline) and _name_save != _productline.name: # already exists self.redirect('/editproduct?%s' % urllib.urlencode({'repeatedit': True, 'id': ID})) return _productline.addPicture(_picture) _productline.put() self.redirect('/view?%s' % urllib.urlencode({'id': ID})) return
def doesExactFactoryExist(factory_add): ''' DON'T USE THIS. Use doesFactoryExist() ''' if factory_add.unique: producer = bene_query.getCurrentProducer() if producer: # if two have same unique ID factories = producer.getFactories().filter('unique = ', factory_add.unique) for factory in factories: if factory: return True # if other factory has no unique ID but same name factories = producer.getFactories().filter('name = ', factory_add.name) for factory in factories: if factory : if not factory.unique: return True return False
def doesExactWorkerExist(worker_add): ''' DON'T USE THIS. Use doesWorkerExist() ''' if worker_add.unique: producer = bene_query.getCurrentProducer() if producer: # if two workers have same unique ID workers = producer.getWorkers().filter('unique =', worker_add.unique) for worker in workers: if worker: return True # if other worker has no unique ID but same name workers = producer.getWorkers().filter('name =', worker_add.name) for worker in workers: if worker: if not worker.unique: return True return False
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 post(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 _name = self.request.get('name') _factory = self.request.get('factory') _picture = self.request.get('picture') _profile = self.request.get('profile') _unique = self.request.get('unique') w = entities.Worker(name=_name, profile=_profile, unique=_unique, owner=user) w.addProducer(_producer) if _factory: w.addFactory(db.get(_factory)) w.addPicture(_picture) if bene_util.doesWorkerExist(w): # already exists self.redirect('/createworker?%s' % urllib.urlencode({'repeat': True})) return w.put() if self.request.get('more'): # want to add more self.redirect('/createworker?%s' % urllib.urlencode({'added': True})) return # otherwise redirect to worker page self.redirect('/viewworker?%s' % urllib.urlencode({'id' : w.key()}))
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) if not _factory: template_values = {} path = os.path.join(os.path.dirname(__file__), 'not_found.html') self.response.out.write(template.render(path, template_values)) return if _factory.owner != user: # if not owner of factory self.redirect('/producerhome?%s' % urllib.urlencode({'not_owner': True})) return template_values = bene_util.urldecode(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 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: # already has a producer page self.redirect('/') return template_values = bene_util.urldecode(self.request.uri) path = os.path.join(os.path.dirname(__file__), 'createproducer.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: # need to sign in self.redirect(users.create_login_url(self.request.uri)) return if not bene_query.getCurrentUser(): # no user exists producer = self.request.get('producer') consumer = self.request.get('consumer') if producer and not consumer: # make person a producer only in most restricted case u = entities.User(email=user.nickname(), owner=user, isConsumer=False, isProducer=True) u.put() self.redirect('/createproducer') return else: # all other cases, make consumer u = entities.User(email=user.nickname(), owner=user, isConsumer=True, isProducer=False) u.put() self.redirect('/createconsumer') return if bene_query.getCurrentUser().isProducer: # signed in producer if bene_query.getCurrentProducer() == None: # no producer page, so create one self.redirect('/createproducer') return else: # already has producer page, so redirect self.redirect('/producerhome') return else: # signed in consumer if bene_query.getCurrentConsumer() == None: # no consumer page, so create on self.redirect('/createconsumer') return else: # already has consumer page, so redirect self.redirect('/consumerhome') 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 _unit = db.get(ID) ''' an error in getting the product will be redirected to exception handler''' if _unit.owner != user: # if current user doesn't own product self.redirect('/producerhome?%s' % urllib.urlencode({'not_owner': True})) return # remove db.delete(_unit.key()) self.redirect('/myproducts') 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 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: # already has a producer 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__), 'createproducer.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 = {} 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 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().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) if not _product: # product doesn't exist template_values = {} path = os.path.join(os.path.dirname(__file__), 'not_found.html') self.response.out.write(template.render(path, template_values)) return 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.urldecode(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'] = [] for factory in _producer.getFactories(): add = True for factory_old in _factories_old: if factory_old.key() == factory.key(): add = False if add: template_values['factories'].append(factory) template_values['workers'] = [] for worker in _producer.getWorkers(): add = True for worker_old in _workers_old: if worker_old.key() == worker.key(): add = False if add: template_values['workers'].append(worker) template_values['badges'] = [] for badge in entities.Badge.all(): add = True 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 post(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) if not _product: # product doesn't exist template_values = {} path = os.path.join(os.path.dirname(__file__), 'not_found.html') self.response.out.write(template.render(path, template_values)) return if _product.owner != user: # if current user doesn't own product self.redirect('/producerhome?%s' % urllib.urlencode({'not_owner': True})) return _product.name = self.request.get('name') _unique_save = _product.unique _product.unique = self.request.get('unique') if bene_util.doesProductExist(_product) and _unique_save != _product.unique: # if product already exists self.redirect('/editproduct?%s' % (urllib.urlencode({'id' : ID, 'repeatedit' : True}))) return _factory = self.request.get('factory') if _factory: _product.addFactory(db.get(_factory)) _picture = self.request.get('picture') _product.addPicture(_picture) # badges _badges = self.request.get_all('badges') _badges_old = _product.getBadges() if _badges_old: for badge in _badges_old: if not _badges: # convert None to empty array _badges = [] if badge not in _badges: _product.remBadge(badge) if _badges: for badge in _badges: if not _badges_old: # convert None to empty array _badges_old = [] if badge not in _badges_old: _product.addBadge(badge) _product.put() # workers ''' TODO: FIX THIS. Make it more efficient ''' _workers = self.request.get_all('workers') _workers_old = _product.getWorkers() key = _product.key() if _workers_old: for worker in _workers_old: worker.remProduct(key) worker.put() if _workers: for _worker in _workers: if _worker: worker = db.get(_worker) worker.addProduct(key) worker.put() self.redirect('/mobilepage?%s' % urllib.urlencode({'id': ID})) return
def post(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 ? ''' 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 _worker.name = bene_util.sanitize(self.request.get('name')) _worker.profile = bene_util.sanitize(self.request.get('profile')) _unique_save = _worker.unique _worker.unique = bene_util.sanitize(self.request.get('unique')) if bene_util.doesExactWorkerExist( _worker ) and _unique_save != _worker.unique: # if worker already exists self.redirect('/editworker?%s' % (urllib.urlencode({ 'id': ID, 'repeateditid': True }))) return if not _worker.unique: if bene_util.doesSimilarWorkerExist( _worker, key=True): # if worker already exists self.redirect('/editworker?%s' % (urllib.urlencode({ 'id': ID, 'repeateditname': True }))) return _location = bene_util.sanitize(self.request.get('location')) if _location: _worker.addLocation(db.get(_location)) else: _worker.clearLocation() _picture = self.request.get('picturedata') _worker.addPicture(_picture) _worker.put() self.redirect('/viewworker?%s' % urllib.urlencode({'id': ID})) 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 ? ''' 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['id'] = ID template_values['cropentity'] = _worker template_values['name_old'] = _worker.name template_values['profile_old'] = _worker.profile template_values['unique_old'] = _worker.unique template_values['path'] = "worker" template_values['no_locations'] = True _locations_old = [_worker.getLocation()] if _worker.getLocation(): template_values['no_locations'] = False template_values['locations_old'] = _locations_old ''' TODO: Make this more efficient. For some reason, 'location not in _locations_old' doesn't work ''' _locations = _producer.getLocations() if len(_locations.fetch(1)) != 0: template_values['locations'] = [] if _locations: for location in _locations: if location: add = True if _locations_old: for location_old in _locations_old: if location_old: if location_old.key() == location.key(): add = False if add: template_values['no_locations'] = False template_values['locations'].append(location) path = os.path.join(os.path.dirname(__file__), 'editworker.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 _productline = db.get(ID) ''' an error in getting the product will be redirected to exception handler''' if _productline.owner != user: # if current user doesn't own product self.redirect('/producerhome?%s' % urllib.urlencode({'not_owner': True})) return # delete all configs _productconfigs = _productline.getConfigs() for _productconfig in _productconfigs: # remove from locations _locations = _productconfig.getLocations() if _locations: for _location in _locations: if _location: _location.remProductConfig(ID) _location.put() # clear out path elements _productconfig.clearPath() # remove from workers _workers = _productconfig.getWorkers() if _workers: for _worker in _workers: if _worker: _worker.remProductConfig(ID) _worker.put() # delete units _units = _productconfig.getProducts() if _units: for _unit in _units: if _unit: db.delete(_unit.key()) # delete messages for _msg in _producer.getSentMsg(): if _msg: if _msg.receiver.key() == _productconfig.key(): db.delete(_msg.key()) # delete from datastore db.delete(_productconfig.key()) # delete messages for _msg in _producer.getSentMsg(): if _msg: if _msg.receiver.key() == _productline.key(): db.delete(_msg.key()) db.delete(_productline.key()) self.redirect('/myproducts') 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 _productline = db.get(ID) ''' an error in getting the product will be redirected to exception handler''' if _productline.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['name_old'] = _productline.name template_values['description_old'] = _productline.description template_values['path'] = "product" template_values['workers'] = _producer.getWorkers() template_values['badges'] = entities.Badge.all() template_values['product'] = _productline template_values['cropentity'] = _productline template_values['no_locations'] = True _locations = _producer.getLocations() if _locations.get(): template_values['no_locations'] = False 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 path = os.path.join(os.path.dirname(__file__), 'createconfig.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 # remove from all workers _workers = _location.getWorkers() if _workers: for _worker in _workers: if _worker: _worker.remLocation(_location) _worker.put() # remove from path in configs _configs = _location.getProductConfigs() if _configs: for _config in _configs: if _config: # all path locations for a config locations = _config.getLocations() _config.clearPath() # clear path to rebuild if locations: i = 0 index_rem_save = -1 # index of removed element # rebuild path for location in locations: if location.key() != _location.key(): _config.addLocationToPath(location, "", i) i = i + 1 else: index_rem_save = i # fix primary index if _config._path_primary_index: if index_rem_save == _config._path_primary_index: _config._path_primary_index = None if index_rem_save != -1 and index_rem_save < _config._path_primary_index: _config._path_primary_index -= 1 _config.put() # remove from datastore db.delete(ID) self.redirect('/mylocations') 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 _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 post(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 _productline = db.get(ID) ''' an error in getting the product will be redirected to exception handler''' if _productline.owner != user: # if current user doesn't own product self.redirect('/producerhome?%s' % urllib.urlencode({'not_owner': True})) return _configname = bene_util.sanitize(self.request.get('configname')) _locations = bene_util.sanitize(self.request.get('orderedlocations')) _workers = bene_util.sanitizeList(self.request.get_all('workers')) _badges = bene_util.sanitizeList(self.request.get_all('badges')) s_price = bene_util.sanitize(self.request.get('storePrice')) s_name = bene_util.sanitize(self.request.get('storeName')) s_url = bene_util.sanitize(self.request.get('storeLink')) s_link = None if s_name and s_url: if not s_price: s_price = "0.0" try: s_price = float(s_price) except ValueError: s_price= 0.0 s_link = entities.StoreLink(name=s_name, url=s_url, price=s_price) s_link.put() _displayAmazon = False if self.request.get('displayAmazon'): _displayAmazon = True p = entities.ProductConfig(config_name=_configname, owner=user, rating=0.0, _num_ratings=0, _num_closet=0, isLine=False, isConfig=True, isUnit=False, store_link=s_link, displayAmazon=_displayAmazon) if bene_util.doesSimilarProductConfigExist(p, _productline): # already exists self.redirect('/createconfig?%s' % urllib.urlencode({'repeateditname': True, 'id': ID})) return p.addProducer(_producer) p.addProductLine(_productline) for _badge in _badges: p.addBadge(db.Key(_badge)) if _locations: _locations = _locations.split(',') locations = db.get(_locations) i = 0 for location in locations: p.addLocationToPath(location, "", i) i = i + 1 p.put() config_key = p.key() # add product to workers if _workers: for _worker in _workers: if _worker: worker = db.get(_worker) worker.addProductConfig(config_key) worker.put() # add product to locations if _locations: for location in locations: location.addProductConfig(config_key) location.put() # edit product line _name = bene_util.sanitize(self.request.get('name')) _description = bene_util.sanitize(self.request.get('description')) _picture = self.request.get('picturedata') if _name != _productline.name or _description != _productline.description or _picture: _name_save = _productline.name _productline.name = _name _productline.description = _description if bene_util.doesSimilarProductLineExist(_productline) and _name_save != _productline.name: # already exists self.redirect('/createconfig?%s' % urllib.urlencode({'id': ID, 'repeatprodname': True})) return _productline.addPicture(_picture) _productline.put() if bene_util.sanitize(self.request.get('more')): # want to add more self.redirect('/createconfig?%s' % urllib.urlencode({'id': ID, 'added': True})) return self.redirect('/view?%s' % urllib.urlencode({'id': config_key})) return
def post(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 _location.name = bene_util.sanitize(self.request.get('name')) _location.address = bene_util.sanitize(self.request.get('address')) _location.description = bene_util.sanitize( self.request.get('description')) _unique_save = _location.unique _location.unique = bene_util.sanitize(self.request.get('unique')) if bene_util.doesExactLocationExist( _location ) and _unique_save != _location.unique: # if location with same unique exists self.redirect('/editlocation?%s' % (urllib.urlencode({ 'id': ID, 'repeateditid': True }))) return if not _location.unique: if bene_util.doesSimilarLocationExist(_location, key=True): self.redirect('/editlocation?%s' % (urllib.urlencode({ 'id': ID, 'repeateditname': True }))) return _picture = self.request.get('picturedata') _location.addPicture(_picture) location = bene_util.sanitize(self.request.get('location')) fields = location.split(',') if len(fields) == 2: try: lat = float(fields[0]) lon = float(fields[1]) gp = db.GeoPt(lat, lon) except ValueError: gp = None else: gp = None _location.location = gp _location.put() self.redirect('/viewlocation?%s' % urllib.urlencode({'id': ID})) return
def get(self): user = users.get_current_user() if not user: # need to sign in self.redirect('/?signin=True') return ''' PRODUCER PROFILE ''' if bene_query.getCurrentUser().isProducer: _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.urldecode(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 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 ''' CONSUMER PROFILE ''' _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.urldecode(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 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 ''' PRODUCER PROFILE ''' if bene_query.getCurrentUser().isProducer: _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 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: 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 ''' CONSUMER PROFILE ''' _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 email_public = _consumer.email_public template_values = bene_util.initTemplate(self.request.uri) template_values['id'] = _consumer.key() 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 post(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 _configname = bene_util.sanitize(self.request.get('configname')) _configname_save = _productconfig.config_name _productconfig.config_name = _configname # already exists if bene_util.doesSimilarProductConfigExist( _productconfig, _productconfig.getProductLine() ) and not _configname_save == _productconfig.config_name: self.redirect('/editconfig?%s' % urllib.urlencode({ 'repeatedit': True, 'id': ID })) return # locations _locations = bene_util.sanitize(self.request.get('orderedlocations')) if _locations: _locations = _locations.split(',') locations = db.get(_locations) config_key = _productconfig.key() # remove config from old locations locations_old = _productconfig.getLocations() if locations_old: for location_old in locations_old: if location_old: if not _locations: # convert nonetype to empty array _locations = [] if location_old.key() not in _locations: location_old.remProductConfig(config_key) location_old.put() _productconfig.clearPath() if _locations: i = 0 if locations: for location in locations: if location: # add config to new locations location.addProductConfig(config_key) location.put() # add to path _productconfig.addLocationToPath(location, "", i) i = i + 1 # workers _workers = bene_util.sanitizeList(self.request.get_all('workers')) if not _workers: _workers = [] # remove config from old locations workers_old = _productconfig.getWorkers() if workers_old: for worker_old in workers_old: if worker_old: if worker_old.key() not in _workers: worker_old.remProductConfig(config_key) worker_old.put() # add config to new locations workers = db.get(_workers) if workers: for worker in workers: if worker: worker.addProductConfig(config_key) worker.put() # badges _badgeskeys = bene_util.sanitizeList(self.request.get_all('badges')) _badges_old = _productconfig.getBadges() if not _badges_old: # convert None to empty array _badges_old = [] if not _badgeskeys: # convert None to empty array _badgeskeys = [] if _badges_old: for badge in _badges_old: if badge.key() not in _badgeskeys: _productconfig.remBadge(badge.key()) if _badgeskeys: for badgekey in _badgeskeys: badge = db.get(badgekey) if badge not in _badges_old: _productconfig.addBadge(db.Key(badgekey)) #storelink s_price = bene_util.sanitize(self.request.get('storePrice')) s_name = bene_util.sanitize(self.request.get('storeName')) s_url = bene_util.sanitize(self.request.get('storeLink')) s_link = _productconfig.store_link if s_name and s_url: if not s_price: s_price = "0.0" try: s_price = float(s_price) except ValueError: s_price = 0.0 if s_link: s_link.name = s_name s_link.url = s_url s_link.price = s_price s_link.put() else: s_link = entities.StoreLink(name=s_name, url=s_url, price=s_price) s_link.put() _productconfig.store_link = s_link else: if s_link: s_link.delete() _productconfig.store_link = None if self.request.get('displayAmazon'): _productconfig.displayAmazon = True else: _productconfig.displayAmazon = False _productconfig.put() # edit product line _picture = self.request.get('picturedata') _name = bene_util.sanitize(self.request.get('name')) _description = bene_util.sanitize(self.request.get('description')) _productline = _productconfig.getProductLine() if _name != _productline.name or _description != _productline.description or _picture: _name_save = _productline.name _productline.name = _name _productline.description = _description if bene_util.doesSimilarProductLineExist( _productline ) and _name_save != _productline.name: # already exists self.redirect('/editconfig?%s' % urllib.urlencode({ 'repeatprodname': True, 'id': ID })) return _productline.addPicture(_picture) _productline.put() self.redirect('/view?%s' % urllib.urlencode({'id': ID})) return
def post(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 _name = bene_util.sanitize(self.request.get('name')) _address = bene_util.sanitize(self.request.get('address')) _location = bene_util.sanitize(self.request.get('location')) _unique = bene_util.sanitize(self.request.get('unique')) _picture = self.request.get('picturedata') _description = bene_util.sanitize(self.request.get('description')) popupworker = bene_util.sanitize(self.request.get('popupworker')) popupproduct = bene_util.sanitize(self.request.get('popupproduct')) fields = _location.split(',') if len(fields) == 2: try: lat = float(fields[0]) lon = float(fields[1]) gp = db.GeoPt(lat, lon) except ValueError: gp = None else: gp = None f = entities.Location(name=_name, address=_address, location=gp, description=_description, unique=_unique, owner=user) f.addProducer(_producer) f.addPicture(_picture) if bene_util.doesExactLocationExist(f): if popupworker: self.redirect('/createlocation?%s' % urllib.urlencode({'repeatid': True, 'popupworker': True})) return if popupproduct: self.redirect('/createlocation?%s' % urllib.urlencode({'repeatid': True, 'popupproduct': True})) return else: self.redirect('/createlocation?%s' % urllib.urlencode({'repeatid': True})) return if not _unique: if bene_util.doesSimilarLocationExist(f): if popupworker: self.redirect('/createlocation?%s' % urllib.urlencode({'repeatname': True, 'popupworker': True})) return if popupproduct: self.redirect('/createlocation?%s' % urllib.urlencode({'repeatname': True, 'popupproduct': True})) return else: self.redirect('/createlocation?%s' % urllib.urlencode({'repeatname': True})) return f.put() if bene_util.sanitize(self.request.get('more')): # want to add more self.redirect('/createlocation?%s' % urllib.urlencode({'added': True})) return # otherwise redirect to location page if popupworker: self.redirect('/viewlocation?%s' % urllib.urlencode({'id' : f.key(), 'popupworker': True})) return if popupproduct: self.redirect('/viewlocation?%s' % urllib.urlencode({'id' : f.key(), 'popupproduct': True})) return self.redirect('/viewlocation?%s' % urllib.urlencode({'id' : f.key()})) return
def post(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 _name = bene_util.sanitize(self.request.get('name')) _description = bene_util.sanitize(self.request.get('description')) _locations = bene_util.sanitize(self.request.get('orderedlocations')) _workers = bene_util.sanitizeList(self.request.get_all('workers')) _badges = bene_util.sanitizeList(self.request.get_all('badges')) _picture = self.request.get('picturedata') product_line = entities.ProductLine(name=_name, owner=user, description=_description, isLine=True, isConfig=False, isUnit=False) if bene_util.doesSimilarProductLineExist( product_line): # already exists self.redirect('/createproduct?%s' % urllib.urlencode({'repeat': True})) return product_line.addProducer(_producer) product_line.addPicture(_picture) product_line.put() s_price = bene_util.sanitize(self.request.get('storePrice')) s_name = bene_util.sanitize(self.request.get('storeName')) s_url = bene_util.sanitize(self.request.get('storeLink')) s_link = None if s_name and s_url: if not s_price: s_price = "0.0" try: s_price = float(s_price) except ValueError: s_price = 0.0 s_link = entities.StoreLink(name=s_name, url=s_url, price=s_price) s_link.put() _displayAmazon = False if self.request.get('displayAmazon'): _displayAmazon = True p = entities.ProductConfig(name=_name, config_name="Default config", owner=user, rating=0.0, _num_ratings=0, _num_closet=0, isLine=False, isConfig=True, isUnit=False, store_link=s_link, displayAmazon=_displayAmazon) p.addProducer(_producer) p.addProductLine(product_line) for _badge in _badges: p.addBadge(db.Key(_badge)) if _locations: _locations = _locations.split(",") locations = db.get(_locations) i = 0 for location in locations: p.addLocationToPath(location, "", i) i = i + 1 p.put() config_key = p.key() # add product to workers if _workers: for _worker in _workers: if _worker: worker = db.get(_worker) worker.addProductConfig(config_key) worker.put() # add product to locations if _locations: for location in locations: location.addProductConfig(config_key) location.put() if bene_util.sanitize(self.request.get('more')): # want to add more self.redirect('/createproduct?%s' % urllib.urlencode({'added': True})) return # otherwise redirect to product page self.redirect('/view?%s' % urllib.urlencode({'id': product_line.key()}))