Esempio n. 1
0
 def get(self):
   current_session = Session().get_current_session(self)
   email = current_session.get_email()
   account = current_session.get_account_entity()
   
   badgeset = badges_dao.get_rendereable_badgeset(account)
   upload_url = blobstore.create_upload_url('/badge/u')
   template_values = {'badges_main': True,
                      'account_name': email,
                      'badges': badgeset,
                      'upload_url': upload_url}
   self.response.out.write(template.render(constants.TEMPLATE_PATHS.CONSOLE_DASHBOARD, template_values))
Esempio n. 2
0
  def milestones_values(self, user_ref, acc_ref, height, width):
    user_badges = badges_dao.get_user_badges(user_ref)
    acc_badges = badges_dao.get_rendereable_badgeset(acc_ref)
    mcase_ref = None
    if not acc_ref:
      mcase_ref = Milestones()
    else:
      try:
        mcase_ref = acc_ref.milestoneWidget
      except:
        mcase_ref = widgets_dao.add_milestones(acc_ref)

    if user_ref and user_ref.userid == constants.ANONYMOUS_USER:
      user_badges = []

    badge_count = 0
    display_badges = []
    for badge in user_badges:
      b = {}
      try:
        # In case the badge was removed, we'll skip it
        b["badgeRef"] = badge.badgeRef
      except Exception, e:
        continue
      if badge.awarded == "yes":
        b["awarded"] = True
      else:
        b["awarded"] = True
      b["id"] = badge_count 
      b["awarded"] = badge.awarded
      b["pointsRequired"] = badge.pointsRequired

      # backward compatibility
      if badge.pointsRequired == 9999999999:
        b["pointsRequired"] = 0
   
      if badge.pointsEarned > badge.pointsRequired:
        b["pointsEarned"] = badge.pointsRequired
      else:  
        b["pointsEarned"] = badge.pointsEarned
      b["resource"] = badge.resource
      b["reason"] = badge.reason
      b["downloadLink"] = badge.downloadLink
      b["id"] = badge_count
      badge_count += 1
      display_badges.append(b)
Esempio n. 3
0
  def milestones_values(self, user_ref, acc_ref, height, width):
    user_badges = badges_dao.get_user_badges(user_ref)
    acc_badges = badges_dao.get_rendereable_badgeset(acc_ref)
    mcase_ref = None
    if not acc_ref:
      mcase_ref = Milestones()
    else:
      try:
        mcase_ref = acc_ref.milestoneWidget
      except:
        mcase_ref = widgets_dao.add_milestones(acc_ref)

    if user_ref and user_ref.userid == constants.ANONYMOUS_USER:
      user_badges = []

    badge_count = 0
    display_badges = []
    for badge in user_badges:
      b = {}
      try:
        # In case the badge was removed, we'll skip it
        b["badgeRef"] = badge.badgeRef
      except Exception, e:
        continue
      if badge.awarded == "yes":
        b["awarded"] = True
      else:
        b["awarded"] = True
      b["id"] = badge_count 
      b["awarded"] = badge.awarded
      b["pointsRequired"] = badge.pointsRequired

      # backward compatibility
      if badge.pointsRequired == 9999999999:
        b["pointsRequired"] = 0
   
      if badge.pointsEarned > badge.pointsRequired:
        b["pointsEarned"] = badge.pointsRequired
      else:  
        b["pointsEarned"] = badge.pointsEarned
      b["resource"] = badge.resource
      b["reason"] = badge.reason
      b["downloadLink"] = badge.downloadLink
      b["id"] = badge_count
      badge_count += 1
      display_badges.append(b)
Esempio n. 4
0
 def get(self):
   """ Render users template """
   current_session = Session().get_current_session(self)
   email = current_session.get_email()
   error = self.request.get("error")
   has_error = False
   if error:
     has_error = True 
     error = getErrorString(error)
   email = current_session.get_email()
   account = current_session.get_account_entity()
   badges = badges_dao.get_rendereable_badgeset(account)
   template_values = {'users_main': True,
                      'account_name': email,
                      'badges':badges,
                      'has_error': has_error,
                      'error': error}
   self.response.out.write(template.render(constants.TEMPLATE_PATHS.CONSOLE_DASHBOARD, template_values))
