Example #1
0
 def __create_cams_draft(self):
     """Creates Cam's Draft smartgrid with two levels, three columns, three actions"""
     try:
         draft = get_object_or_404(Draft, slug='cam')
     except Http404:
         draft = Draft(name="Cam", slug="cam")
         draft.save()
     level1 = DesignerLevel(draft=draft, name="Foo", slug="foo", priority=1)
     level1.save()
     level2 = DesignerLevel(draft=draft, name="Bar", slug="bar", priority=2)
     level2.save()
     column1 = DesignerColumnName(draft=draft, name="Baz", slug='baz')
     column1.save()
     column2 = DesignerColumnName(draft=draft, name="Qux", slug='qux')
     column2.save()
     column3 = DesignerColumnName(draft=draft, name="Zob", slug='zob')
     column3.save()
     col_loc = DesignerColumnGrid(draft=draft, level=level1, column=5, name=column1)
     col_loc.save()
     col_loc = DesignerColumnGrid(draft=draft, level=level1, column=2, name=column2)
     col_loc.save()
     col_loc = DesignerColumnGrid(draft=draft, level=level2, column=1, name=column3)
     col_loc.save()
     action = smartgrid_mgr.instantiate_designer_action_from_library(draft, \
                                                                     'play-outside-cafe-1')
     grid_loc = DesignerGrid(draft=draft, level=level1, column=5, row=2, action=action)
     grid_loc.save()
     action = smartgrid_mgr.instantiate_designer_action_from_library(draft, \
                                                                     'use-stairs')
     grid_loc = DesignerGrid(draft=draft, level=level1, column=2, row=1, action=action)
     grid_loc.save()
     action = smartgrid_mgr.instantiate_designer_action_from_library(draft, \
                                                                     'energy-city')
     grid_loc = DesignerGrid(draft=draft, level=level2, column=5, row=5, action=action)
     grid_loc.save()
def instantiate_column(request, col_slug, level_slug, column):
    """Instantiates the DesignerColumnName from the LibraryColumnName and places it in the
    Grid at the given level and column."""
    _ = request
    _ = level_slug
    lib_col = LibraryColumnName.objects.get(slug=col_slug)
    try:
        col_name = get_object_or_404(DesignerColumnName, slug=col_slug)
    except Http404:
        col_name = DesignerColumnName()

    col_name.name = lib_col.name
    col_name.slug = lib_col.slug
    col_name.save()

    level = get_object_or_404(DesignerLevel, slug=level_slug)
    grid = DesignerColumnGrid()
    grid.level = level
    grid.column = column
    grid.name = col_name
    grid.save()

    #  Return the new pk for the instantiated DesignerColumnName.
    return HttpResponse(json.dumps({
            "pk": col_name.pk,
            }), mimetype="application/json")
Example #3
0
def copy_draft(from_draft, to_draft):
    """Copies all the items in from_draft to copy_draft."""
#     print "copy_draft(%s, %s)" % (from_draft, to_draft)
    clear_designer(to_draft)
    # levels
    for level in DesignerLevel.objects.filter(draft=from_draft):
        copy = DesignerLevel(draft=to_draft)
        _copy_fields_no_foriegn_keys(level, copy)
        copy.save()
    # ColumnNames
    for column in DesignerColumnName.objects.filter(draft=from_draft):
        copy = DesignerColumnName(draft=to_draft)
        _copy_fields_no_foriegn_keys(column, copy)
        copy.save()
    # DesignerColumnGrid
    for loc in DesignerColumnGrid.objects.filter(draft=from_draft):
        level = get_designer_level(to_draft, loc.level.slug)
        column = get_designer_column_name(to_draft, loc.name.slug)
        copy = DesignerColumnGrid(draft=to_draft, name=column, level=level)
        _copy_fields_no_foriegn_keys(loc, copy)
        copy.save()
    # DesignerActions
    for action in DesignerAction.objects.filter(draft=from_draft):
        action = get_designer_action(from_draft, action.slug)
        if action.type == 'activity':
            copy = DesignerActivity(draft=to_draft)
        elif action.type == 'commitment':
            copy = DesignerCommitment(draft=to_draft)
        elif action.type == 'event':
            copy = DesignerEvent(draft=to_draft)
        _copy_fields_no_foriegn_keys(action, copy)
        copy.save()
        # Copy all the DesignerTextPropmtQuestions
        for question in DesignerTextPromptQuestion.objects.filter(action=action, draft=from_draft):
            des_obj = DesignerTextPromptQuestion(action=copy, draft=to_draft)
            _copy_fields_no_foriegn_keys(question, des_obj)
            des_obj.save()
    # DesignerGrid
    for loc in DesignerGrid.objects.filter(draft=from_draft):
        level = get_designer_level(to_draft, loc.level.slug)
        action = get_designer_action(to_draft, loc.action.slug)
        copy = DesignerGrid(level=level, draft=to_draft, action=action)
        _copy_fields_no_foriegn_keys(loc, copy)
        copy.save()
    return to_draft
