Exemplo n.º 1
0
def delete_time(request, tid):
    "Delete a time period"
    time_period = get_object_or_404(Time, pk=tid)
    if request.method == "POST":
        form = TimeForm(request.POST, instance=time_period)
        if form.is_valid():
            try:
                time_period.delete()
                msg = _("The time period has been deleted")
            except DatabaseError:
                msg = _("The time period could not be deleted")
            messages.info(request, msg)
            return HttpResponseRedirect(reverse("time-rules"))
    else:
        form = TimeForm(instance=time_period)
    form.fields["name"].widget.attrs["size"] = "45"
    return render_to_response("web/config/delete_time.html", locals(), context_instance=RequestContext(request))
Exemplo n.º 2
0
def add_time(request):
    "add a time period"
    if request.method == "POST":
        form = TimeForm(request.POST)
        if form.is_valid():
            try:
                form.save()
                msg = _("The time period was created successfully")
                messages.info(request, msg)
                return HttpResponseRedirect(reverse("time-rules"))
            except DatabaseError:
                msg = _("The time period could not be created")
                messages.info(request, msg)
                return HttpResponseRedirect(reverse("time-rules"))
    else:
        form = TimeForm()
    form.fields["name"].widget.attrs["size"] = "45"
    return render_to_response("web/config/add_time.html", locals(), context_instance=RequestContext(request))
Exemplo n.º 3
0
def delete_time(request, tid):
    "Delete a time period"
    time_period = get_object_or_404(Time, pk=tid)
    if request.method == 'POST':
        form = TimeForm(request.POST, instance=time_period)
        if form.is_valid():
            try:
                time_period.delete()
                msg = _('The time period has been deleted')
            except DatabaseError:
                msg = _('The time period could not be deleted')
            messages.info(request, msg)
            return HttpResponseRedirect(reverse('time-rules'))
    else:
        form = TimeForm(instance=time_period)
    form.fields['name'].widget.attrs['size'] = '45'
    return render_to_response('web/config/delete_time.html',
                              locals(),
                              context_instance=RequestContext(request))
Exemplo n.º 4
0
def add_time(request):
    "add a time period"
    if request.method == 'POST':
        form = TimeForm(request.POST)
        if form.is_valid():
            try:
                form.save()
                msg = _('The time period was created successfully')
                messages.info(request, msg)
                return HttpResponseRedirect(reverse('time-rules'))
            except DatabaseError:
                msg = _('The time period could not be created')
                messages.info(request, msg)
                return HttpResponseRedirect(reverse('time-rules'))
    else:
        form = TimeForm()
    form.fields['name'].widget.attrs['size'] = '45'
    return render_to_response('web/config/add_time.html',
                              locals(),
                              context_instance=RequestContext(request))