Exemplo n.º 1
0
def entries(request):

    queryset = Entry.objects.order_by('-publication_date')[:5]
    logged_in = False
    if request.session.get('logged_in'):
        logged_in = True
        if request.method == 'POST':
            form = EntryForm(request.POST)
            if form.is_valid():
                title = form.cleaned_data['title']
                author = User.objects.get(id=request.session.get('user'))
                text = form.cleaned_data['text']
                new_entry = Entry(text=text, title=title, author=author)
                new_entry.save()
                form = EntryForm()
        else:
            form = EntryForm()
    else:
        form = None
        logged_in = False
    e_dict = archive_dict()

    return render(request, 'entry_list.html', {
                  'form': form,
                  'list_of_entries': queryset,
                  'logged_in': logged_in,
                  'e_dict': e_dict},
                  )
Exemplo n.º 2
0
def new():
    # Create the form
    form = EntryForm(request.form)
    # If we're posting and the form is filled out correctly
    # Create the new entry
    # Otherwise return the empty form
    if request.method == 'POST' and form.validate():
        Entry.create(**form.data)
        return redirect('/')
    return render_template('new.html', form=form)
Exemplo n.º 3
0
def edit(id):
    # Get selected entry and create the form
    entry = Entry.get(Entry.id == id)
    form = EntryForm(request.form, entry)
    # If we're posting and the form is filled out correctly
    # Update the entry
    # Otherwise render the empty form
    if request.method == 'POST' and form.validate():
        print(form.data)
        Entry.update(**form.data).where(Entry.id == id).execute()
        return redirect('/')
    return render_template('edit.html', entry=entry, form=form)
Exemplo n.º 4
0
def enter(request):
    def errorHandle(error):
        return render_to_response('templates/default.html', {
                'error' : error,
                'form' : form,
        },context_instance=RequestContext(request))
        
    if request.method == 'POST': # If the form has been submitted...
        form = EntryForm(request.POST)
        reaction = request.POST['reaction']
        out = form.getOut()
        stuff=form.getStuff()
        
        fullreaction=form.getFullReactions()
        print fullreaction
        if form.is_valid():# and formisreallyok: # All validation rules pass
            name = request.POST['name']
            reaction = request.POST['reaction']
            products = request.POST['products']
            conditions = request.POST['conditions']
            synthons = request.POST['synthons']
            doi = request.POST['doi']
            #sadly /t and other tabulations get collapsed to one space in HTML. Therefore the fields are separated by 4* 
            reactionstring=name + 4*" " + reaction +4*" " + products + 4*" " + conditions + 4*" " + str(synthons)+4*" "+doi
            
            return render_to_response('templates/results.html', {
                        'form': form,
                        'reactionstring': reactionstring
                    },context_instance=RequestContext(request))
        else:
            error = u'form is invalid'
            return errorHandle(error)
    else:
        form = EntryForm() 
        
        out = form.getOut()# An unbound form
        return render_to_response('templates/default.html', {
            'form': form,
        }, context_instance=RequestContext(request))