Esempio n. 1
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
Esempio n. 2
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
Esempio n. 3
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
Esempio 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