Esempio n. 1
0
 def testRevertToGrid(self):
     """Tests reverting the DesignerGrid to the SmartGrid using the url interface."""
     # set up really fake designer grid
     self.client.get(reverse('instantiate_action', \
                             args=(self.action_slug,
                                   self.level_slug,
                                   2,
                                   2,
                                   self.draft_slug)))
     # set up fake smartgrid
     level = Level(name='Foo', slug='foo', priority=1)
     level.save()
     action = Activity(name='Test', slug='test', title='test title', description='description', \
                       type='activity', expected_duration=2)
     action.save()
     column = ColumnName(name='Column', slug='column')
     column.save()
     loc = ColumnGrid(level=level, column=1, name=column)
     loc.save()
     loc = Grid(level=level, column=1, row=2, action=action)
     loc.save()
     response = self.client.post(reverse('revert_to_grid', args=(self.draft_slug, )), {}, \
                                 follow=True)
     self.failUnlessEqual(response.status_code, 200)
     draft = smartgrid_mgr.get_designer_draft(self.draft_slug)
     try:
         smartgrid_mgr.get_designer_action(draft, self.action_slug)
         self.fail("Old Action should be deleted")
     except Http404:
         pass
     try:
         level = smartgrid_mgr.get_designer_level(draft, slug='foo')
     except Http404:
         self.fail("Didn't copy Level Foo to designer.")
     try:
         action = smartgrid_mgr.get_designer_action(draft, slug='test')
     except Http404:
         self.fail("Didn't copy action Test to designer.")
     try:
         column = smartgrid_mgr.get_designer_column_name(draft, slug='column')
     except Http404:
         self.fail("Didn't copy the ColumnName to designer.")
     qs = DesignerColumnGrid.objects.filter(name=column)
     self.failUnlessEqual(len(qs), 1, "Column is not in Designer Grid")
     loc = qs[0]
     self.failUnlessEqual(loc.level, level, "Wrong level in Designer Grid")
     self.failUnlessEqual(loc.column, 1, "Wrong column in Designer Grid")
     self.failUnlessEqual(loc.name, column, "Wrong column name in Designer Grid")
     qs = DesignerGrid.objects.filter(action=action)
     self.failUnlessEqual(len(qs), 1, "Action is not in Designer Grid")
     loc = qs[0]
     self.failUnlessEqual(loc.level, level, "Wrong level in Designer Grid")
     self.failUnlessEqual(loc.column, 1, "Wrong column in Designer Grid")
     self.failUnlessEqual(loc.row, 2, "Wrong row in Designer Grid")
Esempio n. 2
0
 def testGridToDesigner(self):
     """Tests instantiating a DesignerAction from an Action."""
     # clear the existing DesignerActions, if any.
     for des_act in DesignerAction.objects.filter(draft=self.draft,
                                                  slug=self.action_slug):
         des_act.delete()
     action = smartgrid_mgr.get_smartgrid_action(self.action_slug)
     des_action = smartgrid_mgr.instantiate_designer_action_from_smartgrid(self.draft, \
                                                                           slug=action.slug)
     self.assertTrue(
         des_action,
         "Couldn't instantiate designer action %s" % action.slug)
     self.assertTrue(smartgrid_mgr.get_designer_action(self.draft, self.action_slug), \
                     "Couldn't retrieve the designer action %s" % self.action_slug)
     # ensure the TextPropmptQuestions are there
     for tpq in TextPromptQuestion.objects.filter(action=action):
         try:
             des_tpq = get_object_or_404(DesignerTextPromptQuestion, draft=self.draft, \
                                         question=tpq.question, answer=tpq.answer, \
                                         action=des_action)
             self.assertTrue(des_tpq,
                             "Couldn't get DesignerTextPromptQuestion")
         except Http404:
             self.fail("Couldn't find DesignerTextPromptQuestion for %s" %
                       tpq)
