Beispiel #1
0
def new_paste(request):
    if request.method == "POST":
        form = PasteForm(request.POST)
        if form.is_valid():
            form.save()
            return list(request)
        else:
            print(form.errors)
    else:
        form = PasteForm()
    
    return render(request, 'add.html', {'form': form})
Beispiel #2
0
def paste_view(request, pastehash = None):
    """Basic pastebin."""

    context = {}
    context['errors'] = []
    
    if request.method == "POST" and request.POST:
        paste = Paste()
        pasteform = PasteForm(request.POST, instance=paste)

        if pasteform.is_valid():
            paste = pasteform.save()
            return redirect(paste.get_absolute_url())
            
    else:
        if pastehash:
            paste = get_object_or_404(Paste, id=pastehash)
            paste.save()
            context['paste'] = paste

    # For now, I'm going to leave the expiration here.
    Paste.objects.remove_expired()

    pasteform = PasteForm()
    context['pasteform'] = pasteform

    context['previous_pastes'] = Paste.objects.all()[:settings.SHOWN_RECENT_PASTES]

    return render(request, 'paste.html', context)
def index(request):
    if request.method == "POST":
        form = PasteForm(request.POST)
        if form.is_valid():
            paste = form.save(commit=False)
            paste.save()
            return redirect('pastebin-detail', pk=paste.pk)
    else:
        form = PasteForm()

    return render(request, 'pastebin/index.jinja2', {'form': form})
def index(request):
    if request.method == "POST":
        form = PasteForm(request.POST)
        if form.is_valid():
            paste = form.save(commit=False)
            paste.save()
            return HttpResponseRedirect(
                '/pastes/{paste.id}'.format(paste=paste))
    else:
        form = PasteForm()

    return render(request, 'pastebin/index.jinja2', {'form': form})
Beispiel #5
0
def index(request):
    form = PasteForm()
    ctx = {}

    if request.method == 'GET':
        ctx["form"] = form
        return render(request, 'pastebin/index.jinja2', ctx)
    elif request.method == 'POST':
        form = PasteForm(request.POST)
        if form.is_valid():
            a = form.save()
            return redirect('pastebin-detail', id=a.id)
        else:
            return render(request, 'pastebin/index.jinja2', {'form': form})
Beispiel #6
0
def index(request):
    form = PasteForm()
    ctx = {'title': 'Bem vindo ao Pastebin'}

    if request.method == 'GET':
        ctx['form'] = form
        return render(request, 'pastebin/index.jinja2', ctx)
    elif request.method == 'POST':
        form = PasteForm(request.POST)
        if form.is_valid():
            paste = form.save()
            return redirect('pastebin:pastebin-detail', id=paste.id)
        else:
            return render(request, 'pastebin/index.jinja2', {'form': form})
Beispiel #7
0
def index(request,template='djpaste/create.html'):
    if request.method == 'POST':
        form = PasteForm(request.POST)
        if form.is_valid():
            paste = form.save()
            request.session['language'] = form.cleaned_data['language']
            request.session['name'] = form.cleaned_data['name']
            return HttpResponseRedirect(paste.get_absolute_url())            
    if request.method == 'GET':
        try:
            language = request.session['language']
            name = request.session['name']
        except KeyError, e:
            language = ''
            name =  ''
        form = PasteForm(initial={'name':name, 'language':language})