Exemple #1
0
	def generate(self, page=None, filter_=None, name=None, format='html'):
		# i hate favicon
		if page == 'favicon.ico':
			abort(404)
		
		if page is None or page == 'main':
			page_obj = meta.Session.query(Page).filter(Page.slug=="main").filter(Page.visible==True).one()
			page_id = None
		else:
			try:
				page_obj = meta.Session.query(Page).filter(Page.slug==page).filter(Page.visible==True).one()
			except:
				abort(404)
			page_id = page_obj.id
		
		items_per_page = int(app_globals.settings(u'maximum_items','blog'))
		page_num = int(request.GET.get('p',1))
		first_item = (page_num - 1) * items_per_page
		
		query = meta.Session.query(Article).filter(Article.published != None)
		specs = {'published':{'$ne':None}}
		if page_id is None:
			query = query.filter(Article.page.has(Page.in_main==True))
			#specs['page.in_main'] = True
		else:
			query = query.filter(Article.page.has(Page.id==page_id))
			#specs['page.id'] = page_id
		
		if filter_ == 'user' and name is not None:
			query = query.filter(Article.author_rel.has(User.name==name))
			#specs['author_rel.name'] = name
		elif filter_ == 'tag' and name is not None:
			#specs['tags.id'] = name
			query = query.filter(Article.tags.any(Tag.id==name))
		
		items = query.order_by(Article.sticky.desc(),Article.published.asc()).limit(items_per_page).offset(first_item).options(orm.joinedload('tags')).all()
		#items = Article.fetch(
		#	specs,
		#	sort=[('sticky','DESCENDING'),('published','DESCENDING')],
		#	offset=first_item,limit=items_per_page,options=[orm.joinedload('tags')]
		#)
		
		if filter_ is not None:
			filter_ = (filter_,name)
		else:
			filter_ = None
		
		if format == 'atom':
			response.content_type = 'application/atom+xml'
			return render_jinja2("%s.atom.jinja"%page_obj.template)
		#elif format == 'json':
		#	response.content_type = 'application/json'
		#	return json.dumps({'data':[item.to_dict() for item in items],'page':page_obj})
		elif format == 'html':
			return render_jinja2("%s.jinja"%page_obj.template, extra_vars={'items':items, 'page_num':page_num, 'page':page_obj})
		else:
			abort(404)
Exemple #2
0
	def index(self, parent_id=None, format='html'):
		"""GET /``REST_Collection``: All items in the collection"""
		settings = self._get_settings()
		
		try:
			page_num = int(self._py_object.request.GET.get('p',1))
		except ValueError:
			page_num = 1
		try:
			limit = int(settings.get('maximum_items'))
		except (ValueError,TypeError):
		 	limit = 20
		offset = (page_num - 1) * limit
		
		items = self._index(parent_id=parent_id, limit=limit, offset=offset)
		
		try:
			self._py_object.response.content_type = self.RESOURCE_FORMATS[format]
			extra_vars={'settings':settings,'page_num':page_num,'items':items,'ctrl_name':self.MULTIPLE}
			#if format == 'ajax':
			#	return render_jinja2_block('/%s/index.html.jinja'%self.MULTIPLE, 'content', extra_vars=extra_vars)
			#else:
			return render_jinja2('/%s/index.%s.jinja'%(self.MULTIPLE,format), extra_vars=extra_vars)
		except TemplateNotFound, ex:
			self.LOGGER.error(ex)
			abort(415, detail='415 Unsupported Media Type')
Exemple #3
0
	def story(self, permalink=None, format='html'):
		item = app_globals.get_article_from_permalink(permalink)
		#item = Article.fetch_one({'permalink':permalink,'published':{'$ne':None}})
		if item is None:
			abort(404)
		else:
			return render_jinja2('/blog/story.jinja', extra_vars={'item':item})
Exemple #4
0
	def new(self, parent_id=None, format='html'):
		"""GET /``REST_Collection``/new: Form to create a new item"""
		settings = self._get_settings()
		item = self._new(parent_id, with_defaults=True)
		try:
			extra_vars = {'item':item,'settings':settings,'ctrl_name':self.MULTIPLE}
			#if format == 'ajax':
			#	return render_jinja2_block('/%s/new.html.jinja'%self.MULTIPLE, 'content', extra_vars=extra_vars)
			#else:
			return render_jinja2('/%s/new.%s.jinja'%(self.MULTIPLE,format), extra_vars=extra_vars)
		except TemplateNotFound, ex:
			self.LOGGER.error(ex)
			abort(415, detail='415 Unsupported Media Type')
