Exemplo n.º 1
0
    def testGetUnread(self):
        """
    Test that we can get the user's unread notifications.
    """
        user = User.objects.create_user("test", "*****@*****.**")
        for i in range(0, 3):
            notification = UserNotification(recipient=user,
                                            contents="Test notification %i" %
                                            i)
            notification.save()

        notifications = get_unread_notifications(user)
        self.assertEqual(notifications["alerts"].count(), 0,
                         "There should not be any alert notifications.")
        unread = notifications["unread"]
        self.assertEqual(unread.count(), 3,
                         "There should be three unread notifications.")
        alert = UserNotification(recipient=user,
                                 contents="Alert notification",
                                 display_alert=True)
        alert.save()

        notifications = get_unread_notifications(user)
        self.assertEqual(notifications["alerts"][0], alert,
                         "Alert notification should have been returned.")
        self.assertEqual(unread.count(), 4,
                         "There should be four unread notifications.")
Exemplo n.º 2
0
 def testGetUnread(self):
   """
   Test that we can get the user's unread notifications.
   """
   user = User.objects.create_user("test", "*****@*****.**")
   for i in range(0, 3):
     notification = UserNotification(recipient=user, contents="Test notification %i" % i)
     notification.save()
     
   notifications = get_unread_notifications(user)
   self.assertEqual(notifications["alerts"].count(), 0, "There should not be any alert notifications.")
   unread = notifications["unread"]
   self.assertEqual(unread.count(), 3, "There should be three unread notifications.")
   alert = UserNotification(recipient=user, contents="Alert notification", display_alert=True)
   alert.save()
   
   notifications = get_unread_notifications(user)
   self.assertEqual(notifications["alerts"][0], alert, "Alert notification should have been returned.")
   self.assertEqual(unread.count(), 4, "There should be four unread notifications.")
Exemplo n.º 3
0
def competition(request):
  """Provides access to standard competition constants within a template."""
  user = request.user
  
  # We may want to retrieve theme settings for insertion into CSS.
  theme_name, theme_dict = get_theme()
  
  # Get user-specific information.
  floor_count = Floor.objects.count()
  overall_member_count = Profile.objects.count()
  floor_member_count = None
  quests = None
  notifications = None
    
  if user.is_authenticated():
    quests = get_quests(user)
    notifications = get_unread_notifications(user, limit=3)
    if user.get_profile().floor:
      floor_member_count = user.get_profile().floor.profile_set.count()
  
  # Get current round info.
  current_round = get_current_round() or "Overall"
  
  # Get Facebook info.
  try:
    facebook_app_id = settings.FACEBOOK_APP_ID
  except AttributeError:
    facebook_app_id = None
    
  return {
    "STATIC_URL": settings.STATIC_URL,
    "COMPETITION_NAME": settings.COMPETITION_NAME,
    "COMPETITION_POINT_NAME": settings.COMPETITION_POINT_NAME or "point",
    "THEME_NAME": theme_name, 
    "THEME": theme_dict,
    "FLOOR_COUNT": floor_count,
    "FLOOR_MEMBER_COUNT": floor_member_count,
    "OVERALL_MEMBER_COUNT": overall_member_count,
    "ROUNDS": get_rounds_for_header(),
    "FLOOR_LABEL": get_floor_label(),
    "CURRENT_ROUND": current_round,
    "CURRENT_ROUND_INFO": get_current_round_info(),
    "FACEBOOK_APP_ID": facebook_app_id,
    "QUESTS": quests,
    "NOTIFICATIONS": notifications,
    "IN_COMPETITION": in_competition(),
    "SPREADSHEETS": {
      "THIRTY_DAYS": settings.ENERGY_THIRTY_DAYS_URL,
      "ENERGY_GOAL": settings.ENERGY_GOAL_URL,
      "POWER": settings.POWER_GAUGE_URL,
    }
  }
Exemplo n.º 4
0
def competition(request):
    """Provides access to standard competition constants within a template."""
    user = request.user

    # We may want to retrieve theme settings for insertion into CSS.
    theme_name, theme_dict = get_theme()

    # Get user-specific information.
    floor_count = Floor.objects.count()
    overall_member_count = Profile.objects.count()
    floor_member_count = None
    quests = None
    quest_help = None
    notifications = None

    # Try to load quest_help from the database.
    try:
        quest_help = HelpTopic.objects.get(slug="quests", category="widget")
    except HelpTopic.DoesNotExist:
        pass

    if user.is_authenticated():
        quests = get_quests(user)
        notifications = get_unread_notifications(user, limit=3)
        if user.get_profile().floor:
            floor_member_count = user.get_profile().floor.profile_set.count()

    # Get current round info.
    current_round = get_current_round()

    # Get Facebook info.
    try:
        facebook_app_id = settings.FACEBOOK_APP_ID
    except AttributeError:
        facebook_app_id = None

    return {
        "COMPETITION_NAME": settings.COMPETITION_NAME,
        "COMPETITION_POINT_NAME": settings.COMPETITION_POINT_NAME or "point",
        "THEME_NAME": theme_name,
        "THEME": theme_dict,
        "FLOOR_COUNT": floor_count,
        "FLOOR_MEMBER_COUNT": floor_member_count,
        "OVERALL_MEMBER_COUNT": overall_member_count,
        "ROUNDS": get_rounds_for_header(),
        "FLOOR_LABEL": get_floor_label(),
        "CURRENT_ROUND": current_round,
        "FACEBOOK_APP_ID": facebook_app_id,
        "QUESTS": quests,
        "QUEST_HELP": quest_help,
        "NOTIFICATIONS": notifications,
    }
Exemplo n.º 5
0
def competition(request):
    """Provides access to standard competition constants within a template."""
    user = request.user

    # We may want to retrieve theme settings for insertion into CSS.
    theme_name, theme_dict = get_theme()

    # Get user-specific information.
    floor_count = Floor.objects.count()
    overall_member_count = Profile.objects.count()
    floor_member_count = None
    quests = None
    notifications = None

    if user.is_authenticated():
        quests = get_quests(user)
        notifications = get_unread_notifications(user, limit=3)
        if user.get_profile().floor:
            floor_member_count = user.get_profile().floor.profile_set.count()

    # Get current round info.
    current_round = get_current_round() or "Overall"

    # Get Facebook info.
    try:
        facebook_app_id = settings.FACEBOOK_APP_ID
    except AttributeError:
        facebook_app_id = None

    return {
        "STATIC_URL": settings.STATIC_URL,
        "COMPETITION_NAME": settings.COMPETITION_NAME,
        "COMPETITION_POINT_NAME": settings.COMPETITION_POINT_NAME or "point",
        "THEME_NAME": theme_name,
        "THEME": theme_dict,
        "FLOOR_COUNT": floor_count,
        "FLOOR_MEMBER_COUNT": floor_member_count,
        "OVERALL_MEMBER_COUNT": overall_member_count,
        "ROUNDS": get_rounds_for_header(),
        "FLOOR_LABEL": get_floor_label(),
        "CURRENT_ROUND": current_round,
        "CURRENT_ROUND_INFO": get_current_round_info(),
        "FACEBOOK_APP_ID": facebook_app_id,
        "QUESTS": quests,
        "NOTIFICATIONS": notifications,
        "IN_COMPETITION": in_competition(),
        "SPREADSHEETS": {
            "THIRTY_DAYS": settings.ENERGY_THIRTY_DAYS_URL,
            "ENERGY_GOAL": settings.ENERGY_GOAL_URL,
            "POWER": settings.POWER_GAUGE_URL,
        }
    }