Esempio n. 3
0
 def testLibraryToDesigner(self):
     """Tests instantiating a DesignerAction from a LibraryAction."""
     # LibraryAction -> DesignerAction
     lib_action = smartgrid_mgr.get_library_action(self.action_slug)
     des_action = smartgrid_mgr.instantiate_designer_action_from_library(self.draft, \
                                                                         lib_action.slug)
     self.assertTrue(
         des_action,
         "Couldn't instantiate designer action %s" % lib_action.slug)
     self.assertTrue(smartgrid_mgr.get_designer_action(self.draft, self.action_slug), \
                     "Couldn't retrieve the designer action %s" % self.action_slug)
     # ensure the TextPropmptQuestions are there
     for tpq in LibraryTextPromptQuestion.objects.filter(
             libraryaction=lib_action):
         try:
             des_tpq = get_object_or_404(DesignerTextPromptQuestion, draft=self.draft, \
                                         question=tpq.question, answer=tpq.answer, \
                                         action=des_action)
             self.assertTrue(des_tpq,
                             "Couldn't get DesignerTextPromptQuestion")
         except Http404:
             self.fail("Couldn't find DesignerTextPromptQuestion for %s" %
                       tpq)
     # LibraryColumnNames -> DesignerColumnNames
     lib_column = smartgrid_mgr.get_library_column_name(self.col_slug)
     self.assertTrue(lib_column,
                     "Couldn't get LibraryColumnName %s" % self.col_slug)
     des_column = smartgrid_mgr.instantiate_designer_column_from_library(self.draft, \
                                                                         self.col_slug)
     self.assertTrue(des_column,
                     "Couldn't get DesignerColumnName %s" % self.col_slug)
     self.assertEqual(self.draft, des_column.draft, "Drafts are not equal.")
Esempio n. 4
0
 def testLibraryToDesigner(self):
     """Tests instantiating a DesignerAction from a LibraryAction."""
     # LibraryAction -> DesignerAction
     lib_action = smartgrid_mgr.get_library_action(self.action_slug)
     des_action = smartgrid_mgr.instantiate_designer_action_from_library(self.draft, \
                                                                         lib_action.slug)
     self.assertTrue(des_action, "Couldn't instantiate designer action %s" % lib_action.slug)
     self.assertTrue(smartgrid_mgr.get_designer_action(self.draft, self.action_slug), \
                     "Couldn't retrieve the designer action %s" % self.action_slug)
     # ensure the TextPropmptQuestions are there
     for tpq in LibraryTextPromptQuestion.objects.filter(libraryaction=lib_action):
         try:
             des_tpq = get_object_or_404(DesignerTextPromptQuestion, draft=self.draft, \
                                         question=tpq.question, answer=tpq.answer, \
                                         action=des_action)
             self.assertTrue(des_tpq, "Couldn't get DesignerTextPromptQuestion")
         except Http404:
             self.fail("Couldn't find DesignerTextPromptQuestion for %s" % tpq)
     # LibraryColumnNames -> DesignerColumnNames
     lib_column = smartgrid_mgr.get_library_column_name(self.col_slug)
     self.assertTrue(lib_column, "Couldn't get LibraryColumnName %s" % self.col_slug)
     des_column = smartgrid_mgr.instantiate_designer_column_from_library(self.draft, \
                                                                         self.col_slug)
     self.assertTrue(des_column, "Couldn't get DesignerColumnName %s" % self.col_slug)
     self.assertEqual(self.draft, des_column.draft, "Drafts are not equal.")
Esempio n. 5
0
 def testMoveAction(self):
     """Tests moving a DesignerAction in the Grid using the url interface."""
     # Setup the action to move, ensure it is in the right place.
     draft = smartgrid_mgr.get_designer_draft(self.draft_slug)
     level = smartgrid_mgr.get_designer_level(draft, self.level_slug)
     self.client.get(reverse('instantiate_action', \
                             args=(self.action_slug,
                                   self.level_slug,
                                   2,
                                   2,
                                   self.draft_slug)))
     response = self.client.get(reverse('move_action', \
                                        args=(self.action_slug,
                                              self.level_slug,
                                              2,
                                              2,
                                              3,
                                              1,
                                              self.draft_slug)))
     self.failUnlessEqual(response.status_code, 200)
     action = smartgrid_mgr.get_designer_action(draft, self.action_slug)
     qs = DesignerGrid.objects.filter(draft=draft, action=action)
     self.assertEquals(len(qs), 1, "Got the wrong number of Actions expecting 1 got %s" % \
                       len(qs))
     loc = qs[0]
     self.assertIsNotNone(loc, "Didn't put the DesignerAction in the grid")
     self.assertEqual(loc.column, 3, "Got column %s expecting 3" % loc.column)
     self.assertEqual(loc.row, 1, "Got row %s expecting 1" % loc.row)
     self.assertEqual(loc.level, level, "Got wrong level")
