コード例 #1
0
ファイル: views.py プロジェクト: dpflug/pasteclone
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)
コード例 #2
0
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})
コード例 #3
0
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})
コード例 #4
0
ファイル: views.py プロジェクト: sq271/web.dev
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})
コード例 #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})
コード例 #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})
コード例 #7
0
ファイル: views.py プロジェクト: samal/django-pastebin
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})
コード例 #8
0
ファイル: views.py プロジェクト: tusec/Pastebin
def index(request):
	if request.method == 'POST': #form has been submitted
		form = PasteForm(request.POST) #store POST data
		if form.is_valid(): #Validation rules
			nick = form.cleaned_data['nick']
			title = form.cleaned_data['title']
			content = form.cleaned_data['content']
			expiration = form.clenaed_data['expiration']
			datetime = datetime.datetime.now()
			expiredate = datetime.datetime.now() + datetime.timedelta(seconds=int(expiration))
			
			model = Pastebin(nick, datetime, title, content, expiredate)
			model.save
			
			return HttpResponseRedirect('/' + nick + '/') #message after post
	else:
		form = PasteForm()	
	return render_to_response('index.html',{'form':form})