Beispiel #1
0
def supply(request, page_name):
    """Supplies view_objects for smartgrid library widgets."""
    _ = page_name
    _ = request

    draft_choices = Draft.objects.all()
    draft = None
    try:
        draft_slug = request.REQUEST['draft']
    except KeyError:
        try:
            draft_slug = request.COOKIES['current-designer-draft']
        except KeyError:
            draft_slug = draft_choices[0].slug
    try:
        draft = smartgrid_mgr.get_designer_draft(draft_slug)
    except Http404:
        if len(draft_choices) > 0:
            draft = draft_choices[0]

    return {
        "predicates": predicate_mgr.get_smartgrid_unlock_predicate_list(),
        "action_slugs": predicate_mgr.get_action_slugs(draft=draft),
        "action_types": predicate_mgr.get_action_types(),
        "event_slugs": predicate_mgr.get_event_slugs(draft=draft),
        "game_names": predicate_mgr.get_game_names(),
        "level_names": predicate_mgr.get_level_names(draft=draft),
        "resources": predicate_mgr.get_resources(),
        "round_names": predicate_mgr.get_round_names(),
        }
Beispiel #2
0
def copy_action(request, action_slug, draft_slug):
    """Copies the given DesignerAction into the palette for the given draft."""
    _ = request
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    smartgrid_mgr.copy_designer_action(draft, action_slug)
    response = HttpResponseRedirect("/sgg_designer/?draft=%s" % draft.slug)
    return response
def submitted_all_of_resource(user, draft_slug, resource):
    """Returns true if user has submitted all Actions of the given resoruce."""
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    count = DesignerAction.objects.filter(draft=draft, related_resource=resource).count()
    c = user.testeractionsubmittion_set.filter(draft=draft,
                                               action__related_resource=resource).count()
    return c == count
Beispiel #4
0
def load_first_template(request):
    """Loads the first template into the Designer."""
    print "load_first_template()"
    if request.method == 'POST':
        form = LoadTemplateForm(request.POST)
        if form.is_valid():
            # load the largest so wont overwrite objects when we load real one.
            draft_name = form.cleaned_data['draft_name']
            template_name = form.cleaned_data['template']
            draft_slug = slugify(draft_name)
            try:
                draft = smartgrid_mgr.get_designer_draft(draft_slug)
            except Http404:
                draft = Draft(name=draft_name, slug=draft_slug)
                draft.save()
            delete_me = Draft(name="delete-me-soon12341",
                              slug='delete-me-soon12341')
            delete_me.save()
            smartgrid_mgr.load_example_grid(draft=delete_me,
                                            example_name='uh12')
            smartgrid_mgr.clear_designer(draft)
            if template_name != 'empty':
                smartgrid_mgr.clear_designer(draft=None)
                smartgrid_mgr.load_example_grid(draft, template_name)
            delete_me.delete()
    response = HttpResponseRedirect("/sgg_designer/?draft=%s" % draft.slug)
    return response
Beispiel #5
0
def load_first_template(request):
    """Loads the first template into the Designer."""
    print "load_first_template()"
    if request.method == 'POST':
        form = LoadTemplateForm(request.POST)
        if form.is_valid():
            # load the largest so wont overwrite objects when we load real one.
            draft_name = form.cleaned_data['draft_name']
            template_name = form.cleaned_data['template']
            draft_slug = slugify(draft_name)
            try:
                draft = smartgrid_mgr.get_designer_draft(draft_slug)
            except Http404:
                draft = Draft(name=draft_name, slug=draft_slug)
                draft.save()
            delete_me = Draft(name="delete-me-soon12341", slug='delete-me-soon12341')
            delete_me.save()
            smartgrid_mgr.load_example_grid(draft=delete_me, example_name='uh12')
            smartgrid_mgr.clear_designer(draft)
            if template_name != 'empty':
                smartgrid_mgr.clear_designer(draft=None)
                smartgrid_mgr.load_example_grid(draft, template_name)
            delete_me.delete()
    response = HttpResponseRedirect("/sgg_designer/?draft=%s" % draft.slug)
    return response
