Пример #1
0
def eval_unlock(user, action):
    """Determine the unlock status of a task by dependency expression"""
    predicates = action.unlock_condition
    if not predicates:
        return False
    draft = smartgrid_mgr.get_designer_draft(action.draft)
    return predicate_mgr.eval_play_tester_predicates(predicates, user, draft)
Пример #2
0
def eval_unlock(user, action):
    """Determine the unlock status of a task by dependency expression"""
    predicates = action.unlock_condition
    if not predicates:
        return False
    draft = smartgrid_mgr.get_designer_draft(action.draft)
    return predicate_mgr.eval_play_tester_predicates(predicates, user, draft)
Пример #3
0
def get_designer_test_levels(draft, user):
    """Returns a list of DesignerLevels with their unlock conditions set according to the
    test predicates."""
    levels = []
    for level in Level.objects.all():
        level.is_unlock = predicate_mgr.eval_play_tester_predicates(level.unlock_condition,
                                                                    user, draft)
        levels.append(level)
    return levels
Пример #4
0
def get_designer_test_levels(draft, user):
    """Returns a list of DesignerLevels with their unlock conditions set according to the
    test predicates."""
    levels = []
    for level in Level.objects.all():
        level.is_unlock = predicate_mgr.eval_play_tester_predicates(level.unlock_condition,
                                                                    user, draft)
        levels.append(level)
    return levels
Пример #5
0
def is_level_unlock(user, level, draft):
    """return True if the level is unlock."""
    return level and predicate_mgr.eval_play_tester_predicates(level.unlock_condition, user, draft)
Пример #6
0
def get_designer_grid(draft, user):  # pylint: disable=R0914,R0912
    """Returns the play tester version of the Smart Grid Game for the given draft."""
    levels = []
    for level in DesignerLevel.objects.filter(draft=draft):
        level.is_unlock = predicate_mgr.eval_play_tester_predicates(level.unlock_condition,
                                                                    user=user,
                                                                    draft_slug=draft.slug)
        if level.is_unlock:  # only include unlocked levels
            if level.unlock_condition != "True":
                contents = "%s is unlocked." % level
                obj, created = UserNotification.objects.\
                    get_or_create(recipient=user,
                                  contents=contents,
                                  level=UserNotification.LEVEL_CHOICES[2][0])
                if created:  # only show the notification if it is new
                    obj.display_alert = True
                    obj.save()
            level_ret = []
            level.is_complete = True
            level_ret.append(level)
            level_ret.append(DesignerColumnGrid.objects.filter(draft=draft, level=level))
#                level_ret.append(Grid.objects.filter(level=level))

            max_column = len(DesignerColumnGrid.objects.filter(draft=draft, level=level))
            max_row = 0
            just_actions = []
            # update each action
            for row in DesignerGrid.objects.filter(draft=draft, level=level):
                action = smartgrid_mgr.get_designer_action(draft=draft, slug=row.action.slug)
                action.row = row.row
                if row.row > max_row:
                    max_row = row.row
                action.column = row.column
                if row.column > max_column:
                    max_column = row.column
                action = annotate_action_details(user, action)
                # if there is one action is not completed, set the level to in-completed
                if not action.completed:
                    level.is_complete = False
                just_actions.append(action)
            level_ret.append(just_actions)
            columns = []
            for cat in level_ret[1]:
                if cat.column not in columns:
                    columns.append(cat.column)
            for act in level_ret[2]:
                if act.column not in columns:
                    columns.append(act.column)
            level_ret.append(columns)
            level_ret.append(max_column)
            level_ret.append(max_row)
            levels.append(level_ret)
        else:
            level_ret = []
            level_ret.append(level)
            level_ret.append([])
            level_ret.append([])
            level_ret.append([])
            level_ret.append(0)
            level_ret.append(0)
            levels.append(level_ret)
    return levels
Пример #7
0
def is_level_unlock(user, level, draft):
    """return True if the level is unlock."""
    return level and predicate_mgr.eval_play_tester_predicates(
        level.unlock_condition, user, draft)
Пример #8
0
def get_designer_grid(draft, user):  # pylint: disable=R0914,R0912
    """Returns the play tester version of the Smart Grid Game for the given draft."""
    levels = []
    for level in DesignerLevel.objects.filter(draft=draft):
        level.is_unlock = predicate_mgr.eval_play_tester_predicates(
            level.unlock_condition, user=user, draft_slug=draft.slug)
        if level.is_unlock:  # only include unlocked levels
            if level.unlock_condition != "True":
                contents = "%s is unlocked." % level
                obj, created = UserNotification.objects.\
                    get_or_create(recipient=user,
                                  contents=contents,
                                  level=UserNotification.LEVEL_CHOICES[2][0])
                if created:  # only show the notification if it is new
                    obj.display_alert = True
                    obj.save()
            level_ret = []
            level.is_complete = True
            level_ret.append(level)
            level_ret.append(
                DesignerColumnGrid.objects.filter(draft=draft, level=level))
            #                level_ret.append(Grid.objects.filter(level=level))

            max_column = len(
                DesignerColumnGrid.objects.filter(draft=draft, level=level))
            max_row = 0
            just_actions = []
            # update each action
            for row in DesignerGrid.objects.filter(draft=draft, level=level):
                action = smartgrid_mgr.get_designer_action(
                    draft=draft, slug=row.action.slug)
                action.row = row.row
                if row.row > max_row:
                    max_row = row.row
                action.column = row.column
                if row.column > max_column:
                    max_column = row.column
                action = annotate_action_details(user, action)
                # if there is one action is not completed, set the level to in-completed
                if not action.completed:
                    level.is_complete = False
                just_actions.append(action)
            level_ret.append(just_actions)
            columns = []
            for cat in level_ret[1]:
                if cat.column not in columns:
                    columns.append(cat.column)
            for act in level_ret[2]:
                if act.column not in columns:
                    columns.append(act.column)
            level_ret.append(columns)
            level_ret.append(max_column)
            level_ret.append(max_row)
            levels.append(level_ret)
        else:
            level_ret = []
            level_ret.append(level)
            level_ret.append([])
            level_ret.append([])
            level_ret.append([])
            level_ret.append(0)
            level_ret.append(0)
            levels.append(level_ret)
    return levels
Пример #9
0
 def testAllTestPredicateStrings(self):
     """Tests all the predicate strings using the tester predicates."""
     for pred in self.predicates:
         print pred
         predicate_mgr.eval_play_tester_predicates(pred, self.user, "test")
Пример #10
0
 def testAllTestPredicateStrings(self):
     """Tests all the predicate strings using the tester predicates."""
     for pred in self.predicates:
         print pred
         predicate_mgr.eval_play_tester_predicates(pred, self.user, "test")