Esempio n. 6
0
def drop_action(request, action_type, slug):
    """Handles the play tester dropping the given action defined by the action_type and slug."""
    draft = _get_current_draft(request)
    action = smartgrid_mgr.get_designer_action(draft=draft, slug=slug)
    _ = action_type
    user = request.user
    try:
        member = user.testeractionsubmittion_set.get(action=action,
                                                     approval_status="pending")
        member.delete()

        response = HttpResponseRedirect(
            reverse("tester_view_action", args=(
                action.type,
                action.slug,
            )))

        value = score_mgr.signup_points()
        notification = "%s dropped. you lose %d points." % (action.type, value)
        response.set_cookie("task_notify", notification)
        return response

    except ObjectDoesNotExist:
        pass

    messages.error = 'It appears that you are not participating in this action.'
    # Take them back to the action page.
    return HttpResponseRedirect(
        reverse("tester_view_action", args=(
            action.type,
            action.slug,
        )))
Esempio n. 7
0
def delete_action(request, action_slug, draft_slug):
    """Deletes the given Smart Grid Game Action."""
    _ = request
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    action = smartgrid_mgr.get_designer_action(draft, action_slug)
    action.delete()
    response = HttpResponseRedirect("/sgg_designer/?draft=%s" % draft.slug)
    return response
Esempio n. 8
0
def clear_from_grid(request, action_slug):
    """Removes the DesignerAction for the given action_slug from the DesignerGrid."""
    _ = request
    action = smartgrid_mgr.get_designer_action(action_slug)
    for grid in DesignerGrid.objects.filter(action=action):
        grid.delete()
    response = HttpResponseRedirect("/sgg_designer/")
    return response
Esempio n. 9
0
def delete_action(request, action_slug, draft_slug):
    """Deletes the given Smart Grid Game Action."""
    _ = request
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    action = smartgrid_mgr.get_designer_action(draft, action_slug)
    action.delete()
    response = HttpResponseRedirect("/sgg_designer/?draft=%s" % draft.slug)
    return response
Esempio n. 10
0
def clear_from_grid(request, action_slug, draft_slug):
    """Removes the DesignerAction for the given action_slug from the DesignerGrid."""
    _ = request
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    action = smartgrid_mgr.get_designer_action(draft, action_slug)
    for grid in DesignerGrid.objects.filter(draft=draft, action=action):
        grid.delete()
    response = HttpResponse("/sgg_designer/?draft=%s" % draft.slug)
    return response
Esempio n. 11
0
def clear_from_grid(request, action_slug, draft_slug):
    """Removes the DesignerAction for the given action_slug from the DesignerGrid."""
    _ = request
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    action = smartgrid_mgr.get_designer_action(draft, action_slug)
    for grid in DesignerGrid.objects.filter(draft=draft, action=action):
        grid.delete()
    response = HttpResponse("/sgg_designer/?draft=%s" % draft.slug)
    return response
Esempio n. 12
0
 def testDeleteAction(self):
     """Tests deleting a DesignerAction using the url interface."""
     # Setup the action to delete, ensure it is in the right place.
     self.client.get(reverse('instantiate_action', \
                             args=(self.action_slug,
                                   self.level_slug,
                                   2,
                                   2,
                                   self.draft_slug)))
     response = self.client.get(reverse('delete_designer_action', \
                                        args=(self.action_slug,
                                              self.draft_slug)))
     self.failUnlessEqual(response.status_code, 302)
     draft = smartgrid_mgr.get_designer_draft(self.draft_slug)
     try:
         smartgrid_mgr.get_designer_action(draft, self.action_slug)
         self.fail("Didn't delete DesignerAction %s" % self.action_slug)
     except Http404:
         pass
Esempio n. 13
0
def add_action(request, action_type, slug):
    """Handles the play tester doing the action defined by the given action_type and slug."""
    draft = _get_current_draft(request)
    action = smartgrid_mgr.get_designer_action(draft=draft, slug=slug)
    if action_type == "commitment":
        return view_test_commitments.add(request, action)
    elif action_type == "activity":
        return view_test_activities.add(request, action)
    else:  # event
        return view_test_events.add(request, action)
Esempio n. 14
0
def add_action(request, action_type, slug):
    """Handles the play tester doing the action defined by the given action_type and slug."""
    draft = _get_current_draft(request)
    action = smartgrid_mgr.get_designer_action(draft=draft, slug=slug)
    if action_type == "commitment":
        return view_test_commitments.add(request, action)
    elif action_type == "activity":
        return view_test_activities.add(request, action)
    else:       # event
        return view_test_events.add(request, action)
