Пример #1
0
	def post(self, request, *args, **kwargs):
		try:
			thread_id = int(kwargs['thread_id'])
			name = request.POST['name']
			mail = request.POST['mail']
			body = request.POST['body']
			try:
				attach = request.POST['attach']
				attach_sfx = request.POST['attach_sfx']
			except KeyError:
				attach = None
				attach_sfx = None
		except KeyError:
			return HttpResponseBadRequest()

		timestamp = time.time()
		try:
			recStr = makeRecordStr(timestamp, name, mail, body, attach, attach_sfx)
		except BadRecordException:
			return HttpResponseBadRequest()
		_, bin_id_hex, body = tuple(str2recordInfo(recStr))[0]
		bin_id = a2b_hex(bin_id_hex)
		with Session() as s:
			try:
				Record.add(s, thread_id, timestamp, bin_id, body)
				s.commit()
				threadTitle = Thread.get(s, id=thread_id).value(Thread.title)
				Recent.add(s, timestamp, bin_id, Thread.getFileName(threadTitle))
				s.commit()
				msgqueue.updateRecord(thread_id, bin_id_hex, timestamp)
			except IntegrityError:
				s.rollback()
		return HttpResponse()
Пример #2
0
	def dispatch(self, request, *args, **kwargs):
		with Session() as s:
			try:
				fileName = kwargs['file']
				prefix, basename = splitFileName(kwargs['file'])
				title = a2b_hex(basename)
				atime = int(kwargs['time'])
				id_hex = kwargs['id']
				id_bin = a2b_hex(id_hex)
				addr = kwargs['node'].replace('+', '/')
			except (BadFileNameException, binascii.Error, ValueError):
				return HttpResponseBadRequest()

			if addr.startswith(':') or addr.startswith('/'):
				addr = request.META['REMOTE_ADDR'] + addr
			response = HttpResponse()
			if prefix=='thread':
				if Recent.get(s, atime, id_bin, fileName).first():
					return response
				thread_id = Thread.get(s, title=title).value(Thread.id)
				if thread_id:
					msgqueue.getAndUpdateRecord(addr, thread_id, id_hex, atime)
				try:
					Recent.add(s, timestamp=atime, binId=id_bin, fileName=fileName)
					s.commit()
				except IntegrityError:
					s.rollback()
			return response