예제 #1
0
def index(request):
    """
    Renders the home page.

    """
    return render(
        request,
        'website/index.html',
        {
            'grid': Grid.get_if_exists('index')
        }
    )
예제 #2
0
def add_grid(request, template_name="grid/add_grid.html"):

    new_grid = Grid()
    form = GridForm(request.POST or None, instance=new_grid)

    if form.is_valid():
        new_grid = form.save()
        return HttpResponseRedirect(
            reverse('grid', kwargs={'slug': new_grid.slug}))

    return render_to_response(template_name, {'form': form},
                              context_instance=RequestContext(request))
예제 #3
0
def grid(context, grid_id):
    """
    Renders the grid of the given ID.

    This block simply outputs the blocks instanced in the grid in
    sequence; you will generally want to ensure that your grid CSS
    automatically breaks the grid stream into rows and columns.

    :param grid_id: the ID (name or primary key) of the grid
    :type grid_id: string, integer or `GridBlock`
    :rtype: a template tag node

    """
    # As grid_block and for the same reasons, but obviously with
    # 'grid' instead of 'box'.
    context['grid'] = Grid.get_if_exists(grid_id)
    context['grid_id'] = grid_id
    return context
예제 #4
0
def add_grid(request, template_name="grid/add_grid.html"):
    """Creates a new grid, requires user to be logged in.
    Works for both GET and POST request methods

    Template context:

    * ``form`` - an instance of :class:`~app.grid.forms.GridForm`
    """

    new_grid = Grid()
    form = GridForm(request.POST or None, instance=new_grid)

    if form.is_valid():
        new_grid = form.save()
        return HttpResponseRedirect(
            reverse('grid', kwargs={'slug': new_grid.slug}))

    return render_to_response(template_name, {'form': form},
                              context_instance=RequestContext(request))
예제 #5
0
def add_grid(request, template_name="grid/add_grid.html"):
    """Creates a new grid, requires user to be logged in.
    Works for both GET and POST request methods

    Template context:

    * ``form`` - an instance of :class:`~app.grid.forms.GridForm`
    """

    if not request.user.get_profile().can_add_grid:
        return HttpResponseForbidden("permission denied")

    new_grid = Grid()
    form = GridForm(request.POST or None, instance=new_grid)    

    if form.is_valid(): 
        new_grid = form.save()
        return HttpResponseRedirect(reverse('grid', kwargs={'slug':new_grid.slug}))

    return render(request, template_name, { 'form': form })