Esempio n. 1
0
    def flush(self):
        "Flushes internal buffer to web and irc services."
        # Timestamp
        winner = self.inc_winner()
        snippit = Snippit()
        snippit.channel = self.engine.current_channel
        snippit.nickname = winner
        snippit.code = redent(str("\n".join(self._ibuffer)))
        snippit.result = unicode("\n".join(self._obuffer))
        snippit.save()

        # Less than four lines
        if len(self._obuffer) <= 4:
            for line in self._obuffer:
                # Return result to channel
                self.engine.signals['outgoing_msg'].emit(
                    self.engine.ircconf.channel,
                    line
                )
        else:
            # Return perma-link to output
            self.engine.signals['outgoing_msg'].emit(
                self.engine.ircconf.channel,
                # TODO: Change with config.
                'Output too long : http://%s/%d' % (SITE_DOMAIN, snippit.pk)
            )
        self._ibuffer = []
        self._obuffer = []
Esempio n. 2
0
def paste(request):
    if request.method == 'POST':
	form = PasteForm(request.POST)
	if form.is_valid():
	    snippit = form.save()
            reindent = request.POST.get('reindent', False)
            if reindent:
                snippit.code = redent(snippit.code)
                snippit.save()
	    pk = snippit.pk
	    return redirect_to(request, "/%d" % pk, False, False)
	else:
	    return render_to_response('paste.html', {
		    'form': form}, context_instance=RequestContext(request))
    else:
	form = PasteForm()
	return render_to_response('paste.html', {
		'form': form}, context_instance=RequestContext(request))