def load_example_grid(request):
    """Clears the Designer and loads the example grid with the given name."""
    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()
            else:
                smartgrid_mgr.load_example_grid(example_name)
    response = HttpResponseRedirect("/sgg_designer/")
    return response
Example #2
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
Example #3
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
Example #4
0
def supply(request, page_name):
    """ supply view_objects for widget rendering."""
    _ = page_name
    user = request.user
    gcc_settings, _ = GccSettings.objects.get_or_create(user=user)
    draft_choices = Draft.objects.all()
    draft = None
    tree_list = None
    levels = []
    if len(draft_choices) != 0:
        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:
            draft = draft_choices[0]
        levels = DesignerLevel.objects.filter(draft=draft)
        if len(levels) == 0:  # need to create default level
            l = DesignerLevel()
            l.name = "Level 1"  # no name
            l.slug = "default"
            l.unlock_condition = "True"
            l.unlock_condition_text = "Unlocked"
            l.draft = draft
            l.save()
        levels = DesignerLevel.objects.filter(draft=draft)
        ts = action_dependency.build_designer_grid_trees(draft)
        tree_list = []
        for k in list(ts):
            tree_list.append(ts[k].tohtmlstring())
    results = gcc.run_designer_checks(draft, gcc_settings)

    return {
        'draft': draft,
        'draft_choices': draft_choices,
        'levels': levels,
        'columns': LibraryColumnName.objects.all(),
        'activities': LibraryActivity.objects.all(),
        'commitments': LibraryCommitment.objects.all(),
        'events': LibraryEvent.objects.all(),
        'fillers': Filler.objects.all(),
        'reset_form': RevertToSmartgridForm(),
        'publish_form': DeployToSmartgridForm(),
        'example_grid_form': ExampleGridsForm(),
        'add_level_form': AddLevelForm(),
        'delete_level_form': DeleteLevelForm(),
        'event_date_form': EventDateForm(),
        'new_draft_form': NewDraftForm(),
        'delete_draft_form': DeleteDraftForm(),
        'load_template_form': LoadTemplateForm(),
        'gcc_settings_form': GccSettingsForm(instance=gcc_settings),
        'palette': smartgrid_mgr.get_designer_palette(draft),
        'designer_grid': smartgrid_mgr.get_designer_grid(draft),
        'designer_actions': smartgrid_mgr.get_designer_action_slugs(draft),
        'designer_columns':
        smartgrid_mgr.get_designer_column_name_slugs(draft),
        'errors': results[_ERRORS],
        'warnings': results[_WARNINGS],
        'trees': tree_list,
    }