Esempio n. 1
0
 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)
     # Display error if product ID not found
     if not producer:
         template_values = {}
         path = os.path.join(os.path.dirname(__file__), 'not_found.html')
         self.response.out.write(template.render(path, template_values))
         return
     
     # Make a dictionary for template
     template_values = bene_util.urldecode(self.request.uri)
     template_values['id'] = ID
     template_values['producer'] = producer
     template_values['workers'] = producer.getWorkers()
     
     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__), 'viewproducerworkers.html')
     self.response.out.write(template.render(path, template_values))
     return
Esempio n. 2
0
 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.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
Esempio n. 3
0
 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
Esempio n. 4
0
 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)
     if not consumer:
         template_values = {}
         path = os.path.join(os.path.dirname(__file__), 'not_found.html')
         self.response.out.write(template.render(path, template_values))
         return
     # Make a dictionary for template
     name = consumer.name
     profile = consumer.profile
     
     template_values = bene_util.urldecode(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
Esempio n. 5
0
 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)
     if not _product:
         template_values = {}
         path = os.path.join(os.path.dirname(__file__), 'not_found.html')
         self.response.out.write(template.render(path, template_values))
         return
     # Make a dictionary for template
     name = _product.name
     producer = _product.getProducer()
     workers = _product.getWorkers()
     factory = _product.getFactory()
     template_values = bene_util.urldecode(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
Esempio n. 6
0
 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.urldecode(self.request.uri)
     template_values['id'] = producer.key()
     template_values['producer'] = producer
     template_values['workers'] = producer.getWorkers()
     
     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__), 'viewproducerworkers.html')
     self.response.out.write(template.render(path, template_values))
     return
Esempio n. 7
0
 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)
     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
     
     template_values = bene_util.urldecode(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
     '''
     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)
                                         
     path = os.path.join(os.path.dirname(__file__), 'editworker.html')
     self.response.out.write(template.render(path, template_values))
     return
Esempio n. 8
0
    def post(self):
        query = self.request.get("query")
        productlist = entities.Product.all()

        matches = [p for p in productlist if query.lower() in p.name.lower()]
        template_values = bene_util.urldecode(self.request.uri)
        template_values["matches"] = matches
        path = os.path.join(os.path.dirname(__file__), "searchresult.html")
        self.response.out.write(template.render(path, template_values))
Esempio n. 9
0
 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)
     # Display error if product ID not found
     if not product:
         template_values = {}
         path = os.path.join(os.path.dirname(__file__), 'not_found.html')
         self.response.out.write(template.render(path, template_values))
         return
     
     _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.urldecode(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
         
     path = os.path.join(os.path.dirname(__file__), 'viewproduct.html')
     self.response.out.write(template.render(path, template_values))
     return
Esempio n. 10
0
 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)
     if not worker:
         template_values = {}
         path = os.path.join(os.path.dirname(__file__), 'not_found.html')
         self.response.out.write(template.render(path, template_values))
         return
     # 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.urldecode(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
 
     path = os.path.join(os.path.dirname(__file__), 'viewworker.html')
     self.response.out.write(template.render(path, template_values))
     return
Esempio n. 11
0
 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.urldecode(self.request.uri)
     path = os.path.join(os.path.dirname(__file__), 'createbadge.html')
     self.response.out.write(template.render(path, template_values))
     return
Esempio n. 12
0
 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)
     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
     # 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.urldecode(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
     
     path = os.path.join(os.path.dirname(__file__), 'viewfactory.html')
     self.response.out.write(template.render(path, template_values))
     return
Esempio n. 13
0
 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.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
Esempio n. 14
0
 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.urldecode(self.request.uri)
     path = os.path.join(os.path.dirname(__file__), 'createconsumer.html')
     self.response.out.write(template.render(path, template_values))
     return
Esempio n. 15
0
 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
Esempio n. 16
0
 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)
     if not producer:
         template_values = {}
         path = os.path.join(os.path.dirname(__file__), 'not_found.html')
         self.response.out.write(template.render(path, template_values))
         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'] = 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           
     
     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
Esempio n. 17
0
 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.urldecode(self.request.uri)
     path = os.path.join(os.path.dirname(__file__), 'consumerhome.html')
     self.response.out.write(template.render(path, template_values))
     return
Esempio n. 18
0
 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.urldecode(self.request.uri)
     path = os.path.join(os.path.dirname(__file__), 'producerhome.html')
     self.response.out.write(template.render(path, template_values))
     return
Esempio n. 19
0
    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.urldecode(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

        """
Esempio n. 20
0
 def get(self):
     template_values = bene_util.urldecode(self.request.uri)
     path = os.path.join(os.path.dirname(__file__), "searchproduct.html")
     self.response.out.write(template.render(path, template_values))
     return
Esempio n. 21
0
 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