コード例 #1
0
ファイル: views.py プロジェクト: MechanisM/opencomparison
def add_feature(request, grid_slug, template_name="grid/add_feature.html"):
    """Adds a feature to the grid, accepts GET and POST requests.

    Requires user to be logged in

    Template context:

    * ``form`` - instance of :class:`grid.forms.FeatureForm` form
    * ``grid`` - instance of :class:`grid.models.Grid` model
    """

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

    grid = get_object_or_404(Grid, slug=grid_slug)
    feature = Feature()
    form = FeatureForm(request.POST or None, instance=feature)    

    if form.is_valid(): 
        feature = Feature(
                    grid=grid, 
                    title=request.POST['title'],
                    description = request.POST['description']
                )
        feature.save()
        return HttpResponseRedirect(reverse('grid', kwargs={'slug':feature.grid.slug}))

    return render(request, template_name, { 'form': form,'grid':grid })
コード例 #2
0
def add_feature(request, grid_slug, template_name="grid/add_feature.html"):
    """Adds a feature to the grid, accepts GET and POST requests.

    Requires user to be logged in

    Template context:

    * ``form`` - instance of :class:`grid.forms.FeatureForm` form
    * ``grid`` - instance of :class:`grid.models.Grid` model
    """

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

    grid = get_object_or_404(Grid, slug=grid_slug)
    feature = Feature()
    form = FeatureForm(request.POST or None, instance=feature)    

    if form.is_valid(): 
        feature = Feature(
                    grid=grid, 
                    title=request.POST['title'],
                    description = request.POST['description']
                )
        feature.save()
        return HttpResponseRedirect(reverse('grid', kwargs={'slug':feature.grid.slug}))

    return render(request, template_name, { 'form': form,'grid':grid })
コード例 #3
0
ファイル: views.py プロジェクト: rhok-planet/crisishacks
def edit_feature(request, id, template_name="grid/edit_feature.html"):

    feature = get_object_or_404(Feature, id=id)
    form = FeatureForm(request.POST or None, instance=feature)

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

    return render_to_response(
        template_name, {"form": form, "grid": feature.grid}, context_instance=RequestContext(request)
    )
コード例 #4
0
ファイル: views.py プロジェクト: rhok-planet/crisishacks
def add_feature(request, grid_slug, template_name="grid/add_feature.html"):

    grid = get_object_or_404(Grid, slug=grid_slug)
    feature = Feature()
    form = FeatureForm(request.POST or None, instance=feature)

    if form.is_valid():
        feature = Feature(grid=grid, title=request.POST["title"], description=request.POST["description"])
        feature.save()
        return HttpResponseRedirect(reverse("grid", kwargs={"slug": feature.grid.slug}))

    return render_to_response(template_name, {"form": form, "grid": grid}, context_instance=RequestContext(request))
コード例 #5
0
ファイル: views.py プロジェクト: akavlie/packaginator
def edit_feature(request, id, template_name="grid/edit_feature.html"):

    feature = get_object_or_404(Feature, id=id)
    form = FeatureForm(request.POST or None, instance=feature)

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

    return render_to_response(template_name, { 
        'form': form,
        'grid': feature.grid  
        }, 
        context_instance=RequestContext(request))
コード例 #6
0
ファイル: views.py プロジェクト: qbig/opencomparison
def edit_feature(request, id, template_name="grid/update_feature.html"):
    """edits feature on a grid - this view has the same
    semantics as :func:`grid.views.add_feature`.

    Requires the user to be logged in.
    """

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

    feature = get_object_or_404(Feature, id=id)
    form = FeatureForm(request.POST or None, instance=feature)

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

    return render(request, template_name, {'form': form, 'grid': feature.grid})
コード例 #7
0
ファイル: views.py プロジェクト: ojii/opencomparison
def edit_feature(request, id, template_name="grid/edit_feature.html"):
    """edits feature on a grid - this view has the same
    semantics as :func:`grid.views.add_feature`.

    Requires the user to be logged in.
    """

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

    feature = get_object_or_404(Feature, id=id)
    form = FeatureForm(request.POST or None, instance=feature)

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

    return render(request, template_name, {"form": form, "grid": feature.grid})
コード例 #8
0
def add_feature(request, grid_slug, template_name="grid/add_feature.html"):

    grid = get_object_or_404(Grid, slug=grid_slug)
    feature = Feature()
    form = FeatureForm(request.POST or None, instance=feature)

    if form.is_valid():
        feature = Feature(grid=grid,
                          title=request.POST['title'],
                          description=request.POST['description'])
        feature.save()
        return HttpResponseRedirect(
            reverse('grid', kwargs={'slug': feature.grid.slug}))

    return render_to_response(template_name, {
        'form': form,
        'grid': grid
    },
                              context_instance=RequestContext(request))
コード例 #9
0
ファイル: views.py プロジェクト: cartwheelweb/garbaginator
def edit_feature(request, id, template_name="grid/edit_feature.html"):
    """edits feature on a grid - this view has the same
    semantics as :func:`grid.views.add_feature`.

    Requires the user to be logged in.
    """

    feature = get_object_or_404(Feature, id=id)
    form = FeatureForm(request.POST or None, instance=feature)

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

    return render_to_response(template_name, { 
        'form': form,
        'grid': feature.grid  
        }, 
        context_instance=RequestContext(request))
コード例 #10
0
def edit_feature(request, id, template_name="grid/edit_feature.html"):
    """edits feature on a grid - this view has the same
    semantics as :func:`grid.views.add_feature`.

    Requires the user to be logged in.
    """

    feature = get_object_or_404(Feature, id=id)
    form = FeatureForm(request.POST or None, instance=feature)

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

    return render_to_response(template_name, {
        'form': form,
        'grid': feature.grid
    },
                              context_instance=RequestContext(request))