Exemplo n.º 1
0
	def set_name(self):
		try:
			user_name = request.POST.getone("name")
			if User.is_unique(user_name):
				user = meta.Session.query(User).get(int(session['user_id']))
				user.name = session['user_name'] = user_name
				user.save()
				session.save()
		except Exception, ex:
			log.error(traceback.format_exc())
Exemplo n.º 2
0
	def check_unique_name(self):
		try:
			user_name = request.params.getone("name")
			if User.is_unique(user_name):
				return "Not Taken"
			else:
				return "Already Taken"
		except Exception, ex:
			log.error(traceback.format_exc())
			return "Error"
Exemplo n.º 3
0
	def create(self, parent_id=None, format='html'):
		"""POST /``REST_Collection``: Create a new item"""
		if session['user_name'] is None:
			name = unicode(request.POST.get('name',u'').strip())
			if name != u'' and User.is_unique(name):
				user = meta.Session.query(User).get(int(session['user_id']))
				user.name = session['user_name'] = name
				user.save()
				session.save()
		try:
			item = self._create(format, parent_id)
		except UnacceptedFormat: 
			abort(415, detail='415 Unsupported Media Type')
		#except InvalidForm, ex:
		#	return ex.value
		
		if self.FORMAT_NEEDS_REDIRECT[format] is True:
			redirect(self._py_object.url('story',permalink=item.article.permalink))
		else:
			#if parent_id is None:
			#	abort(201, detail='201 Created', headers={'Location': self._py_object.url(self.SINGLE, id=item.id)})
			#else:
			abort(201, detail='201 Created', headers={'Location': self._py_object.url(self.SINGLE, parent_id=parent_id, id=item.id)})