Beispiel #1
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.initTemplate(self.request.uri)
        template_values["id"] = _consumer.key()
        template_values["consumer"] = _consumer
        template_values["name"] = name
        template_values["profile"] = profile

        template_values["can_edit"] = False
        user = users.get_current_user()
        if user:
            if _consumer.owner == user:
                template_values["can_edit"] = True
                template_values["edit_link"] = "/editconsumer"

        path = os.path.join(os.path.dirname(__file__), "viewconsumer.html")
        self.response.out.write(template.render(path, template_values))
        return
Beispiel #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
     template_values = bene_util.initTemplate(self.request.uri)
     template_values['id'] = _consumer.key()
     template_values['consumer'] = _consumer
     template_values['products'] = _consumer.getProducts()
     
     template_values['can_edit_local'] = False
     user = users.get_current_user()
     if user:
         if _consumer.owner == user:
             template_values['can_edit_local'] = True
         
     path = os.path.join(os.path.dirname(__file__), 'viewcloset.html')
     self.response.out.write(template.render(path, template_values))
     return
Beispiel #3
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)
     ''' an error in getting the product will be redirected to exception handler'''
     
     _factory = product.getFactory()
     if _factory and _factory.location:
         latitude = _factory.location.lat
         longitude = _factory.location.lon
     else:
         latitude = None
         longitude = None
     # Make a dictionary for template
     template_values = bene_util.initTemplate(self.request.uri)
     template_values['id'] = ID
     template_values['name'] = product.name
     template_values['producer'] = product.getProducer()
     template_values['latitude'] = latitude
     template_values['longitude'] = longitude
     template_values['url'] = self.request.url
     template_values['qr_url'] = self.request.url.replace('view','qr')
     template_values['factory'] = _factory
     template_values['badges'] = product.getBadges()
     template_values['rating'] = product.rating
     template_values['workers'] = product.getWorkers()
     if product.picture:
         template_values['has_image'] = True
     else:
         template_values['has_image'] = False
         
     template_values['can_edit'] = False
     user = users.get_current_user()
     if user:
         if product.owner == user:
             template_values['can_edit'] = True
             template_values['edit_link'] = '/editproduct?%s' % urllib.urlencode({'id': ID})
     template_values['in_closet'] = False
     template_values['add_closet'] = False
     if user:
         if bene_query.getCurrentUser().isConsumer:
             consumer = bene_query.getCurrentConsumer()
             if consumer:
                 if consumer.hasProduct(product.key()):
                     template_values['in_closet'] = True
                     template_values['rem_closet_link'] = '/removefromcloset?%s' % urllib.urlencode({'id': ID})
                 else:
                     template_values['add_closet'] = True
                     template_values['add_closet_link'] = '/addtocloset?%s' % urllib.urlencode({'id': ID})
         
     path = os.path.join(os.path.dirname(__file__), 'viewproduct.html')
     self.response.out.write(template.render(path, template_values))
     return
Beispiel #4
0
 def get(self):
     user = users.get_current_user()
     if not user: # not signed in
         self.redirect('/?%s' % urllib.urlencode({'signin': True}))
         return
     if bene_query.getCurrentUser().isProducer: # producers don't have closets
         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({'msg': True}))
         return
     ID = self.request.get('id')
     if not ID:
         '''
         TODO: If no ID sent, default to viewcloset?
         '''
         self.redirect('/')
         return
     product = db.get(ID)
     if not product: # invalid product
         template_values = {}
         path = os.path.join(os.path.dirname(__file__), 'not_found.html')
         self.response.out.write(template.render(path, template_values))
         return
     
     # if not already in closet, add to closet, and redirect back to product page
     #return
     if not _consumer.hasProduct(product.key()): 
         _consumer.addProduct(product.key())
         _consumer.put()
     self.redirect('/mobilepage?%s' % urllib.urlencode({'id': product.key()}))  
     return
Beispiel #5
0
    def post(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

        _name = self.request.get("name")
        _profile = self.request.get("profile")
        _picture = self.request.get("picture")

        _consumer.name = _name
        _consumer.profile = _profile
        _consumer.addPicture(_picture)
        _consumer.put()

        self.redirect("/viewconsumer?%s" % urllib.urlencode({"id": _consumer.key()}))
        return

        """
Beispiel #6
0
 def post(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: # already exists
         self.redirect('/')
         return
         
     # no consumer, so add to store
     _name = self.request.get('name')
     _picture = self.request.get('picture')
     _profile = self.request.get('profile')
             
     c = entities.Consumer(name=_name, 
                           email=bene_util.getEmail(user), 
                           owner=user,
                           profile=_profile,                      
                           verified=False)
     c.addPicture(_picture)
     c.put()                
     self.redirect('/')
     return
Beispiel #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().isProducer: # producers can't do this
         self.redirect('/')
         return
     
     if bene_query.getCurrentConsumer() != None: # has consumer page 
         self.redirect('/')
         return
         
     template_values = bene_util.initTemplate(self.request.uri)
     path = os.path.join(os.path.dirname(__file__), 'createconsumer.html')
     self.response.out.write(template.render(path, template_values))
     return
Beispiel #8
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.initTemplate(self.request.uri)
     path = os.path.join(os.path.dirname(__file__), 'consumerhome.html')
     self.response.out.write(template.render(path, template_values))
     return
Beispiel #9
0
 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
Beispiel #10
0
 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
Beispiel #11
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

        """
Beispiel #12
0
 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
Beispiel #13
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
     # Make a dictionary for template
     _factory = product.getFactory()
     if _factory and _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'] = 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'] = product.getFactory()
     template_values['rating'] = product.rating
     template_values['workers'] = product.getWorkers()
     _badges = product.getBadges()
     if _badges:
         template_values['badges'] = _badges
         template_values['has_badges'] = True
     else:
         template_values['has_badges'] = False
     if product.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 product.owner == user:
             template_values['can_edit'] = True
             
     template_values['in_closet'] = False
     template_values['add_closet'] = False
     if user:
         if bene_query.getCurrentUser().isConsumer:
             consumer = bene_query.getCurrentConsumer()
             if consumer:
                 if consumer.hasProduct(product.key()):
                     template_values['in_closet'] = True
                 else:
                     template_values['add_closet'] = True
         
     path = os.path.join(os.path.dirname(__file__), 'mobilepage.html')
     self.response.out.write(template.render(path, template_values))
     return