コード例 #1
0
ファイル: views.py プロジェクト: jeffcole/whachapay
def deal_entry(request, place_id):
    """
    Deal entry view.
    """
    if 'data' in request.session:
        # Verify that the passed-in place is in the session.
        place_data = util.get_dict(
            request.session['data']['places']['results'], 'id', place_id)
        if not place_data:
            raise Http404
        data = {'vehicle': request.session['data']['vehicle'],
                'dealer': place_data}
        model_pk = data['vehicle']['obj']['model']
        trim_year = data['vehicle']['text']['year']
        data['place_json'] = json.dumps(place_data)
        if request.method == 'POST':
            form = EntryForm(request.POST, model_pk=model_pk, trim_year=trim_year,
                             label_suffix='')
            if form.is_valid():
                user_ip = queries.store_user_ip(request.META, form.cleaned_data)
                vehicle = queries.store_vehicle(data['vehicle'])
                dealer = queries.store_dealer(place_data)
                deal = queries.store_deal(user_ip, vehicle, dealer,
                                          form.cleaned_data)
                data['deal'] = deal
                request.session['data'] = data
                return redirect(deal_entered)
        else:
            form = EntryForm(initial={'date': date.today()}, model_pk=model_pk,
                             trim_year=trim_year, label_suffix='')
        data['form'] = form
    
        return _rtr('deal_entry.html', data,
                    context_instance=RequestContext(request))
    raise Http404
コード例 #2
0
ファイル: views.py プロジェクト: Dylgar/simpleblog
def edit_entry(request, entry_id):
    data = _get_default_template_data(request)
    if not data['user']:
        return HttpResponseRedirect(users.create_login_url(request.path))
    entry = Entry.get_by_id(long(entry_id))
    if request.method == "POST":
        form = EntryForm(request.POST)
        if form.is_valid():
            entry.title = form.cleaned_data['title']
            entry.content = form.cleaned_data['content']
            entry.put()
            return HttpResponseRedirect("/entry/%s/" % entry_id)
    else:
        form = EntryForm(initial={'title': entry.title, 'content': entry.content})
        data['form'] = form
        data.update(csrf(request))
        return render_to_response('edit.html', data)
コード例 #3
0
ファイル: views.py プロジェクト: Dylgar/simpleblog
def add_entry(request):
    data = _get_default_template_data(request)
    if not data['user']:
        return HttpResponseRedirect(users.create_login_url(request.path))
    if request.method == "POST":
        form = EntryForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            instance = Entry(title=data['title'], 
                             content=data['content'], 
                             labels=data['labels'].split(' '))
            instance.put()
        return HttpResponseRedirect("/entry/%s" % instance.key().id())
    else:
        form = EntryForm()
        data['form'] = form
        data.update(csrf(request))
        return render_to_response('edit.html', data)
コード例 #4
0
ファイル: views.py プロジェクト: odinho/tabulagratulatoria
def adder(request):
    if request.method == 'POST':
        form = EntryForm(request.POST)
        if form.is_valid():
            text = _make_email_body(form.cleaned_data, request.META)
            subject = u' '.join([form.cleaned_data.get('first_name', u''),
                                 form.cleaned_data.get('last_name', u'')])
            mail_managers(subject,
                          text.encode('utf-8'))
            return HttpResponseRedirect(reverse('ui:takk'))
    else:
        form = EntryForm(initial={
            'want_issue': True,
            'want_tg': True,
            'num_issues': 1,
        })
    return render(request, 'ui/adder.html',
                  {
                      'form': form,
                  })