Пример #1
0
def alarm_add(request):
    """Add new Alarm for the logged in user

    **Attributes**:

        * ``form`` - AlarmForm
        * ``template`` - frontend/cdr_alert/alarm/change.html

    **Logic Description**:

        * Add a new Alarm which will belong to the logged in user
          via the AlarmForm & get redirected to the Alarm list
    """
    form = AlarmForm()
    if request.method == 'POST':
        form = AlarmForm(request.POST)
        if form.is_valid():
            obj = form.save(commit=False)
            obj.user = User.objects.get(username=request.user)
            obj.save()
            request.session["msg"] = _('"%(name)s" added.') %\
                                     {'name': request.POST['name']}
            return HttpResponseRedirect('/alert/')
    template = 'frontend/cdr_alert/alarm/change.html'
    data = {
        'module': current_view(request),
        'form': form,
        'action': 'add',
        'notice_count': notice_count(request),
    }
    return render_to_response(template, data,
        context_instance=RequestContext(request))
Пример #2
0
def alarm_add(request):
    """Add new Alarm for the logged in user

    **Attributes**:

        * ``form`` - AlarmForm
        * ``template`` - cdr_alert/alarm/change.html

    **Logic Description**:

        * Add a new Alarm which will belong to the logged in user
          via the AlarmForm & get redirected to the Alarm list
    """
    form = AlarmForm(request.POST or None)
    if form.is_valid():
        form.save(user=request.user)
        form.save()
        request.session["msg"] = _('"%(name)s" added.') % {
            'name': request.POST['name']
        }
        return HttpResponseRedirect(redirect_url_alarm)

    data = {
        'form': form,
        'action': 'add',
    }
    return render_to_response('cdr_alert/alarm/change.html',
                              data,
                              context_instance=RequestContext(request))
Пример #3
0
def alarm_add(request):
    """Add new Alarm for the logged in user

    **Attributes**:

        * ``form`` - AlarmForm
        * ``template`` - cdr_alert/alarm/change.html

    **Logic Description**:

        * Add a new Alarm which will belong to the logged in user
          via the AlarmForm & get redirected to the Alarm list
    """
    form = AlarmForm(request.POST or None)
    if form.is_valid():
        form.save(user=request.user)
        form.save()
        request.session["msg"] = _('"%(name)s" added.') % {'name': request.POST['name']}
        return HttpResponseRedirect(redirect_url_alarm)

    data = {
        'form': form,
        'action': 'add',
    }
    return render_to_response('cdr_alert/alarm/change.html', data, context_instance=RequestContext(request))
Пример #4
0
def alarm_change(request, object_id):
    """Update/Delete Alarm for the logged in user

    **Attributes**:

        * ``object_id`` - Selected alarm object
        * ``form`` - AlarmForm
        * ``template`` - cdr_alert/alarm/change.html

    **Logic Description**:

        * Update/delete selected alarm from the alarm list
          via alarmForm & get redirected to alarm list
    """
    alarm = get_object_or_404(Alarm, pk=object_id, user=request.user)
    form = AlarmForm(request.POST or None, instance=alarm)
    if request.method == 'POST':
        if request.POST.get('delete'):
            alarm_del(request, object_id)
            return HttpResponseRedirect(redirect_url_alarm)
        else:
            if form.is_valid():
                form.save()
                request.session["msg"] = _('"%(name)s" is updated.') % {
                    'name': request.POST['name']
                }
                return HttpResponseRedirect(redirect_url_alarm)
    data = {
        'form': form,
        'action': 'update',
    }
    return render_to_response('cdr_alert/alarm/change.html',
                              data,
                              context_instance=RequestContext(request))
Пример #5
0
def alarm_change(request, object_id):
    """Update/Delete Alarm for the logged in user

    **Attributes**:

        * ``object_id`` - Selected alarm object
        * ``form`` - AlarmForm
        * ``template`` - cdr_alert/alarm/change.html

    **Logic Description**:

        * Update/delete selected alarm from the alarm list
          via alarmForm & get redirected to alarm list
    """
    alarm = get_object_or_404(Alarm, pk=object_id, user=request.user)
    form = AlarmForm(request.POST or None, instance=alarm)
    if request.method == 'POST':
        if request.POST.get('delete'):
            alarm_del(request, object_id)
            return HttpResponseRedirect(redirect_url_alarm)
        else:
            if form.is_valid():
                form.save()
                request.session["msg"] = _('"%(name)s" is updated.') % {'name': request.POST['name']}
                return HttpResponseRedirect(redirect_url_alarm)
    data = {
        'form': form,
        'action': 'update',
    }
    return render_to_response('cdr_alert/alarm/change.html', data, context_instance=RequestContext(request))