def paste(self, bot, update): bot_user = self.get_user(update) bot.send_chat_action(chat_id=update.message.chat_id, action=ChatAction.TYPING) _source = Paste(source=update.message.text, name='Untitled', language='auto', author=bot_user, created_using_bot=True) try: _source.save() _source.alias = hashlib.md5(str( _source.id).encode()).hexdigest()[:8] _source.save() text = _('paste_message').format(prepare_source_link( _source.alias)) update.message.reply_text(text) except Error: update.message.reply_text(_('something_went_wrong'))
def main(request): posted = request.POST.get('paste', -1) title = request.POST.get('title', -1) if (posted != -1) and (title != -1): randString = random_generator() while Paste.objects.filter(url=randString).count() > 0: randString = random_generator() p = Paste(title=title,url=randString,content=posted) p.save() return redirect('/'+ randString) else: return render(request, 'paste/index.html')
def create(self, validated_data): try: language = guess_lexer(validated_data['source']).name except ClassNotFound: language = 'undefined' source = Paste(name=validated_data['name'], source=validated_data['source'], language=language) source.save() source.alias = hashlib.md5(str(source.id).encode()).hexdigest()[:8] source.save() return source
def add(request): if request.method == 'POST': language = request.POST['language'] content = request.POST['content'] try: lang = Language.objects.get(pk=language) except: lang = Language.objects.get(pk='txt') paste = Paste(content=content, language=lang) paste.save() paste = Paste.objects.latest() return HttpResponse(paste.pk, content_type='text/plain') else: return redirect('/api')
def handle_new_paste(data, remote_ip_addr): p = Paste(data=data, remote_ip_addr=remote_ip_addr) p.save() return p
def SavePaste(request): paste = Paste(title = request.POST.get('title'), text = request.POST.get('text'), date = timezone.now()); paste.save() return HttpResponseRedirect(reverse('index'))