Esempio n. 15
0
def set_event_date(request):
    """Sets the event date from the EventDateForm."""
    if request.method == 'POST':
        form = EventDateForm(request.POST)
        if form.is_valid():
            event_slug = form.cleaned_data['event_slug']
            event = smartgrid_mgr.get_designer_action(event_slug)
            event_date = form.cleaned_data['event_date']
            event.event_date = event_date
            event.event_location = form.cleaned_data['location']
            event.save()
    response = HttpResponseRedirect("/sgg_designer/")
    return response
Esempio n. 16
0
def set_event_date(request, draft_slug):
    """Sets the event date from the EventDateForm."""
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    if request.method == 'POST':
        form = EventDateForm(request.POST)
        if form.is_valid():
            event_slug = form.cleaned_data['event_slug']
            event = smartgrid_mgr.get_designer_action(draft=draft,
                                                      slug=event_slug)
            event_date = form.cleaned_data['event_date']
            event.event_date = event_date
            event.event_location = form.cleaned_data['location']
            event.save()
    response = HttpResponseRedirect("/sgg_designer/?draft=%s" % draft.slug)
    return response
Esempio n. 17
0
def view_action(request, action_type, slug):
    """Shows the details of the action defined by the given action_type and slug."""
    draft = _get_current_draft(request)
    user = request.user
    view_objects = {}
    action = smartgrid_mgr.get_designer_action(draft=draft, slug=slug)
    action = play_tester.annotate_action_details(user, action)

    if not action.is_unlock:
        response = HttpResponseRedirect(reverse("tester_view", args=()))
        response.set_cookie("task_unlock_condition",
                            action.unlock_condition_text)
        return response

    if action_type == "commitment":
        form = view_test_commitments.view(request, action)
    elif action_type == "activity":
        form = view_test_activities.view(request, action)

        # if there is embedded widget, get the supplied objects
        if action.embedded_widget:
            view_module_name = 'apps.widgets.' + action.embedded_widget + '.views'
            view_objects[action.embedded_widget] = importlib.import_module(
                view_module_name).supply(request, None)
            view_objects['embedded_widget_template'] = "widgets/" + \
                action.embedded_widget + "/templates/index.html"
    elif action.type in ("event", ):  # action.event:
        form = view_test_events.view(request, action)
        # calculate available seat
        action.available_seat = action.event_max_seat - 1
    elif action_type == "filler":
        response = HttpResponseRedirect(reverse("tester_view", args=()))
        return response

    feedback = None

    return render_to_response(
        "tester_action.html", {
            "action": action,
            "form": form,
            "completed_count": 1,
            "team_members": [],
            "display_form": True if "display_form" in request.GET else False,
            "reminders": None,
            "view_objects": view_objects,
            "feedback_p": feedback,
        },
        context_instance=RequestContext(request))
Esempio n. 18
0
def preview_draft_action(request, action_slug, draft_slug):
    """Pre-views the DesignerAction with the given action_slug and in the given draft."""
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    action = smartgrid_mgr.get_designer_action(draft=draft, slug=action_slug)
    view_objects = {}
    # if there is embedded widget, get the supplied objects
    if action.embedded_widget:
        view_module_name = 'apps.widgets.' + action.embedded_widget + '.views'
        view_objects[action.embedded_widget] = importlib.import_module(
            view_module_name).supply(request, None)
        view_objects['embedded_widget_template'] = "widgets/" + \
            action.embedded_widget + "/templates/index.html"

    return render_to_response("action.html", {
    "action": action,
    "view_objects": view_objects,
    }, context_instance=RequestContext(request))
Esempio n. 19
0
def move_action(request, action_slug, level_slug, old_column, old_row, new_column, new_row):
    """Moves the Designer Grid Action from the old column and row to the new column and row."""
    _ = request
    _ = level_slug

    action = smartgrid_mgr.get_designer_action(action_slug)
    level = smartgrid_mgr.get_designer_level(level_slug)
    for grid in DesignerGrid.objects.filter(action=action, level=level):
        if grid.column == int(old_column) and grid.row == int(old_row):
            grid.column = new_column
            grid.row = new_row
            grid.save()

    #  Return the pk for the moved action.
    return HttpResponse(json.dumps({
            "pk": action.pk,
            }), mimetype="application/json")
