Exemplo n.º 1
0
 def find_categories(categories, parent=None):
     for category_config in raw_categories:
         yield Category(id=category_config['id'],
                        name=category_config['name'],
                        parent=parent)
         for subcategory_config in category_config.get('subcategories', []):
             yield Category(id=subcategory_config['id'],
                            name=subcategory_config['name'],
                            parent=category_config['id'])
Exemplo n.º 2
0
 def get(self):
   user = users.get_current_user()
   u = User.get_by_key_name(user.email())
   categories = []
   suggestions = set()
   for category in Category.all():
     areas = category.get_areas_of_expertise()
     if areas:
       area_data = [{
         'user_name' : area.user.get_name(),
         'user_email' : area.user.email,
         'user_profile_pic' : area.user.profile_pic,
         'user_available' : area.user.is_available_for_hangout(),
         'description' : area.description.title(),
       } for area in areas if area.user.is_expert]
       for area in areas:
         suggestions.add(category.name.title() + ' :: ' + area.description.title())
       if area_data:
         categories.append({'name':category.name, 'areas':area_data})
   self.Render("main.html", {
     'user': u,
     'validate': u.validate(),
     'contents': 'expert_list.html',
     'token': channel.create_channel(user.user_id()),
     'is_expert': u.is_expert,
     'categories': categories,
     'suggestions': [suggestion for suggestion in suggestions],
     'login': users.create_login_url("/"),
     'logout': users.create_logout_url("/"),
     'is_admin': users.is_current_user_admin(),
   })
Exemplo n.º 3
0
  def get(self):
    user = users.get_current_user()
    u = User.get_by_key_name(user.email())
    if not u.is_expert and not u.convert_to_expert(service, calendar_service, decorator):
      # Token access error. Go back to sign up page and restart flow
      self.redirect('/signUp')
      return
        
    # get the areas of expertise for this user
    user_areas = u.get_areas_of_expertise()
    # user_areas_dict = dict((area.category.name, area) for area in user_areas)
    # 
    # # construct a data structure of all categories
    # all_categories = []
    # for category in Category.all():
    #   category_data = {
    #     'checked': False,
    #     'name': category.name,
    #     'description': category.name,      
    #   }
    #   if category.name in user_areas_dict:
    #     category_data['checked'] = True
    #     category_data['description'] = \
    #       user_areas_dict[category.name].description
    #   all_categories.append(category_data)
      
    suggestions = set()
    for category in Category.all():
      for area in category.get_areas_of_expertise():
        suggestions.add(category.name.title() + ' :: ' + area.description.title())

    # this is what we pass to the templating engine
    template_values = {
      # 'all_categories': all_categories,
      'suggestions': [suggestion for suggestion in suggestions],
      'user_categories': [(area.category.name.title(), area.category.name.title() + ' :: ' + area.description.title()) for area in user_areas],
      'user': u,
      'validate': u.validate(),
      'logout': users.create_logout_url("/"),
      'contents': 'add_expertise.html',
      'is_expert': u.is_expert,
      'is_admin': users.is_current_user_admin(),
    }
    self.Render('main.html', template_values)
Exemplo n.º 4
0
 def get(self):
   user = self.request.get('user')
   category = self.request.get('category')
   u = User.get_by_key_name(user)
   if u == None or not u.validate() or not u.is_available_for_hangout():
     logging.error('Connect request to invalid and/or unavailable user/expert ' + user)
     self.redirect('/')
     return
   c = Category.get_by_key_name(category.lower())
   if not c:
     logging.error('Connect request with invalid category key: ' + category.lower())
     self.redirect('/')
     return
   url = HangoutStats.get_hangout_url()
   logging.info('Hangout url: %s in category %s' % (url, category))
   xmpp.send_message(u.email, chat.REQUEST_MSG % (category, url))
   for email in ['*****@*****.**', '*****@*****.**', '*****@*****.**']:
     u = User.get_by_key_name(email)
     if u and u.is_subscribed:
       xmpp.send_message(email, chat.FACILITATOR_MSG % (category, url))
   self.redirect(url)
Exemplo n.º 5
0
  def post(self):
    # figure out the current user
    user = users.get_current_user()
    if user == None:
      self.redirect(users.create_login_url("/manageAccount"))
      return
    u = User.get_by_key_name(user.email())
    if u == None:
      self.redirect(users.create_login_url("/signUp"))
      return
      
    # add all the existing categories
    area = AreaOfExpertise.all()
    area.filter("user ="******"expertoptout") != "true"
    u.put()
    
    for category_subcategory in self.request.get_all("usercategory"):
      if category_subcategory and category_subcategory != "" and re.search("\s::\s", category_subcategory):
        match = re.search("\s::\s", category_subcategory)
        category_name = category_subcategory[0:match.start(0)].lower()
        subcategory = category_subcategory[match.end(0):].lower()
        if not Category.get_by_key_name(category_name):
          category = Category(name=category_name)
          category.put()
        u.add_category(category_name, subcategory)
      
        
    # for param in self.request.arguments():
    #   value = self.request.get(param)
    #   if param == "expertoptout":
    #     u.expert_opt_out = self.request.get("expertoptout") != "true"
    #     u.put()
    #   elif not re.search(" description$", param) and value == "true":
    #     if not Category.get_by_key_name(param):
    #       c = Category(name=param)
    #       c.put()
    #     description = self.request.get('%s description' % param)
    #     logging.error(param + " :: " + description)
    #     u.add_category(param, description)

    # for category in Category.all().fetch(100):
    #    if self.request.get(category.name) == 'true':
    #      description = self.request.get('%s description' % category.name)
    #      u.add_category(category.name, description)
         
    # # add the other category
    # other_category = self.request.get("other").lower()
    # if other_category and other_category != "" and other_category != "other":
    #   # Disallow empty category names and the "other" category name
    #   if not Category.get_by_key_name(other_category):
    #     category = Category(name=other_category)
    #     category.put()
    #   u.add_category(other_category, other_category)
    
    # add_category = self.request.get("addcategory").lower()
    # if add_category and add_category != "" and re.search("\s::\s", add_category):
    #   match = re.search("\s::\s", add_category)
    #   category_name = add_category[0:match.start(0)]
    #   subcategory = add_category[match.end(0):]
    #   if not Category.get_by_key_name(category_name):
    #     category = Category(name=category_name)
    #     category.put()
    #   u.add_category(category_name, subcategory)
    
    # do the opt out stuff
    self.redirect("/")