Esempio n. 1
0
def check_designer_unlock_dates(draft):
    """Checks all the DesignerAction unlock_conditions looking for unlock_on_date predicates.
    Checks the dates in the predicate to ensure they are in the challenge."""
    ret = {}
    ret[_ERRORS] = []
    ret[_WARNINGS] = []
    for action in DesignerAction.objects.filter(draft=draft):
        if action.unlock_condition:
            l = action.unlock_condition.split('unlock_on_date(')
            if len(l) > 1:
                index = l[1].find(')')
                date_string = l[1][:index].strip('"\'')
                unlock_date = datetime.strptime(date_string, "%Y-%m-%d")
                if __is_after_challenge(
                        datetime.combine(unlock_date, time(0, 0))):
                    message = "unlock date %s is after challenge end %s" % \
                    (unlock_date.date(), challenge_mgr.get_challenge_end().date())
                    ret[_ERRORS].append(Error(message=message, action=action))
                if not __is_in_rounds(datetime.combine(unlock_date, time(0,
                                                                         0))):
                    message = "unlock date %s is not in a round" % unlock_date.date(
                    )
                    ret[_WARNINGS].append(Warn(message=message, \
                                                action=action))

    return ret
Esempio n. 2
0
def check_grid_pub_exp_dates(draft):
    """Returns a dictionary of Errors and Warnings for DesignerActions in the grid whose pub_date or
     exp_date are not in the challenge."""
    ret = {}
    ret[_ERRORS] = []
    ret[_WARNINGS] = []
    challenge_start = challenge_mgr.get_challenge_start()
    challenge_end = challenge_mgr.get_challenge_end()
    for loc in DesignerGrid.objects.filter(draft=draft):
        if loc.action.pub_date > challenge_end.date():
            message = "Publication Date %s after end of Challenge %s" % (loc.action.pub_date, \
                                                                         challenge_end.date())
            ret[_ERRORS].append(Error(message=message, \
                                       action=loc.action))
        if loc.action.expire_date and \
            loc.action.expire_date < \
            challenge_start.date():
            message = "Expiration date %s is before beginning of Challenge %s" % \
            (loc.action.expire_date, challenge_start.date())
            ret[_ERRORS].append(Error(message=message, \
                                       action=loc.action))


#         if not __is_in_rounds(datetime.combine(loc.action.pub_date, time(0, 0))):
#             message = "Publication Date %s isn't in a round" % loc.action.pub_date
#             ret[_WARNINGS].append(Warn(message=message, \
#                                         action=loc.action))
#         if loc.action.expire_date and not \
#             __is_in_rounds(datetime.combine(loc.action.expire_date, time(0, 0))):
#             message = "Expiration Date isn't in a round" % loc.action.expire_date
#             ret[_WARNINGS].append(Warn(message=message, \
#                                         action=loc.action))
    return ret
Esempio n. 3
0
File: gcc.py Progetto: csdl/makahiki
def check_grid_pub_exp_dates(draft):
    """Returns a dictionary of Errors and Warnings for DesignerActions in the grid whose pub_date or
     exp_date are not in the challenge."""
    ret = {}
    ret[_ERRORS] = []
    ret[_WARNINGS] = []
    challenge_start = challenge_mgr.get_challenge_start()
    challenge_end = challenge_mgr.get_challenge_end()
    for loc in DesignerGrid.objects.filter(draft=draft):
        if loc.action.pub_date > challenge_end.date():
            message = "Publication Date %s after end of Challenge %s" % (loc.action.pub_date, \
                                                                         challenge_end.date())
            ret[_ERRORS].append(Error(message=message, \
                                       action=loc.action))
        if loc.action.expire_date and \
            loc.action.expire_date < \
            challenge_start.date():
            message = "Expiration date %s is before beginning of Challenge %s" % \
            (loc.action.expire_date, challenge_start.date())
            ret[_ERRORS].append(Error(message=message, \
                                       action=loc.action))