Esempio n. 20
0
def move_palette_action(request, action_slug, level_slug, new_column, new_row):
    """Moves the Designer Grid Action from the palette to the new column and row."""
    _ = request

    action = smartgrid_mgr.get_designer_action(action_slug)
    level = DesignerLevel.objects.get(slug=level_slug)
    grid = DesignerGrid()
    grid.level = level
    grid.column = new_column
    grid.row = new_row
    grid.action = action
    grid.save()

    #  Return the pk for the moved action.
    return HttpResponse(json.dumps({
            "pk": action.pk,
            }), mimetype="application/json")
Esempio n. 21
0
 def testClearFromGrid(self):
     """Test removing a DesignerAction from the DesignerGrid using the url interface."""
     # Setup the action to move to the palette, ensure it is in the right place.
     self.client.get(reverse('instantiate_action', \
                             args=(self.action_slug,
                                   self.level_slug,
                                   2,
                                   2,
                                   self.draft_slug)))
     response = self.client.get(reverse('clear_from_grid', \
                                        args=(self.action_slug,
                                              self.draft_slug)))
     self.failUnlessEqual(response.status_code, 200)
     draft = smartgrid_mgr.get_designer_draft(self.draft_slug)
     action = smartgrid_mgr.get_designer_action(draft, self.action_slug)
     qs = DesignerGrid.objects.filter(action=action)
     self.failUnlessEqual(len(qs), 0, "Didn't remove the DesignerAction from the grid.")
Esempio n. 22
0
def view_action(request, action_type, slug):
    """Shows the details of the action defined by the given action_type and slug."""
    draft = _get_current_draft(request)
    user = request.user
    view_objects = {}
    action = smartgrid_mgr.get_designer_action(draft=draft, slug=slug)
    action = play_tester.annotate_action_details(user, action)

    if not action.is_unlock:
        response = HttpResponseRedirect(reverse("tester_view", args=()))
        response.set_cookie("task_unlock_condition", action.unlock_condition_text)
        return response

    if action_type == "commitment":
        form = view_test_commitments.view(request, action)
    elif action_type == "activity":
        form = view_test_activities.view(request, action)

        # if there is embedded widget, get the supplied objects
        if action.embedded_widget:
            view_module_name = 'apps.widgets.' + action.embedded_widget + '.views'
            view_objects[action.embedded_widget] = importlib.import_module(
                view_module_name).supply(request, None)
            view_objects['embedded_widget_template'] = "widgets/" + \
                action.embedded_widget + "/templates/index.html"
    elif action.type in ("event",):  # action.event:
        form = view_test_events.view(request, action)
        # calculate available seat
        action.available_seat = action.event_max_seat - 1
    elif action_type == "filler":
        response = HttpResponseRedirect(reverse("tester_view", args=()))
        return response

    feedback = None

    return render_to_response("tester_action.html", {
        "action": action,
        "form": form,
        "completed_count": 1,
        "team_members": [],
        "display_form": True if "display_form" in request.GET else False,
        "reminders": None,
        "view_objects": view_objects,
        "feedback_p": feedback,
        }, context_instance=RequestContext(request))
Esempio n. 23
0
def preview_draft_action(request, action_slug, draft_slug):
    """Pre-views the DesignerAction with the given action_slug and in the given draft."""
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    action = smartgrid_mgr.get_designer_action(draft=draft, slug=action_slug)
    view_objects = {}
    # if there is embedded widget, get the supplied objects
    if action.embedded_widget:
        view_module_name = 'apps.widgets.' + action.embedded_widget + '.views'
        view_objects[action.embedded_widget] = importlib.import_module(
            view_module_name).supply(request, None)
        view_objects['embedded_widget_template'] = "widgets/" + \
            action.embedded_widget + "/templates/index.html"

    return render_to_response("action.html", {
        "action": action,
        "view_objects": view_objects,
    },
                              context_instance=RequestContext(request))