Beispiel #6
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")
def submitted_some_of_level(user, draft_slug, level_priority, count=1):
    """Returns true if the user has completed count Actions of the specified level."""
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    c = 0
    for action in DesignerGrid.objects.filter(draft=draft, level__priority=level_priority):
        c += user.testeractionsubmittion_set.filter(action=action).count()
    return c >= count
Beispiel #8
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)
Beispiel #9
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)
Beispiel #10
0
def copy_action(request, action_slug, draft_slug):
    """Copies the given DesignerAction into the palette for the given draft."""
    _ = request
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    smartgrid_mgr.copy_designer_action(draft, action_slug)
    response = HttpResponseRedirect("/sgg_designer/?draft=%s" % draft.slug)
    return response
def submitted_some(user, draft_slug, count=1):
    """Returns true if the user has completed count Actions."""
    try:
        draft = smartgrid_mgr.get_designer_draft(draft_slug)
        return user.testeractionsubmittion_set.filter(draft=draft).count() >= count
    except Http404:
        return False
Beispiel #12
0
def supply(request, page_name):
    """Supplies view_objects for smartgrid library widgets."""
    _ = page_name
    _ = request

    draft_choices = Draft.objects.all()
    draft = None
    try:
        draft_slug = request.REQUEST['draft']
    except KeyError:
        try:
            draft_slug = request.COOKIES['current-designer-draft']
        except KeyError:
            draft_slug = draft_choices[0].slug
    try:
        draft = smartgrid_mgr.get_designer_draft(draft_slug)
    except Http404:
        if len(draft_choices) > 0:
            draft = draft_choices[0]

    return {
        "predicates": predicate_mgr.get_smartgrid_unlock_predicate_list(),
        "action_slugs": predicate_mgr.get_action_slugs(draft=draft),
        "action_types": predicate_mgr.get_action_types(),
        "event_slugs": predicate_mgr.get_event_slugs(draft=draft),
        "game_names": predicate_mgr.get_game_names(),
        "level_names": predicate_mgr.get_level_names(draft=draft),
        "resources": predicate_mgr.get_resources(),
        "round_names": predicate_mgr.get_round_names(),
    }
def social_bonus_count(user, draft_slug, count):
    """Returns True if the number of social bonus the user received equals to count."""
    try:
        draft = smartgrid_mgr.get_designer_draft(draft_slug)
        return user.testeractionsubmittion_set.filter(draft=draft,
                                                      social_bonus_awarded=True).count() >= count
    except Http404:
        return False
Beispiel #14
0
def get_diff(request, draft_slug):
    """Returns the difference between the designer grid and the Smart Grid as a string."""
    _ = request
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    diff = smartgrid_mgr.diff_between_designer_and_grid(draft)
    return HttpResponse(json.dumps({
            "diff": diff,
            }), mimetype="application/json")
Beispiel #15
0
def delete_column(request, col_slug, draft_slug):
    """Deletes the DesignerColumnName for the given col_slug."""
    _ = request
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    column = smartgrid_mgr.get_designer_column_name(draft, col_slug)
    column.delete()
    response = HttpResponse("/sgg_designer/?draft=%s" % draft.slug)
    return response
Beispiel #16
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
def approved_action(user, draft_slug, action_slug):
    """Returns true if the action is approved."""
    try:
        draft = smartgrid_mgr.get_designer_draft(draft_slug)
        return user.testeractionsubmittion_set.filter(draft=draft, action__slug=action_slug,
                                            approval_status="approved").count() > 0
    except Http404:
        return False
def approved_some_of_type(user, draft_slug, action_type, count=1):
    """Returns true if the user has had count Actions approved with the given action_type."""
    try:
        draft = smartgrid_mgr.get_designer_draft(draft_slug)
        return user.testeractionsubmittion_set.filter(draft=draft, action__type=action_type,
                                            approval_status="approved").count() >= count
    except Http404:
        return False