#         if not __is_in_rounds(datetime.combine(loc.action.pub_date, time(0, 0))):
#             message = "Publication Date %s isn't in a round" % loc.action.pub_date
#             ret[_WARNINGS].append(Warn(message=message, \
#                                         action=loc.action))
#         if loc.action.expire_date and not \
#             __is_in_rounds(datetime.combine(loc.action.expire_date, time(0, 0))):
#             message = "Expiration Date isn't in a round" % loc.action.expire_date
#             ret[_WARNINGS].append(Warn(message=message, \
#                                         action=loc.action))
    return ret
Esempio n. 4
0
def check_pub_exp_dates(draft):
    """Returns a dictionary of Errors and Warnings for DesignerActions whose pub_date or
     exp_date are not in the challenge."""
    ret = {}
    ret[_ERRORS] = []
    ret[_WARNINGS] = []
    challenge_start = challenge_mgr.get_challenge_start()
    challenge_end = challenge_mgr.get_challenge_end()
    for action in DesignerAction.objects.filter(draft=draft):
        if action.pub_date > challenge_end.date():
            ret[_ERRORS].append(Error(message="Publication Date after end of Challenge", \
                                       action=action))
        if action.expire_date and \
            datetime.combine(action.expire_date, time(0, 0)) < \
            challenge_start.date():
            ret[_ERRORS].append(Error(message="Expiration date before beginning of Challenge", \
                                       action=action))
        if not __is_in_rounds(datetime.combine(action.pub_date, time(0, 0))):
            ret[_WARNINGS].append(Warn(message="Publication Date isn't in a round", \
                                        action=action))
        if action.expire_date and not \
            __is_in_rounds(datetime.combine(action.expire_date, time(0, 0))):
            ret[_WARNINGS].append(Warn(message="Expiration Date isn't in a round", \
                                        action=action))
    return ret
Esempio n. 5
0
File: gcc.py Progetto: csdl/makahiki
def check_pub_exp_dates(draft):
    """Returns a dictionary of Errors and Warnings for DesignerActions whose pub_date or
     exp_date are not in the challenge."""
    ret = {}
    ret[_ERRORS] = []
    ret[_WARNINGS] = []
    challenge_start = challenge_mgr.get_challenge_start()
    challenge_end = challenge_mgr.get_challenge_end()
    for action in DesignerAction.objects.filter(draft=draft):
        if action.pub_date > challenge_end.date():
            ret[_ERRORS].append(Error(message="Publication Date after end of Challenge", \
                                       action=action))
        if action.expire_date and \
            datetime.combine(action.expire_date, time(0, 0)) < \
            challenge_start.date():
            ret[_ERRORS].append(Error(message="Expiration date before beginning of Challenge", \
                                       action=action))
        if not __is_in_rounds(datetime.combine(action.pub_date, time(0, 0))):
            ret[_WARNINGS].append(Warn(message="Publication Date isn't in a round", \
                                        action=action))
        if action.expire_date and not \
            __is_in_rounds(datetime.combine(action.expire_date, time(0, 0))):
            ret[_WARNINGS].append(Warn(message="Expiration Date isn't in a round", \
                                        action=action))
    return ret
Esempio n. 6
0
def __is_in_challenge(date):
    """Returns True if the given date is between the Challenge start and end dates."""
    if date:
        start = challenge_mgr.get_challenge_start()
        end = challenge_mgr.get_challenge_end()
        return date >= start and date <= end
    else:
        return False
Esempio n. 7
0
File: gcc.py Progetto: csdl/makahiki
def __is_in_challenge(date):
    """Returns True if the given date is between the Challenge start and end dates."""
    if date:
        start = challenge_mgr.get_challenge_start()
        end = challenge_mgr.get_challenge_end()
        return date >= start and date <= end
    else:
        return False
Esempio n. 8
0
def check_pub_exp_dates(draft):
    """Returns a list of DesignerAction slugs whose pub_date or exp_date are not in the
     challenge."""
    ret = []
    trees = build_designer_trees(draft)
    challenge_start = challenge_mgr.get_challenge_start()
    challenge_end = challenge_mgr.get_challenge_end()
    # check only DesignerActions in the grid?
    for action in DesignerAction.objects.filter(draft=draft):
        if action.pub_date > challenge_end.date() or (action.expire_date and \
                                                      action.expire_date < challenge_start.date()):
            for k in list(trees):
                tree = trees[k]
                node = tree.get_node(action.slug)
                if node:
                    ret.append(node.admin_link())
    return ret