Exemple #5
0
	def edit(self, id, parent_id=None, format='html'):
		"""GET /``REST_Collection``/id/edit: Form to edit an existing item"""
		settings = self._get_settings()
		item = self._get_from_id(id, parent_id)
		if item is None:
			abort(404, detail='404 Not Found')
		try:
			extra_vars = {'item':item,'settings':settings,'ctrl_name':self.MULTIPLE}
			#if format == 'ajax':
			#	return render_jinja2_block('/%s/edit.html.jinja'%self.MULTIPLE, 'content', extra_vars=extra_vars)
			#else:
			return render_jinja2('/%s/edit.%s.jinja'%(self.MULTIPLE,format), extra_vars=extra_vars)
		except TemplateNotFound, ex:
			self.LOGGER.error(ex)
			abort(415, detail='415 Unsupported Media Type')
Exemple #6
0
	def show(self, id, parent_id=None, format='html'):
		"""GET /``REST_Collection``/id: Show a specific item"""
		try:
			page_num = int(self._py_object.request.GET.get('p',1))
		except ValueError:
			#someone put something stupid as the value for page
			page_num = 1
		try:
			settings = self._get_settings()
			item = self._get_from_id(id, parent_id)
			if item is None:
				abort(404, detail='404 Not Found')
			settings = self._get_settings()
			self._py_object.response.content_type = self.RESOURCE_FORMATS[format]
			extra_vars = {'item':item,'settings':settings,'page_num':page_num,'ctrl_name':self.MULTIPLE}
			#if format == 'ajax':
			#	return render_jinja2_block('/%s/show.html.jinja'%self.MULTIPLE, 'content', extra_vars=extra_vars)
			#else:
			return render_jinja2('/%s/show.%s.jinja'%(self.MULTIPLE,format), extra_vars=extra_vars)
		except TemplateNotFound, ex:
			self.LOGGER.error(ex)
			abort(415, detail='415 Unsupported Media Type')
Exemple #7
0
	def search(self):
		try:
			q = request.GET.getone("q")
			pnum = request.GET.get("pnum",None)
		except:
			redirect(url("main"))
		page_num = 1 if pnum is None else int(pnum)
		items_per_page = int(app_globals.settings(u'maximum_items','blog'))
		first_item = (page_num - 1) * items_per_page
		
		q_string = q.lower()
		res = meta.Session.query(Article).filter(
			sql.or_(
				Article.tags.any(sql.func.lower(Tag.label).contains(q_string)),
				sql.func.lower(Article.title).contains(q_string),
				sql.func.lower(Article.metacontent).contains(q_string)
			)
		).filter(Article.published!=None).filter(Article.page.has(Page.in_main==True)).\
		order_by(Article.published.desc()).limit(items_per_page).offset(first_item)
		items = res.all()
		
		return render_jinja2('/blog/stream.jinja', extra_vars={'items':items, 'page_num':page_num, 'page':None})
Exemple #8
0
	def browse(self):
		"this template uses ajax to page through and sort thumbs of all media"
		"once a thumbnail is selected, the form goes to quick_upload"
		ckedit_num = request.GET.get('CKEditorFuncNum',None)
		return render_jinja2('/admin/browse.html.jinja', extra_vars={'ckedit_num':ckedit_num})
Exemple #9
0
	def index(self, format='html'):
		# Dashboard for admin
		if format == 'html':
			return render_jinja2('/admin/dashboard.jinja')
		else:
			abort(404)
Exemple #10
0
	def edit(self, format='html'):
		"""GET /accounts/edit: Form to edit an existing item"""
		# url('edit_account')
		item = meta.Session.query(User).get(int(session['user_id']))
		return render_jinja2("/accounts/edit.html.jinja", extra_vars={'item':item})
Exemple #11
0
	def new(self, format='html'):
		"""GET /accounts/new: Form to create a new item
		this is a super simple form to quickly create new user accounts
		when someone initially logs in with openid, oauth or facebook"""
		# url('new_account')
		return render_jinja2("/accounts/new.html.jinja")
Exemple #12
0
	def index(self):
		return render_jinja2('/analytics/base.jinja')
Exemple #13
0
	def sitemap(self, format='html'):
		tags = meta.Session.query(Tag).order_by(Tag.label.asc()).all()
		users = meta.Session.query(User.name).filter(User.type <= self.permissions_map['probation']).order_by(User.name.asc()).all()
		pages = meta.Session.query(Page.title,Page.slug).filter(Page.visible == True).order_by(Page.title.asc()).all()
		return render_jinja2('/blog/sitemap.%s.jinja'%format, extra_vars={'tags':tags,'users':users,'pages':pages})
Exemple #14
0
	def xrds(self):
		response.content_type = 'application/xrds+xml'
		return render_jinja2('/xrds.jinja')
Exemple #15
0
	def create(self):
		return render_jinja2('/blog/login.jinja')