def submitted_all_of_level(user, draft_slug, level_priority):
    """Returns True if the user has submitted all Actions on the given level."""
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    c = 0
    count = len(DesignerGrid.objects.filter(draft=draft, level__priority=level_priority))
    for action in DesignerGrid.objects.filter(draft=draft, level__priority=level_priority):
        c += user.testeractionsubmittion_set.filter(draft=draft, action=action).count()
    return c >= count
def approved_some_of_level(user, draft_slug, level_priority, count=1):
    """Returns True if the user has had count Actions approved for the given level."""
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    c = 0
    for action in DesignerGrid.objects.filter(draft=draft, level__priority=level_priority):
        c += user.testeractionsubmittion_set.filter(action=action,
                                          approval_status="approved").count()
    return c >= count
Beispiel #21
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
Beispiel #22
0
def delete_column(request, col_slug, draft_slug):
    """Deletes the DesignerColumnName for the given col_slug."""
    _ = request
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    column = smartgrid_mgr.get_designer_column_name(draft, col_slug)
    column.delete()
    response = HttpResponse("/sgg_designer/?draft=%s" % draft.slug)
    return response
def approved_some(user, draft_slug, count=1):
    """Returns True if the user has had count Actions approved."""
    try:
        draft = smartgrid_mgr.get_designer_draft(draft_slug)
        return user.testeractionsubmittion_set.filter(draft=draft,
                                                      approval_status='approved').count() >= count
    except Http404:
        return False
def submitted_some_of_type(user, draft_slug, action_type, count=1):
    """Returns True if user has submitted count Actions with the given action_type."""
    try:
        draft = smartgrid_mgr.get_designer_draft(draft_slug)
        return user.testeractionsubmittion_set.filter(draft=draft,
                                                      action__type=action_type).count() >= count
    except Http404:
        return False
def submitted_all_of_type(user, draft_slug, action_type):
    """Returns true if user has submitted all Actions of the given action_type."""
    try:
        draft = smartgrid_mgr.get_designer_draft(draft_slug)
        count = DesignerAction.objects.filter(draft=draft, type=action_type).count()
        return user.testeractionsubmittion_set.filter(draft=draft,
                                                      action__type=action_type).count() == count
    except Http404:
        return False
Beispiel #26
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
Beispiel #27
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
Beispiel #28
0
def get_diff(request, draft_slug):
    """Returns the difference between the designer grid and the Smart Grid as a string."""
    _ = request
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    diff = smartgrid_mgr.diff_between_designer_and_grid(draft)
    return HttpResponse(json.dumps({
        "diff": diff,
    }),
                        mimetype="application/json")
def approved_all_of_type(user, draft_slug, action_type):
    """Returns True if the user has had all Actions of the action_type approved."""
    try:
        draft = smartgrid_mgr.get_designer_draft(draft_slug)
        count = DesignerAction.objects.filter(draft=draft, type=action_type).count()
        return user.testeractionsubmittion_set.filter(action__type=action_type,
                                            approval_status="approved").count() == count
    except Http404:
        return False
def submitted_all_of_resource(user, draft_slug, resource):
    """Returns true if user has submitted all Actions of the given resoruce."""
    try:
        draft = smartgrid_mgr.get_designer_draft(draft_slug)
        count = DesignerAction.objects.filter(draft=draft, related_resource=resource).count()
        c = user.testeractionsubmittion_set.filter(draft=draft,
                                                   action__related_resource=resource).count()
        return c == count
    except Http404:
        return False
Beispiel #31
0
def delete_draft(request):
    """Deletes the Draft in the DeleteDraftForm."""
    if request.method == 'POST':
        form = DeleteDraftForm(request.POST)
        if form.is_valid():
            draft_slug = form.cleaned_data['draft_slug']
            draft = smartgrid_mgr.get_designer_draft(draft_slug)
            draft.delete()
    response = HttpResponseRedirect("/sgg_designer/")
    return response