Esempio n. 9
0
File: gcc.py Progetto: csdl/makahiki
def check_grid_event_dates(draft):
    """Returns a list of Errors for DesignerEvents in the grid whose event_date isn't in the
    challenge or isn't during a round."""
    ret = []
    for loc in DesignerGrid.objects.filter(draft=draft):
        if loc.action.type == 'event':
            event = smartgrid_mgr.get_designer_action(draft=draft, slug=loc.action.slug)
            if not __is_in_rounds(event.event_date):
                if event.event_date:
                    message = "Event date %s isn't in a round" % event.event_date.date()
                else:
                    message = "Event doesn't have an event date."
                ret.append(Error(message=message, action=event))
            if not __is_in_challenge(event.event_date):
                if event.event_date:
                    message = "Event date %s isn't in the challenge %s - %s" % \
                    (event.event_date.date(), challenge_mgr.get_challenge_start().date(), \
                     challenge_mgr.get_challenge_end().date())
                else:
                    message = "Event doesn't have an event date."
                ret.append(Error(message=message, action=event))
    return ret
Esempio n. 10
0
File: gcc.py Progetto: csdl/makahiki
def check_designer_unlock_dates(draft):
    """Checks all the DesignerAction unlock_conditions looking for unlock_on_date predicates.
    Checks the dates in the predicate to ensure they are in the challenge."""
    ret = {}
    ret[_ERRORS] = []
    ret[_WARNINGS] = []
    for action in DesignerAction.objects.filter(draft=draft):
        if action.unlock_condition:
            l = action.unlock_condition.split('unlock_on_date(')
            if len(l) > 1:
                index = l[1].find(')')
                date_string = l[1][:index].strip('"\'')
                unlock_date = datetime.strptime(date_string, "%Y-%m-%d")
                if __is_after_challenge(datetime.combine(unlock_date, time(0, 0))):
                    message = "unlock date %s is after challenge end %s" % \
                    (unlock_date.date(), challenge_mgr.get_challenge_end().date())
                    ret[_ERRORS].append(Error(message=message, action=action))
                if not __is_in_rounds(datetime.combine(unlock_date, time(0, 0))):
                    message = "unlock date %s is not in a round" % unlock_date.date()
                    ret[_WARNINGS].append(Warn(message=message, \
                                                action=action))

    return ret
Esempio n. 11
0
def check_grid_event_dates(draft):
    """Returns a list of Errors for DesignerEvents in the grid whose event_date isn't in the
    challenge or isn't during a round."""
    ret = []
    for loc in DesignerGrid.objects.filter(draft=draft):
        if loc.action.type == 'event':
            event = smartgrid_mgr.get_designer_action(draft=draft,
                                                      slug=loc.action.slug)
            if not __is_in_rounds(event.event_date):
                if event.event_date:
                    message = "Event date %s isn't in a round" % event.event_date.date(
                    )
                else:
                    message = "Event doesn't have an event date."
                ret.append(Error(message=message, action=event))
            if not __is_in_challenge(event.event_date):
                if event.event_date:
                    message = "Event date %s isn't in the challenge %s - %s" % \
                    (event.event_date.date(), challenge_mgr.get_challenge_start().date(), \
                     challenge_mgr.get_challenge_end().date())
                else:
                    message = "Event doesn't have an event date."
                ret.append(Error(message=message, action=event))
    return ret
Esempio n. 12
0
def __is_after_challenge(date):
    """Returns True if the given date is after the Challenge end date."""
    return date > challenge_mgr.get_challenge_end()
Esempio n. 13
0
File: gcc.py Progetto: csdl/makahiki
def __is_after_challenge(date):
    """Returns True if the given date is after the Challenge end date."""
    return date > challenge_mgr.get_challenge_end()