Ejemplo n.º 1
0
def copy_designer_action(draft, slug):
    """Copies the DesignerAction with the given slug."""
    action = get_designer_action(draft, slug)
    action_type = action.type
    if action_type == 'activity':
        obj = DesignerActivity()
    elif action_type == 'commitment':
        obj = DesignerCommitment()
    elif action_type == 'event':
        obj = DesignerEvent()
    _copy_fields(action, obj)
    copy_slug = __get_next_designer_copy_slug(draft, slug)
    obj.slug = copy_slug
    obj.pk = None
    obj.id = None
    obj.save()
    # Copy all the DesignerTextPropmtQuestions
    for question in DesignerTextPromptQuestion.objects.filter(action=action, draft=draft):
        des_obj = DesignerTextPromptQuestion()
        _copy_fields_no_foriegn_keys(question, des_obj)
        des_obj.action = obj
        des_obj.draft = draft
        des_obj.save()

    return obj
Ejemplo n.º 2
0
def copy_designer_action(draft, slug):
    """Copies the DesignerAction with the given slug."""
    action = get_designer_action(draft, slug)
    action_type = action.type
    if action_type == 'activity':
        obj = DesignerActivity()
    elif action_type == 'commitment':
        obj = DesignerCommitment()
    elif action_type == 'event':
        obj = DesignerEvent()
    _copy_fields(action, obj)
    copy_slug = __get_next_designer_copy_slug(draft, slug)
    obj.slug = copy_slug
    obj.pk = None
    obj.id = None
    obj.save()
    # Copy all the DesignerTextPropmtQuestions
    for question in DesignerTextPromptQuestion.objects.filter(action=action, draft=draft):
        des_obj = DesignerTextPromptQuestion()
        _copy_fields_no_foriegn_keys(question, des_obj)
        des_obj.action = obj
        des_obj.draft = draft
        des_obj.save()

    return obj
Ejemplo n.º 3
0
def instantiate_designer_action_from_library(draft, slug):
    """Instantiates a Smart Grid Game Design instance from the Smart Grid Game Library instance.
    draft is the draft to use. slug is the slug value for the library instance. If the Design
    instance exists it is over written."""
    lib_obj = get_library_action(slug)
    action_type = lib_obj.type
    exist_obj = None
    try:
        exist_obj = get_designer_action(draft, slug)
    except Http404:
        exist_obj = None
    design_obj = None
    if exist_obj == None:
        if action_type == 'activity':
            design_obj = DesignerActivity()
            lib_obj = LibraryActivity.objects.get(slug=slug)
        if action_type == 'commitment':
            design_obj = DesignerCommitment()
            lib_obj = LibraryCommitment.objects.get(slug=slug)
        if action_type == 'event':
            design_obj = DesignerEvent()
            lib_obj = LibraryEvent.objects.get(slug=slug)
        if action_type == 'filler':
            design_obj = DesignerFiller()
        design_obj.draft = draft
    else:  # use the existing instance.
        design_obj = exist_obj

    _copy_fields(lib_obj, design_obj)

    # Copy all the LibraryTextPropmtQuestions
    for question in LibraryTextPromptQuestion.objects.filter(libraryaction=lib_obj):
        try:
            des_obj = get_object_or_404(DesignerTextPromptQuestion, action=design_obj, \
                                        question=question.question, answer=question.answer, \
                                        draft=draft)
        except Http404:
            des_obj = DesignerTextPromptQuestion()
        _copy_fields_no_foriegn_keys(question, des_obj)
        des_obj.action = get_designer_action(draft, slug)
        des_obj.draft = draft
        des_obj.save()

    return design_obj