def submitted_some_of_level(user, draft_slug, level_priority, count=1):
    """Returns true if the user has completed count Actions of the specified level."""
    try:
        draft = smartgrid_mgr.get_designer_draft(draft_slug)
        c = 0
        for grid in DesignerGrid.objects.filter(draft=draft, level__priority=level_priority):
            c += user.testeractionsubmittion_set.filter(action=grid.action).count()
        return c >= count
    except Http404:
        return False
Beispiel #33
0
def delete_draft(request):
    """Deletes the Draft in the DeleteDraftForm."""
    if request.method == 'POST':
        form = DeleteDraftForm(request.POST)
        if form.is_valid():
            draft_slug = form.cleaned_data['draft_slug']
            draft = smartgrid_mgr.get_designer_draft(draft_slug)
            draft.delete()
    response = HttpResponseRedirect("/sgg_designer/")
    return response
def submitted_all_of_level(user, draft_slug, level_priority):
    """Returns True if the user has submitted all Actions on the given level."""
    try:
        draft = smartgrid_mgr.get_designer_draft(draft_slug)
        c = 0
        count = len(DesignerGrid.objects.filter(draft=draft, level__priority=level_priority))
        for action in DesignerGrid.objects.filter(draft=draft, level__priority=level_priority):
            c += user.testeractionsubmittion_set.filter(draft=draft, action=action).count()
        return c >= count
    except Http404:
        return False
def approved_some_of_level(user, draft_slug, level_priority, count=1):
    """Returns True if the user has had count Actions approved for the given level."""
    try:
        draft = smartgrid_mgr.get_designer_draft(draft_slug)
        c = 0
        for action in DesignerGrid.objects.filter(draft=draft, level__priority=level_priority):
            c += user.testeractionsubmittion_set.filter(action=action,
                                              approval_status="approved").count()
        return c >= count
    except Http404:
        return False
Beispiel #36
0
def publish_to_grid(request, draft_slug):
    """Clears all the current Smart Grid Instances and Copies the DesignerActions to the Smart
    Grid Game."""
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    if request.method == 'POST':
        form = DeployToSmartgridForm(request.POST)
        if form.is_valid():
            use_filler = form.cleaned_data['use_filler']
            smartgrid_mgr.deploy_designer_to_smartgrid(draft, use_filler)
    response = HttpResponseRedirect("/sgg_designer/?draft=%s" % draft.slug)
    return response
Beispiel #37
0
def revert_to_grid(request, draft_slug):
    """Deletes all the DesignerActions and creates new DesignerActions from the current Smart
    Grid Game instances."""
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    if request.method == 'POST':  # If the form has been submitted...
        form = RevertToSmartgridForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            smartgrid_mgr.clear_designer(draft)
            smartgrid_mgr.copy_smartgrid_to_designer(draft)
    response = HttpResponseRedirect("/sgg_designer/?draft=%s" % draft.slug)
    return response
Beispiel #38
0
def publish_to_grid(request, draft_slug):
    """Clears all the current Smart Grid Instances and Copies the DesignerActions to the Smart
    Grid Game."""
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    if request.method == 'POST':
        form = DeployToSmartgridForm(request.POST)
        if form.is_valid():
            use_filler = form.cleaned_data['use_filler']
            smartgrid_mgr.deploy_designer_to_smartgrid(draft, use_filler)
    response = HttpResponseRedirect("/sgg_designer/?draft=%s" % draft.slug)
    return response
Beispiel #39
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")
Beispiel #40
0
def _get_current_draft(request):
    """Returns the currently selected Draft."""
    draft_choices = Draft.objects.all()
    try:
        draft_slug = request.COOKIES['current-designer-draft']
    except KeyError:
        draft_slug = draft_choices[0].slug
    try:
        draft = smartgrid_mgr.get_designer_draft(draft_slug)
    except Http404:
        draft = draft_choices[0]
    return draft