Esempio n. 5
0
 def get(self):
   current_session = Session().get_current_session(self)
   email = current_session.get_email()
   account = current_session.get_account_entity()
   error = self.request.get("error")
   has_error = False
   if error:
     has_error = True 
     error = getErrorString(error)
   badgeset = badges_dao.get_rendereable_badgeset(account)
   upload_url = blobstore.create_upload_url('/badge/u')
   template_values = {'badges_main': True,
                      'account_name': email,
                      'badges': badgeset,
                      'upload_url': upload_url,
                      'has_error': has_error,
                      'error': error}
   self.response.out.write(template.render(constants.TEMPLATE_PATHS.CONSOLE_DASHBOARD, template_values))
Esempio n. 6
0
 def get(self):
     """ Render users template """
     current_session = Session().get_current_session(self)
     email = current_session.get_email()
     error = self.request.get("error")
     has_error = False
     if error:
         has_error = True
         error = getErrorString(error)
     email = current_session.get_email()
     account = current_session.get_account_entity()
     badges = badges_dao.get_rendereable_badgeset(account)
     template_values = {
         'users_main': True,
         'account_name': email,
         'badges': badges,
         'has_error': has_error,
         'error': error
     }
     self.response.out.write(
         template.render(constants.TEMPLATE_PATHS.CONSOLE_DASHBOARD,
                         template_values))
Esempio n. 7
0
 def get(self):
     current_session = Session().get_current_session(self)
     email = current_session.get_email()
     account = current_session.get_account_entity()
     error = self.request.get("error")
     has_error = False
     if error:
         has_error = True
         error = getErrorString(error)
     badgeset = badges_dao.get_rendereable_badgeset(account)
     upload_url = blobstore.create_upload_url('/badge/u')
     template_values = {
         'badges_main': True,
         'account_name': email,
         'badges': badgeset,
         'upload_url': upload_url,
         'has_error': has_error,
         'error': error
     }
     self.response.out.write(
         template.render(constants.TEMPLATE_PATHS.CONSOLE_DASHBOARD,
                         template_values))
Esempio n. 8
0
  def milestones_values(self, user_ref, acc_ref, height, width):
    user_badges = badges_dao.get_user_badges(user_ref)
    acc_badges = badges_dao.get_rendereable_badgeset(acc_ref)
    mcase_ref = None
    if not acc_ref:
      mcase_ref = Milestones()
    else:
      try:
        mcase_ref = acc_ref.milestoneWidget
      except:
        mcase_ref = widgets_dao.add_milestones(acc_ref)

    if user_ref and user_ref.userid == constants.ANONYMOUS_USER:
      user_badges = []

    badge_count = 0
    display_badges = []
    for badge in user_badges:
      b = {}
      if badge.awarded == "yes":
        b["awarded"] = True
      else:
        b["awarded"] = True
      b["id"] = badge_count 
      b["awarded"] = badge.awarded
      b["pointsRequired"] = badge.pointsRequired

      # backward compatibility
      if badge.pointsRequired == 9999999999:
        b["pointsRequired"] = 0
   
      if badge.pointsEarned > badge.pointsRequired:
        b["pointsEarned"] = badge.pointsRequired
      else:  
        b["pointsEarned"] = badge.pointsEarned
      b["resource"] = badge.resource
      b["reason"] = badge.reason
      b["downloadLink"] = badge.downloadLink
      b["id"] = badge_count
      b["badgeRef"] = badge.badgeRef
      badge_count += 1
      display_badges.append(b)
    # Put all badges that have not been awarded
    to_add = []
    for aa in acc_badges:
      is_there = False
      for dd in display_badges:
        if aa["key"] == dd["badgeRef"].key().name():
          is_there = True
      if not is_there:
        b = {}
        b["id"] = badge_count 
        b["awarded"] = False
        b["pointsEarned"] = 0
        b["pointsRequired"] = 0
        # This name should not have changed
        b["resource"] = ""
        b["reason"] = aa["description"]
        b["downloadLink"] = aa["downloadLink"]
        badge_count += 1
        to_add.append(b)
    display_badges.extend(to_add)
    ret = {"status":"success"}
     
    for ii in mcase_ref.properties():
      ret[ii] = getattr(mcase_ref, ii)
    ret["badges"] = display_badges

    # Internal div's need to be slighy smaller than the iframe
    if width and height:
      try:
        width = int(width)
        height = int(height)
        # How did I get this equation? Trial and error.
        height = height - 2 *int(ret['borderThickness']) - 8
        width = width - 2 *int(ret['borderThickness']) - 8
        ret['height'] = height
        ret['width'] = width
      except:
        pass
    ret['barSize'] = ret['imageSize']
    return ret