Ejemplo n.º 4
0
def instantiate_designer_action_from_smartgrid(draft, slug):
    """Creates a designer instance from the Smart Grid instance with the given draft."""
    grid_obj = get_smartgrid_action(slug)
    action_type = grid_obj.type
    old_obj = None
    try:
        old_obj = get_designer_action(draft, slug)
    except Http404:
        old_obj = None
    designer_obj = None
    if old_obj == None:
        if action_type == 'activity':
            designer_obj = DesignerActivity()
        if action_type == 'commitment':
            designer_obj = DesignerCommitment()
        if action_type == 'event':
            designer_obj = DesignerEvent()
        if action_type == 'filler':
            designer_obj = DesignerFiller()
        designer_obj.draft = draft
    else:
        designer_obj = old_obj
    _copy_fields(grid_obj, designer_obj)

    # Copy all the TextPropmtQuestions
    for question in TextPromptQuestion.objects.filter(action=grid_obj):
        try:
            des_obj = get_object_or_404(DesignerTextPromptQuestion, action=designer_obj, \
                                        question=question.question, answer=question.answer, \
                                        draft=draft)
        except Http404:
            des_obj = DesignerTextPromptQuestion()
        _copy_fields_no_foriegn_keys(question, des_obj)
        des_obj.action = get_designer_action(draft, slug)
        des_obj.draft = draft
        des_obj.save()

    return designer_obj
Ejemplo n.º 5
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
Ejemplo n.º 6
0
def instantiate_designer_action_from_library(draft, slug):
    """Instantiates a Smart Grid Game Design instance from the Smart Grid Game Library instance.
    draft is the draft to use. slug is the slug value for the library instance. If the Design
    instance exists it is over written."""
    lib_obj = get_library_action(slug)
    action_type = lib_obj.type
    exist_obj = None
    try:
        exist_obj = get_designer_action(draft, slug)
    except Http404:
        exist_obj = None
    design_obj = None
    if exist_obj == None:
        if action_type == 'activity':
            design_obj = DesignerActivity()
            lib_obj = LibraryActivity.objects.get(slug=slug)
        if action_type == 'commitment':
            design_obj = DesignerCommitment()
            lib_obj = LibraryCommitment.objects.get(slug=slug)
        if action_type == 'event':
            design_obj = DesignerEvent()
            lib_obj = LibraryEvent.objects.get(slug=slug)
        if action_type == 'filler':
            design_obj = DesignerFiller()
        design_obj.draft = draft
    else:  # use the existing instance.
        design_obj = exist_obj

    _copy_fields(lib_obj, design_obj)

    # Copy all the LibraryTextPropmtQuestions
    for question in LibraryTextPromptQuestion.objects.filter(libraryaction=lib_obj):
        try:
            des_obj = get_object_or_404(DesignerTextPromptQuestion, action=design_obj, \
                                        question=question.question, answer=question.answer, \
                                        draft=draft)
        except Http404:
            des_obj = DesignerTextPromptQuestion()
        _copy_fields_no_foriegn_keys(question, des_obj)
        des_obj.action = get_designer_action(draft, slug)
        des_obj.draft = draft
        des_obj.save()

    return design_obj
Ejemplo n.º 7
0
def instantiate_designer_action_from_smartgrid(draft, slug):
    """Creates a designer instance from the Smart Grid instance with the given draft."""
    grid_obj = get_smartgrid_action(slug)
    action_type = grid_obj.type
    old_obj = None
    try:
        old_obj = get_designer_action(draft, slug)
    except Http404:
        old_obj = None
    designer_obj = None
    if old_obj == None:
        if action_type == 'activity':
            designer_obj = DesignerActivity()
        if action_type == 'commitment':
            designer_obj = DesignerCommitment()
        if action_type == 'event':
            designer_obj = DesignerEvent()
        if action_type == 'filler':
            designer_obj = DesignerFiller()
        designer_obj.draft = draft
    else:
        designer_obj = old_obj
    _copy_fields(grid_obj, designer_obj)

    # Copy all the TextPropmtQuestions
    for question in TextPromptQuestion.objects.filter(action=grid_obj):
        try:
            des_obj = get_object_or_404(DesignerTextPromptQuestion, action=designer_obj, \
                                        question=question.question, answer=question.answer, \
                                        draft=draft)
        except Http404:
            des_obj = DesignerTextPromptQuestion()
        _copy_fields_no_foriegn_keys(question, des_obj)
        des_obj.action = get_designer_action(draft, slug)
        des_obj.draft = draft
        des_obj.save()

    return designer_obj