Exemplo n.º 1
0
  def post(self, group_name):
    group = get1_by_property(Group, 'name', group_name)
    user_name = self.request.POST.get('member')

    user = get1_by_property(User, 'name', user_name)

    if not user:
      self.redirect('/oops/invalid_user')
    else:
      user.join(group)
      group.put()
      self.redirect('/g/%s/profile' % group.name)
Exemplo n.º 2
0
 def get_balances(self):
     user = get1_by_property(User, 'who', self.user)
     bs = [Balance.create_from_mutual_balance(b, self.user) \
           for b in user.get_balances()]
     if not bs:
         return bs, 0, 0
     amount_list = [b.amount for b in bs]
     max_amount = max(abs(a) for a in amount_list)
     total_amount = sum(amount_list)
     for b in bs:
         b.normalize(max_amount)
     return bs, total_amount, max_amount
Exemplo n.º 3
0
 def get(self, vendor_name):
     vendor = get1_by_property(Vendor, "name", vendor_name)
     if vendor is None:
         logging.debug("vendor %s not found " % vendor_name)
         self.redirect("/v/entry?vendor=%s" % vendor_name)
         return
     items = list(vendor.get_items())
     event_id = self.request.get("event")
     if event_id:
         event = Event.get_by_id(long(event_id))
         self.generate("list_item.html", {"items": items, "event": event})
     else:
         self.generate("show_item.html", {"vendor": vendor, "items": items, "nitems": len(items)})
Exemplo n.º 4
0
 def post(self, vendor_name):
     # TODO: should be editing existing item if the name of item is identical with existing one
     #       upload thumb
     #       resize thumb using google.appengine.api.images
     data = ItemForm(data=self.request.POST)
     if data.is_valid():
         item = data.save(commit=False)
         item.photo = self.get_photo()
         vendor = get1_by_property(Vendor, "name", vendor_name)
         vendor.items.append(item.put())
         vendor.put()
         self.redirect("/v/%s/item/list" % vendor_name)
     else:
         self.redirect("/v/%s/item/entry" % vendor_name)
Exemplo n.º 5
0
 def get(self, username):
   if username == 'mine':
     user = User.get_current_user()
   else:
     user = get1_by_property(User, 'name', username)
   
   if user:
     balances = self.get_balances(user)
     self.generate('user_profile.html',
                   {'user':user,
                    'balances':balances,
                    'groups':Group.all(),
                    'vendors':Vendor.all()})    
   else:
     self.redirect('/oops/invalid_user')
Exemplo n.º 6
0
  def get(self, group_name):
    group = get1_by_property(Group, 'name', group_name)

    self.generate('group_profile.html',
                  {'group':group})
Exemplo n.º 7
0
 def get_current_user():
     user = get1_by_property(User, 'who', users.get_current_user())
     return user
Exemplo n.º 8
0
 def user(name):
     """Get google user by name"""
     return get1_by_property(User, 'name', name).who
Exemplo n.º 9
0
 def get_item(name):
     item = get1_by_property(Item, 'name', name)
     if item is None:
         raise Purchase.NotExists(name=name)
     else:
         return item