Esempio n. 24
0
 def testGridToDesigner(self):
     """Tests instantiating a DesignerAction from an Action."""
     # clear the existing DesignerActions, if any.
     for des_act in DesignerAction.objects.filter(draft=self.draft, slug=self.action_slug):
         des_act.delete()
     action = smartgrid_mgr.get_smartgrid_action(self.action_slug)
     des_action = smartgrid_mgr.instantiate_designer_action_from_smartgrid(self.draft, \
                                                                           slug=action.slug)
     self.assertTrue(des_action, "Couldn't instantiate designer action %s" % action.slug)
     self.assertTrue(smartgrid_mgr.get_designer_action(self.draft, self.action_slug), \
                     "Couldn't retrieve the designer action %s" % self.action_slug)
     # ensure the TextPropmptQuestions are there
     for tpq in TextPromptQuestion.objects.filter(action=action):
         try:
             des_tpq = get_object_or_404(DesignerTextPromptQuestion, draft=self.draft, \
                                         question=tpq.question, answer=tpq.answer, \
                                         action=des_action)
             self.assertTrue(des_tpq, "Couldn't get DesignerTextPromptQuestion")
         except Http404:
             self.fail("Couldn't find DesignerTextPromptQuestion for %s" % tpq)
Esempio n. 25
0
def move_palette_action(request, action_slug, level_slug, new_column, new_row,
                        draft_slug):
    """Moves the Designer Grid Action from the palette to the new column and row."""
    _ = request
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    action = smartgrid_mgr.get_designer_action(draft, action_slug)
    level = smartgrid_mgr.get_designer_level(draft, level_slug)
    grid = DesignerGrid()
    grid.level = level
    grid.column = new_column
    grid.row = new_row
    grid.action = action
    grid.draft = draft
    grid.save()

    #  Return the pk for the moved action.
    return HttpResponse(json.dumps({
        "pk": action.pk,
    }),
                        mimetype="application/json")
Esempio n. 26
0
def move_action(request, action_slug, level_slug, old_column, old_row, new_column, new_row, \
                draft_slug):
    """Moves the Designer Grid Action from the old column and row to the new column and row."""
    _ = request
    _ = level_slug
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    action = smartgrid_mgr.get_designer_action(draft, action_slug)
    level = smartgrid_mgr.get_designer_level(draft, level_slug)
    for grid in DesignerGrid.objects.filter(draft=draft,
                                            action=action,
                                            level=level):
        if grid.column == int(old_column) and grid.row == int(old_row):
            grid.column = new_column
            grid.row = new_row
            grid.save()

    #  Return the pk for the moved action.
    return HttpResponse(json.dumps({
        "pk": action.pk,
    }),
                        mimetype="application/json")
Esempio n. 27
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. 28
0
 def testInstantiateAction(self):
     """Test instantiating DesignerAction from LibraryAction using the url interface."""
     response = self.client.get(reverse('instantiate_action', \
                                        args=(self.action_slug,
                                              self.level_slug,
                                              2,
                                              2,
                                              self.draft_slug)))
     self.failUnlessEqual(response.status_code, 200)
     try:
         draft = smartgrid_mgr.get_designer_draft(self.draft_slug)
         level = smartgrid_mgr.get_designer_level(draft, self.level_slug)
         action = smartgrid_mgr.get_designer_action(draft, self.action_slug)
         qs = DesignerGrid.objects.filter(draft=draft, action=action)
         self.assertEquals(len(qs), 1, "Got the wrong number of Actions expecting 1 got %s" % \
                           len(qs))
         loc = qs[0]
         self.assertIsNotNone(loc, "Didn't put the DesignerAction in the grid")
         self.assertEqual(loc.column, 2, "Got column %s expecting 2" % loc.column)
         self.assertEqual(loc.row, 2, "Got row %s expecting 2" % loc.row)
         self.assertEqual(loc.level, level, "Got wrong level")
     except Http404:
         self.fail("Got 404 response, designer objects didn't instantiate")
Esempio n. 29
0
def drop_action(request, action_type, slug):
    """Handles the play tester dropping the given action defined by the action_type and slug."""
    draft = _get_current_draft(request)
    action = smartgrid_mgr.get_designer_action(draft=draft, slug=slug)
    _ = action_type
    user = request.user
    try:
        member = user.testeractionsubmittion_set.get(action=action, approval_status="pending")
        member.delete()

        response = HttpResponseRedirect(
            reverse("tester_view_action", args=(action.type, action.slug,)))

        value = score_mgr.signup_points()
        notification = "%s dropped. you lose %d points." % (action.type, value)
        response.set_cookie("task_notify", notification)
        return response

    except ObjectDoesNotExist:
        pass

    messages.error = 'It appears that you are not participating in this action.'
    # Take them back to the action page.
    return HttpResponseRedirect(reverse("tester_view_action", args=(action.type, action.slug,)))
Esempio n. 30
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. 31
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
Esempio n. 32
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