Example #1
0
def load_first_template(request):
    """Loads the first template into the Designer."""
    print "load_first_template()"
    if request.method == 'POST':
        form = LoadTemplateForm(request.POST)
        if form.is_valid():
            # load the largest so wont overwrite objects when we load real one.
            draft_name = form.cleaned_data['draft_name']
            template_name = form.cleaned_data['template']
            draft_slug = slugify(draft_name)
            try:
                draft = smartgrid_mgr.get_designer_draft(draft_slug)
            except Http404:
                draft = Draft(name=draft_name, slug=draft_slug)
                draft.save()
            delete_me = Draft(name="delete-me-soon12341",
                              slug='delete-me-soon12341')
            delete_me.save()
            smartgrid_mgr.load_example_grid(draft=delete_me,
                                            example_name='uh12')
            smartgrid_mgr.clear_designer(draft)
            if template_name != 'empty':
                smartgrid_mgr.clear_designer(draft=None)
                smartgrid_mgr.load_example_grid(draft, template_name)
            delete_me.delete()
    response = HttpResponseRedirect("/sgg_designer/?draft=%s" % draft.slug)
    return response
Example #2
0
def load_template(request):
    """Loads a template into the given draft."""
    print "load_template()"
    if request.method == 'POST':
        form = LoadTemplateForm(request.POST)
        if form.is_valid():
            draft_name = form.cleaned_data['draft_name']
            template_name = form.cleaned_data['template']
            draft_slug = slugify(draft_name)
            try:
                draft = smartgrid_mgr.get_designer_draft(draft_slug)
            except Http404:
                draft = Draft(name=draft_name, slug=draft_slug)
                draft.save()
            smartgrid_mgr.clear_designer(draft)
            if template_name != 'empty':
                smartgrid_mgr.clear_designer(draft=None)
                smartgrid_mgr.load_example_grid(draft, template_name)
    response = HttpResponseRedirect("/sgg_designer/?draft=%s" % draft.slug)
    return response
Example #3
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,
    }