Esempio n. 1
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. 2
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. 3
0
def delete_level(request, draft_slug):
    """Deletes the DesignerLevel for the given level_slug and removes all the location
    information for the level."""
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    if request.method == 'POST':
        form = DeleteLevelForm(request.POST)
        if form.is_valid():
            level_slug = form.cleaned_data['level_slug']
            level = smartgrid_mgr.get_designer_level(draft, slug=level_slug)
            for grid in DesignerColumnGrid.objects.filter(draft=draft, level=level):
                grid.delete()
            for grid in DesignerGrid.objects.filter(draft=draft, level=level):
                grid.delete()
            level.delete()
    response = HttpResponseRedirect("/sgg_designer/?draft=%s" % draft.slug)
    return response
Esempio n. 4
0
def instantiate_column(request, col_slug, level_slug, column, draft_slug):
    """Instantiates the DesignerColumnName from the LibraryColumnName and places it in the
    Grid at the given level and column."""
    _ = request
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    col = smartgrid_mgr.instantiate_designer_column_from_library(draft, col_slug)

    level = smartgrid_mgr.get_designer_level(draft, level_slug)
    grid, _ = DesignerColumnGrid.objects.get_or_create(draft=draft, name=col, level=level)
    grid.column = column
    grid.save()

    #  Return the new pk for the instantiated DesignerColumnName.
    return HttpResponse(json.dumps({
            "pk": col.pk,
            }), mimetype="application/json")
Esempio n. 5
0
def delete_level(request, draft_slug):
    """Deletes the DesignerLevel for the given level_slug and removes all the location
    information for the level."""
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    if request.method == 'POST':
        form = DeleteLevelForm(request.POST)
        if form.is_valid():
            level_slug = form.cleaned_data['level_slug']
            level = smartgrid_mgr.get_designer_level(draft, slug=level_slug)
            for grid in DesignerColumnGrid.objects.filter(draft=draft,
                                                          level=level):
                grid.delete()
            for grid in DesignerGrid.objects.filter(draft=draft, level=level):
                grid.delete()
            level.delete()
    response = HttpResponseRedirect("/sgg_designer/?draft=%s" % draft.slug)
    return response
Esempio n. 6
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. 7
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. 8
0
    def setUp(self):
        """Sets up the test evironment for the Designer views."""
        self.user = test_utils.setup_superuser(username="******", password="******")

        challenge_mgr.register_page_widget("sgg_designer", "smartgrid_design")
        from apps.managers.cache_mgr import cache_mgr
        cache_mgr.clear()

        self.client.login(username="******", password="******")
        try:
            draft = smartgrid_mgr.get_designer_draft(self.draft_slug)
        except Http404:  # shouldn't happen Default draft is defined in base_settings
            draft = Draft(name='Default', slug='default')
            draft.save()
        try:
            level = smartgrid_mgr.get_designer_level(draft, self.level_slug)
        except Http404:  # ensure there is a DesignerLevel
            level = DesignerLevel(name="Level 1", slug=self.level_slug, priority=1, draft=draft)
            level.save()
Esempio n. 9
0
def instantiate_action(request, action_slug, level_slug, column, row, draft_slug):
    """Instantiated the Smart Grid Game Action from the Library Action with the
    given level, column, and row."""
    _ = request
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    grid_action = smartgrid_mgr.instantiate_designer_action_from_library(draft, action_slug)
    level = smartgrid_mgr.get_designer_level(draft, level_slug)
    grid = DesignerGrid()
    grid.level = level
    grid.column = column
    grid.row = row
    grid.action = grid_action
    grid.draft = draft
    grid.save()

    #  Return the new pk for the instantiated action.
    return HttpResponse(json.dumps({
            "pk": grid_action.pk,
            }), mimetype="application/json")
Esempio n. 10
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. 11
0
def instantiate_column(request, col_slug, level_slug, column, draft_slug):
    """Instantiates the DesignerColumnName from the LibraryColumnName and places it in the
    Grid at the given level and column."""
    _ = request
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    col = smartgrid_mgr.instantiate_designer_column_from_library(
        draft, col_slug)

    level = smartgrid_mgr.get_designer_level(draft, level_slug)
    grid, _ = DesignerColumnGrid.objects.get_or_create(draft=draft,
                                                       name=col,
                                                       level=level)
    grid.column = column
    grid.save()

    #  Return the new pk for the instantiated DesignerColumnName.
    return HttpResponse(json.dumps({
        "pk": col.pk,
    }),
                        mimetype="application/json")
Esempio n. 12
0
 def testInstantiateColumn(self):
     """Test instantiating DesignerColumnName from LibraryColumnName using the url interface."""
     response = self.client.get(reverse('instantiate_column', \
                                        args=(self.column_slug,
                                              self.level_slug,
                                              1,
                                              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)
         column_name = smartgrid_mgr.get_designer_column_name(draft, self.column_slug)
         qs = DesignerColumnGrid.objects.filter(draft=draft, name=column_name)
         self.assertEquals(len(qs), 1, "Got the wrong number of Columns expecting 1 got %s" % \
                           len(qs))
         grid = qs[0]
         self.assertIsNotNone(grid, "Didn't put %s in ColumnGrid" % self.column_slug)
         self.assertEqual(grid.column, 1, "Got column %s expecting 1" % grid.column)
         self.assertEqual(grid.level, level, "Got wrong level")
     except Http404:
         self.fail("Got 404 response, designer objects didn't instantiate")
Esempio n. 13
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. 14
0
def instantiate_action(request, action_slug, level_slug, column, row,
                       draft_slug):
    """Instantiated the Smart Grid Game Action from the Library Action with the
    given level, column, and row."""
    _ = request
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    grid_action = smartgrid_mgr.instantiate_designer_action_from_library(
        draft, action_slug)
    level = smartgrid_mgr.get_designer_level(draft, level_slug)
    grid = DesignerGrid()
    grid.level = level
    grid.column = column
    grid.row = row
    grid.action = grid_action
    grid.draft = draft
    grid.save()

    #  Return the new pk for the instantiated action.
    return HttpResponse(json.dumps({
        "pk": grid_action.pk,
    }),
                        mimetype="application/json")
Esempio n. 15
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")