Пример #1
0
def publisher_settings_alerts_edit(request, id):
    ''' View to allow a Publisher the ability to edit an Alert '''
    from forms import AlertForm

    alert = get_object_or_404(request.organization.alert_set, id=id)

    if request.method == "POST":
        form = AlertForm(request.POST)

        if form.is_valid():
            alert.alert_field = form.cleaned_data['alert_field']
            alert.time_period = form.cleaned_data['time_period']

            if not form.cleaned_data['up_or_down']:
                alert.change = str(form.cleaned_data['change'] * -1.00)
            else:
                alert.change = str(form.cleaned_data['change'])

            alert.save()

            return HttpResponseRedirect('/publisher/settings/alerts/')
    else:
        form = AlertForm(initial=alert.__dict__)

    return AQ_render_to_response(request,
                                 'publisher/settings/alerts-edit.html', {
                                     'form': form,
                                     'alert': alert,
                                 },
                                 context_instance=RequestContext(request))
Пример #2
0
def publisher_settings_alerts_add(request):
    ''' View to allow a Publisher to Add an Alert '''
    from atrinsic.base.models import Alert
    from forms import AlertForm

    if request.method == "POST":
        form = AlertForm(request.POST)

        if form.is_valid():
            change = form.cleaned_data['change']

            if not form.cleaned_data['up_or_down']:
                change = change * -1.00

            Alert.objects.create(organization=request.organization,
                                 alert_field=form.cleaned_data['alert_field'],
                                 time_period=form.cleaned_data['time_period'],
                                 change=str(change))

            return HttpResponseRedirect('/publisher/settings/alerts/')
    else:
        form = AlertForm()

    return AQ_render_to_response(request,
                                 'publisher/settings/alerts-add.html', {
                                     'form': form,
                                 },
                                 context_instance=RequestContext(request))