コード例 #1
0
ファイル: mgr_tests.py プロジェクト: jtakayama/makahiki-draft
 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()
コード例 #2
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")
コード例 #3
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()
コード例 #4
0
ファイル: views.py プロジェクト: csdl/makahiki
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")
コード例 #5
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")
コード例 #6
0
ファイル: views.py プロジェクト: csdl/makahiki
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")
コード例 #7
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
コード例 #8
0
ファイル: smartgrid_mgr.py プロジェクト: csdl/makahiki
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()
コード例 #9
0
ファイル: mgr_tests.py プロジェクト: pavelpromin/makahiki
 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()