def add_level(request):
    """Creates a new level."""
    if request.method == 'POST':
        form = AddLevelForm(request.POST)
        if form.is_valid():
            max_priority = 0
            for level in DesignerLevel.objects.all():
                if max_priority < level.priority:
                    max_priority = level.priority
            max_priority += 1
            slug = slugify(form.cleaned_data['level_name'])
            level = DesignerLevel(name=form.cleaned_data['level_name'], slug=slug, \
                                  priority=max_priority)
            level.save()
    response = HttpResponseRedirect("/sgg_designer/")
    return response
Example #2
0
def add_level(request, draft_slug):
    """Creates a new level."""
    draft = smartgrid_mgr.get_designer_draft(draft_slug)
    if request.method == 'POST':
        form = AddLevelForm(request.POST)
        if form.is_valid():
            max_priority = 0
            for level in DesignerLevel.objects.filter(draft=draft):
                if max_priority < level.priority:
                    max_priority = level.priority
            max_priority += 1
            slug = slugify(form.cleaned_data['level_name'])
            level = DesignerLevel(name=form.cleaned_data['level_name'], slug=slug, \
                                  priority=max_priority, draft=draft)
            predicate = form.cleaned_data['unlock_condition']
            if not predicate_mgr.validate_predicates(predicate):
                level.unlock_condition = predicate
            else:
                level.unlock_condition = 'False'  # What is the correct default value?
            level.save()
    response = HttpResponseRedirect("/sgg_designer/?draft=%s" % draft.slug)
    return response