Beispiel #41
0
def _get_current_draft(request):
    """Returns the currently selected Draft."""
    draft_choices = Draft.objects.all()
    try:
        draft_slug = request.COOKIES['current-designer-draft']
    except KeyError:
        draft_slug = draft_choices[0].slug
    try:
        draft = smartgrid_mgr.get_designer_draft(draft_slug)
    except Http404:
        draft = draft_choices[0]
    return draft
def approved_all_of_level(user, draft_slug, level_priority):
    """Returns True if the user has had all Actions on the given level approved."""
    try:
        draft = smartgrid_mgr.get_designer_draft(draft_slug)
        c = 0
        count = len(DesignerGrid.objects.filter(draft=draft, level__priority=level_priority))
        for action in DesignerGrid.objects.filter(level__priority=level_priority):
            c += user.testeractionsubmittion_set.filter(action=action,
                                              approval_status="approved").count()
        return c >= count
    except Http404:
        return False
Beispiel #43
0
def revert_to_grid(request, draft_slug):
    """Deletes all the DesignerActions and creates new DesignerActions from the current Smart
    Grid Game instances."""
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    if request.method == 'POST':  # If the form has been submitted...
        form = RevertToSmartgridForm(
            request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            smartgrid_mgr.clear_designer(draft)
            smartgrid_mgr.copy_smartgrid_to_designer(draft)
    response = HttpResponseRedirect("/sgg_designer/?draft=%s" % draft.slug)
    return response
Beispiel #44
0
def load_example_grid(request, draft_slug):
    """Clears the Designer and loads the example grid with the given name."""
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    if request.method == 'POST':
        form = ExampleGridsForm(request.POST)
        if form.is_valid():
            example_name = form.cleaned_data['grid']
            if example_name == 'empty':
                smartgrid_mgr.clear_designer(draft)
            else:
                smartgrid_mgr.load_example_grid(draft, example_name)
    response = HttpResponseRedirect("/sgg_designer/?draft=%s" % draft.slug)
    return response
Beispiel #45
0
def load_example_grid(request, draft_slug):
    """Clears the Designer and loads the example grid with the given name."""
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    if request.method == 'POST':
        form = ExampleGridsForm(request.POST)
        if form.is_valid():
            example_name = form.cleaned_data['grid']
            if example_name == 'empty':
                smartgrid_mgr.clear_designer(draft)
            else:
                smartgrid_mgr.load_example_grid(draft, example_name)
    response = HttpResponseRedirect("/sgg_designer/?draft=%s" % draft.slug)
    return response
Beispiel #46
0
def new_draft(request):
    """Creates a new Draft from the given draft name if the Draft doesn't already exist."""
    if request.method == 'POST':
        form = NewDraftForm(request.POST)
        if form.is_valid():
            draft_name = form.cleaned_data['draft_name']
            draft_slug = slugify(draft_name)
            try:
                draft = smartgrid_mgr.get_designer_draft(draft_slug)
            except Http404:
                draft = Draft(name=draft_name, slug=draft_slug)
                draft.save()
    response = HttpResponseRedirect("/sgg_designer/?draft=%s" % draft.slug)
    return response
Beispiel #47
0
def new_draft(request):
    """Creates a new Draft from the given draft name if the Draft doesn't already exist."""
    if request.method == 'POST':
        form = NewDraftForm(request.POST)
        if form.is_valid():
            draft_name = form.cleaned_data['draft_name']
            draft_slug = slugify(draft_name)
            try:
                draft = smartgrid_mgr.get_designer_draft(draft_slug)
            except Http404:
                draft = Draft(name=draft_name, slug=draft_slug)
                draft.save()
    response = HttpResponseRedirect("/sgg_designer/?draft=%s" % draft.slug)
    return response
Beispiel #48
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
Beispiel #49
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
Beispiel #50
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.")