Example #4
0
def copy_smartgrid_to_designer(draft):
    """Copies the current Smart Grid Game to the given designer draft."""
    # Clear out the Designer
    clear_designer(draft)
    # Copy the levels
    for lvl in Level.objects.all():
        try:
            des_lvl = get_object_or_404(DesignerLevel, draft=draft, slug=lvl.slug)
        except Http404:
            des_lvl = DesignerLevel()
            des_lvl.draft = draft
        _copy_fields(lvl, des_lvl)
    # Copy the ColumnNames
    for col in ColumnName.objects.all():
        try:
            des_col = get_object_or_404(DesignerColumnName, draft=draft, slug=col.slug)
        except Http404:
            des_col = DesignerColumnName()
            des_col.draft = draft
        _copy_fields(col, des_col)
    # Copy the location information
    for grid in ColumnGrid.objects.all():
        col = DesignerColumnGrid()
        col.level = get_designer_level(draft, grid.level.slug)
        col.column = grid.column
        col.name = get_designer_column_name(draft, grid.name.slug)
        col.draft = draft
        col.save()
    # Copy the Actions
    for action in Action.objects.all():
        instantiate_designer_action_from_smartgrid(draft, action.slug)
    # Copy the location information
    for grid in Grid.objects.all():
        loc = DesignerGrid()
        loc.level = get_designer_level(draft, grid.level.slug)
        loc.column = grid.column
        loc.row = grid.row
        loc.action = get_designer_action(draft, grid.action.slug)
        loc.draft = draft
        loc.save()
Example #5
0
def copy_smartgrid_to_designer(draft):
    """Copies the current Smart Grid Game to the given designer draft."""
    # Clear out the Designer
    clear_designer(draft)
    # Copy the levels
    for lvl in Level.objects.all():
        try:
            des_lvl = get_object_or_404(DesignerLevel, draft=draft, slug=lvl.slug)
        except Http404:
            des_lvl = DesignerLevel()
            des_lvl.draft = draft
        _copy_fields(lvl, des_lvl)
    # Copy the ColumnNames
    for col in ColumnName.objects.all():
        try:
            des_col = get_object_or_404(DesignerColumnName, draft=draft, slug=col.slug)
        except Http404:
            des_col = DesignerColumnName()
            des_col.draft = draft
        _copy_fields(col, des_col)
    # Copy the location information
    for grid in ColumnGrid.objects.all():
        col = DesignerColumnGrid()
        col.level = get_designer_level(draft, grid.level.slug)
        col.column = grid.column
        col.name = get_designer_column_name(draft, grid.name.slug)
        col.draft = draft
        col.save()
    # Copy the Actions
    for action in Action.objects.all():
        instantiate_designer_action_from_smartgrid(draft, action.slug)
    # Copy the location information
    for grid in Grid.objects.all():
        loc = DesignerGrid()
        loc.level = get_designer_level(draft, grid.level.slug)
        loc.column = grid.column
        loc.row = grid.row
        loc.action = get_designer_action(draft, grid.action.slug)
        loc.draft = draft
        loc.save()
Example #6
0
 def __create_cams_draft(self):
     """Creates Cam's Draft smartgrid with two levels, three columns, three actions"""
     try:
         draft = get_object_or_404(Draft, slug='cam')
     except Http404:
         draft = Draft(name="Cam", slug="cam")
         draft.save()
     level1 = DesignerLevel(draft=draft, name="Foo", slug="foo", priority=1)
     level1.save()
     level2 = DesignerLevel(draft=draft, name="Bar", slug="bar", priority=2)
     level2.save()
     column1 = DesignerColumnName(draft=draft, name="Baz", slug='baz')
     column1.save()
     column2 = DesignerColumnName(draft=draft, name="Qux", slug='qux')
     column2.save()
     column3 = DesignerColumnName(draft=draft, name="Zob", slug='zob')
     column3.save()
     col_loc = DesignerColumnGrid(draft=draft,
                                  level=level1,
                                  column=5,
                                  name=column1)
     col_loc.save()
     col_loc = DesignerColumnGrid(draft=draft,
                                  level=level1,
                                  column=2,
                                  name=column2)
     col_loc.save()
     col_loc = DesignerColumnGrid(draft=draft,
                                  level=level2,
                                  column=1,
                                  name=column3)
     col_loc.save()
     action = smartgrid_mgr.instantiate_designer_action_from_library(draft, \
                                                                     'play-outside-cafe-1')
     grid_loc = DesignerGrid(draft=draft,
                             level=level1,
                             column=5,
                             row=2,
                             action=action)
     grid_loc.save()
     action = smartgrid_mgr.instantiate_designer_action_from_library(draft, \
                                                                     'use-stairs')
     grid_loc = DesignerGrid(draft=draft,
                             level=level1,
                             column=2,
                             row=1,
                             action=action)
     grid_loc.save()
     action = smartgrid_mgr.instantiate_designer_action_from_library(draft, \
                                                                     'energy-city')
     grid_loc = DesignerGrid(draft=draft,
                             level=level2,
                             column=5,
                             row=5,
                             action=action)
     grid_loc.save()