Beispiel #1
0
def update(request, account_group_id=None):
    try:
        account_group = AccountGroup.objects.get(pk=account_group_id)
    except AccountGroup.DoesNotExist:
        raise Http404(u'アカウントグループが存在しません。')

    if request.method == 'POST':
        query = request.POST.copy()
        form = EditForm(query)
        if form.is_valid():
            try:
                with transaction.atomic():
                    d = form.cleaned_data
                    account_group.name=d['name']
                    account_group.info=d['info']
                    account_group.save()
            except Exception:
                logger.exception(None)
                raise 
            return render(request, 'accountgroup/complete.html',
                          {'message': u'アカウントグループを更新しました。'})
    else:
        form = EditForm(initial={'name': account_group.name,
                                 'info': account_group.info})
    return render(request, 'accountgroup/edit.html',
                  {'account_group': account_group, 'edit_type': 'update',
                   'form': form})
Beispiel #2
0
def create(request):
    accounts = Account.objects.all()
    if request.method == 'POST':
        query = request.POST.copy()
        form = EditForm(query)
        if form.is_valid():
            try:
                with transaction.atomic():
                    d = form.cleaned_data
                    account_group = AccountGroup(
                        name=d['name'],
                        info=d['info'])
                    account_group.save()
            except Exception:
                logger.exception(None)
                raise 
            return render(request, 'accountgroup/complete.html',
                          {'message': u'アカウントグループを追加しました。'})
    else:
        form = EditForm()
    return render(request, 'accountgroup/edit.html',
                  {'accounts': accounts, 'edit_type': 'create', 'form': form})