Exemplo n.º 1
0
def card_add(request, did):
    description = Description.objects.get(pk=did)
    StageFormset = inlineformset_factory(Card, Stage, form=StageForm, extra=1)
    if request.method == 'POST':
        cardform = CardForm(request.POST)
        table1form = Table1Form(request.POST)
        table2form = Table2Form(request.POST)
        table3form = Table3Form(request.POST)
        table4form = Table4Form(request.POST)
        table31form = Table31Form(request.POST)
        table32form = Table32Form(request.POST)
        stageformset = StageFormset(request.POST)
        if cardform.is_valid() and table1form.is_valid() and table2form.is_valid() and table3form.is_valid() and table4form.is_valid() and table31form.is_valid() and table32form.is_valid():
            card = cardform.save(commit=False)
            card.description = description
            card.save()
            table1 = table1form.save(commit=False)
            table1.card = card
            table1.save()
            table2 = table2form.save(commit=False)
            table2.card = card
            table2.save()
            table3 = table3form.save(commit=False)
            table3.card = card
            table3.save()
            table4 = table4form.save(commit=False)
            table4.card = card
            table4.save()
            table31 = table31form.save(commit=False)
            table31.card = card
            table31.save()
            table32 = table32form.save(commit=False)
            table32.card = card
            table32.save()
            stageformset = StageFormset(request.POST, instance=card)
            if stageformset.is_valid():
                stageformset.save()
            return HttpResponseRedirect(card.get_absolute_url())
    else:
        cardform = CardForm()
        table1form = Table1Form()
        table2form = Table2Form()
        table3form = Table3Form()
        table4form = Table4Form()
        table31form = Table31Form()
        table32form = Table32Form()
        stageformset = StageFormset()
    content = {
        'description': description,
        'cardform': cardform,
        'table1form': table1form,
        'table2form': table2form,
        'table3form': table3form,
        'table4form': table4form,
        'table31form': table31form,
        'table32form': table32form,
        'stageformset': stageformset,
    }
    content.update(csrf(request))
    return render(request, 'card_edit.html', content)
Exemplo n.º 2
0
def create_card(request):
	if request.method == "POST":
		formset = CardForm(data=request.POST)
		if formset.is_valid():
			formset.save()
			return redirect(to='list_cards')
	else:
		formset = CardForm()

	context = {
		'formset':formset
	}
	return render(request, 'create_card.html', context)
Exemplo n.º 3
0
def add_edit_card(request, deck_id=None, card_id=None):
    if card_id:
        card = get_object_or_404(Card, pk=card_id)
    else:
        card = Card()
    if request.method == "GET":
        card_form = CardForm(instance=card)
    elif request.method == "POST":
        if deck_id is None:
            deck_id = card.deck.id
        card_form = CardForm(data=request.POST,
                             instance=card,
                             deck_id=deck_id)
        if card_form.is_valid():
            card = card_form.save(commit=False)
            if not hasattr(card, "deck"):
                # Card is added.
                deck = get_object_or_404(Deck, pk=deck_id)
                card.deck = deck
                card.save()

                # If new card is added then we need also to add it
                # to train pools so user can train it also from now.
                trainpools = TrainPool.objects.filter(deck=deck)
                for train_pool in trainpools:
                    train_card = TrainCard(card=card)
                    train_card.save()
                    train_pool.train_cards.add(train_card)
                    train_pool.save()
                return redirect(request.path)
            else:
                # Card is edited.
                card.save()
                return redirect(reverse("pamietacz.views.show_deck",
                                        args=(deck_id,)))
    return render(request,
                  "add_edit_card.html",
                  {"card_form": card_form,
                   "action": request.get_full_path()})
Exemplo n.º 4
0
def card():
	if session['user'] is None:
		return redirect('/login_required')
	else:
		form = CardForm()
		filterForm = CardFilterForm()
		if form.validate_on_submit():
			transaction = Receipt(name = session['user'],
				card_type = form.card_type.data,
				date = form.date.data,
				description = form.description.data,
				amount = form.amount.data)
			db.session.add(transaction)
			db.session.commit()
			flash('Transaction submitted')
			return redirect('/card')
		transactions = Receipt.query.filter_by(name = session['user']).all()
		if filterForm.validate_on_submit():
			card = filterForm.card_type.data
			transactions = Receipt.query.filter_by(card_type = card, name = session['user'])
		return render_template('card.html',
			form = form,
			filterForm = filterForm,
			transactions = transactions)
