コード例 #1
0
ファイル: views.py プロジェクト: uSlackr/fermentrack
def external_push_brewers_friend_view(request, push_target_id):
    # TODO - Add user permissioning
    # if not request.user.has_perm('app.add_device'):
    #     messages.error(request, 'Your account is not permissioned to add devices. Please contact an admin')
    #     return redirect("/")

    try:
        push_target = BrewersFriendPushTarget.objects.get(id=push_target_id)
    except ObjectDoesNotExist:
        messages.error(
            request, "Brewers's Friend push target {} does not exist".format(
                push_target_id))
        return redirect('external_push_list')

    if request.POST:
        form = forms.BrewersFriendPushTargetModelForm(request.POST,
                                                      instance=push_target)
        if form.is_valid():
            updated_push_target = form.save()
            messages.success(request, 'Updated push target')
            return redirect('external_push_list')

        messages.error(request, 'Unable to update push target')

    form = forms.BrewersFriendPushTargetModelForm(instance=push_target)

    return render(
        request,
        template_name='external_push/brewers_friend_push_target_view.html',
        context={
            'push_target': push_target,
            'form': form
        })
コード例 #2
0
ファイル: views.py プロジェクト: uSlackr/fermentrack
def external_push_brewers_friend_target_add(request):
    # TODO - Add user permissioning
    # if not request.user.has_perm('app.add_device'):
    #     messages.error(request, 'Your account is not permissioned to add devices. Please contact an admin')
    #     return redirect("/")

    form = forms.BrewersFriendPushTargetModelForm()

    if request.POST:
        form = forms.BrewersFriendPushTargetModelForm(request.POST)
        if form.is_valid():
            new_push_target = form.save()
            messages.success(request, 'Successfully added push target')

            # Update last triggered to force a refresh in the next cycle
            new_push_target.last_triggered = new_push_target.last_triggered - datetime.timedelta(
                seconds=new_push_target.push_frequency)
            new_push_target.save()

            return redirect('external_push_list')

        messages.error(request, 'Unable to add new push target')

    # Basically, if we don't get redirected, in every case we're just outputting the same template
    return render(
        request,
        template_name='external_push/brewers_friend_push_target_add.html',
        context={'form': form})