Ejemplo n.º 1
0
	def get(self, entry_id):
		e = Entry.get( entry_id )
		
		if e == None:
			# entry not found
			self.writeResponse({'error': True, 'message': 'Entry not found'})
		else:	
			self.writeResponse({'error': False, 'entry': e, 'entry_id': entry_id})
Ejemplo n.º 2
0
	def get(self, entry_id):
		try:
			entry = Entry.get(entry_id)
		except BadKeyError:
			entry = None
				
		if entry == None:
			self.writeResponse('error.html', { 'message': 'Entry could not be found '} )
		else:			
			# if found, display it	
			self.writeResponse('new_blog_post.html', { 
				'entry': entry, 
				'entry_id': entry.key(), 
				'form': EntryForm(instance=entry).render() 
			})		
Ejemplo n.º 3
0
	def delete(self, entry_id):
		e = Entry.get( entry_id )
		
		if e == None:
			# entry not found
			self.writeResponse({'error': True, 'message': 'Entry not found'})
		else:
			# otherwise, mark it as deleted and return success
			e.deleted = True
			e.put()
			
			# reset the data cache since there's been some changes
			from google.appengine.api import memcache
			memcache.flush_all()		
			
			self.writeResponse({'error': False, 'message': 'Entry successfully deleted', 'entry_id': entry_id})
Ejemplo n.º 4
0
def es_search2():
    if not app.config.get('IS_ES_INDEX'):
        return 'Sorry, you need enable Elasticsearch first.'

    app.logger.info('{} - {}'.format(request.remote_addr, request.url))
    query = request.args.get('q')
    results = es.search(index=app.config.get('ES_INDEX_NAME'),
                        doc_type=app.config.get('ES_TYPE_NAME'),
                        q=query)
    hits = results['hits']['hits']

    entries = []
    for hit in hits:
        entries.append(Entry.get(Entry.id == hit['_id']))

    return render_template('search.jinja2', entries=entries, search=query)
Ejemplo n.º 5
0
	def entry(self, entry_slug):
		
		# see if we can find the entry by slug
		entry = Entry.all().filter('slug =', entry_slug ).filter('deleted = ', False).get()
		#entry = self.getEntryQuery({'slug = ': entry_slug}).get()
		# entry not found, let's try by id
		if entry == None:
			try: 
				entry = Entry.get(entry_slug)
			except BadKeyError:
				entry = None
				
			if entry == None:
				#self.response.out.write( View(self.request, 'error.html').render ({ 'message': 'Entry could not be found '} ))
				return 'error.html', { 'message': 'Entry could not be found ', 'error': True}
					
		# if found, display it
		return 'entry.html', { 'entry': entry } 	
Ejemplo n.º 6
0
	def _updateEntry(self, form, entry_id):
		logging.debug("query string: " + self.request.query_string)
		logging.debug("query body: " + self.request.body)
		e = Entry.get( entry_id )
		
		if e == None:
			# entry not found
			self.response.out.write( View(None, self.request).render( {'error': True, 'message': 'Entry not found'}, force_renderer='json'))
			
		form = EntryForm( self.request.POST )
		if form.is_valid():
			# validation succesful
			e.title = form.clean_data['title']
			e.text = form.clean_data['text']
			e.tags = form.clean_data['tags'].split(' ')
			e.lat = form.clean_data['lat']
			e.lng = form.clean_data['lng']			
			e.put()
			
			# reset the data cache since there's new content
			from google.appengine.api import memcache
			memcache.flush_all()			
			
			data = {
				'error': False, 
				'entry': e, 
				'entry_id': entry_id,
				'entry_link': e.permalink(),
				'message': 'Entry successfully updated. <a href="%s">Link to the entry</a>.' % e.permalink(),
			}
		else:
			# form not valid, must show again with the errors
			data = { 'error': True, 'errors': {}}
			# (the Form object is actually iterable)
			for field in form:
				if field.errors:
					data['errors'][field.name] = field.errors

		# return the view
		self.writeResponse(data)
Ejemplo n.º 7
0
	def _addNewEntry(self, form):
		if form.is_valid():
			# validation successful, we can save the data
			e = Entry()
			e.title = form.clean_data['title']
			e.text = form.clean_data['text']
			e.tags = form.clean_data['tags'].split(' ')
			e.lat = form.clean_data['lat']
			if e.lat == "":
				e.lat = None
			e.lng = form.clean_data['lng']			
			if e.lng == "":
				e.lng = None
			e.source = 'blog'
			e.put()
			
			e = Entry.get(e.key())
			
			# reset the data cache since there's new content
			from google.appengine.api import memcache
			memcache.flush_all()			

			# return successful creation
			view_data = {
				'message': 'New blog entry added successfully. <a href="%s">Link to the entry</a>.' % e.permalink(), 
				'error': False,
				'entry_link': e.permalink(),							
				'entry': e
			}
			self.writeResponse(view_data)

		else:
			# form not valid, must show again with the errors
			data = { 'error': True, 'errors': {}}
			# (the Form object is actually iterable)
			for field in form:
				if field.errors:
					data['errors'][field.name] = field.errors

			self.writeResponse(data)