Exemplo n.º 5
0
def card_number_page(request):
    form = CardForm(request.GET)
    card = request.GET.get("number")
    request.session["number"] = str(card).replace('-', '')
    # card = request.session["number"]
    request.session["try_pin"] = 0
    cards = Card.objects.filter(number=card, status=1)
    card_blocked = Card.objects.filter(number=card, status=0)
    if cards:
        return HttpResponseRedirect('/cash/pin/')
    elif card_blocked:
        href = '/cash/'
        error = 'Your card is blocked! Please, call the bank!'
        return render(request, 'error.html', {'error': error, 'href': href})
    elif not cards and card != None:
        href = '/cash/'
        error = 'Such card number does not exist!'
        return render(request, 'error.html', {'error': error, 'href': href})
    else:
        return render(request, "card_number_page.html", {'form': form})
Exemplo n.º 6
0
def add_edit_card(request, deck_id=None, card_id=None):
    if card_id:
        card = get_object_or_404(Card, pk=card_id)
    else:
        card = Card()
    if request.method == "GET":
        card_form = CardForm(instance=card)
    elif request.method == "POST":
        if deck_id is None:
            deck_id = card.deck.id
        card_form = CardForm(data=request.POST, instance=card, deck_id=deck_id)
        if card_form.is_valid():
            card = card_form.save(commit=False)
            if not hasattr(card, "deck"):
                # Card is added.
                deck = get_object_or_404(Deck, pk=deck_id)
                card.deck = deck
                card.save()

                # If new card is added then we need also to add it
                # to train pools so user can train it also from now.
                trainpools = TrainPool.objects.filter(deck=deck)
                for train_pool in trainpools:
                    train_card = TrainCard(card=card)
                    train_card.save()
                    train_pool.train_cards.add(train_card)
                    train_pool.save()
                return redirect(request.path)
            else:
                # Card is edited.
                card.save()
                return redirect(
                    reverse("pamietacz.views.show_deck", args=(deck_id, )))
    return render(request, "add_edit_card.html", {
        "card_form": card_form,
        "action": request.get_full_path()
    })
Exemplo n.º 7
0
 def post(self, request):
     print('you go there!')
     form = CardForm(request.POST)
     if form.is_valid():
         form.save()
     return redirect('card-index')
Exemplo n.º 8
0
 def get(self, request):
     context = {
         'cards': Card.objects.all(),
         'form': CardForm(),
     }
     return render(request, 'cards/index.html', context)
Exemplo n.º 9
0
def card_add(request, did):
    description = Description.objects.get(pk=did)
    StageFormset = inlineformset_factory(Card, Stage, form=StageForm, extra=1)
    if request.method == 'POST':
        cardform = CardForm(request.POST)
        table1form = Table1Form(request.POST)
        table2form = Table2Form(request.POST)
        table3form = Table3Form(request.POST)
        table4form = Table4Form(request.POST)
        table31form = Table31Form(request.POST)
        table32form = Table32Form(request.POST)
        stageformset = StageFormset(request.POST)
        if cardform.is_valid() and table1form.is_valid(
        ) and table2form.is_valid() and table3form.is_valid(
        ) and table4form.is_valid() and table31form.is_valid(
        ) and table32form.is_valid():
            card = cardform.save(commit=False)
            card.description = description
            card.save()
            table1 = table1form.save(commit=False)
            table1.card = card
            table1.save()
            table2 = table2form.save(commit=False)
            table2.card = card
            table2.save()
            table3 = table3form.save(commit=False)
            table3.card = card
            table3.save()
            table4 = table4form.save(commit=False)
            table4.card = card
            table4.save()
            table31 = table31form.save(commit=False)
            table31.card = card
            table31.save()
            table32 = table32form.save(commit=False)
            table32.card = card
            table32.save()
            stageformset = StageFormset(request.POST, instance=card)
            if stageformset.is_valid():
                stageformset.save()
            return HttpResponseRedirect(card.get_absolute_url())
    else:
        cardform = CardForm()
        table1form = Table1Form()
        table2form = Table2Form()
        table3form = Table3Form()
        table4form = Table4Form()
        table31form = Table31Form()
        table32form = Table32Form()
        stageformset = StageFormset()
    content = {
        'description': description,
        'cardform': cardform,
        'table1form': table1form,
        'table2form': table2form,
        'table3form': table3form,
        'table4form': table4form,
        'table31form': table31form,
        'table32form': table32form,
        'stageformset': stageformset,
    }
    content.update(csrf(request))
    return render(request, 'card_edit.html', content)