Beispiel #1
0
def add_entry():	
	if not current_user.is_authenticated():
		abort(401)
		
	tag_arr=request.form['tags'].split(',')
	
	tag_list_out=[]
	for index, a in enumerate(tag_arr):
		a=a.strip()
		if a:
			tag_list_out.append(Tag(a))
	
	last_entry_object = Entry.query.order_by(Entry.id.desc()).first()
	if last_entry_object: 
		entry_content_object=EntryContent(tag_list_out, last_entry_object.id+1)
	else:
		entry_content_object=EntryContent(tag_list_out, 1)
	
	entry_object=Entry(entry_content_object, request.form['title'], request.form['text'])
	db_session.add(entry_content_object)	
	db_session.add(entry_object)
	db_session.commit()
	
	flash('New post was successfully added')
	return redirect(url_for('show_entries'))
Beispiel #2
0
	def setUp(self):
		"""Before each test, set up a blank database"""
		
		self.db_fd, library.core.config.DB_URI = tempfile.mkstemp()
		library.core.config.TESTING = True
		self.app = blogheaven.app.test_client()
		
		library.core.database.init_db()
		
		last_user_object = User.query.order_by(User.id.desc()).first()		
		if last_user_object:
			admin = User(last_user_object.id+1, last_user_object.id+1, 'default')
		else: 
			admin = User(1, 'leiksu', 'default')			
		db_session.add(admin)
		db_session.commit()
Beispiel #3
0
def delete_entry(entry_id):	
	if not current_user.is_authenticated():
		abort(401)		
		
	db_session.delete(Entry.query.get(entry_id))	
	entry_content_list=EntryContent.query.filter_by(entry_id=entry_id).all()
		
	for index, entry_content_object in enumerate(entry_content_list):		
		for tag_index, tag_object in enumerate(entry_content_object.tag_lists):			
			# delete entries in tags table			
			db_session.delete(Tag.query.get(tag_object.id))	 		
			
		# delete entries in entry_tags table
		db_session.execute('delete from entry_tags where entry_content_id=:entry_content_id', {'entry_content_id':entry_content_object.id})
	
	# delete entries in entry_contents table
	db_session.execute('delete from entry_contents where entry_id=:entry_id', {'entry_id':entry_id})
	db_session.commit()
	
	flash('The post was successfully deleted')
	return redirect(url_for('show_entries'))
Beispiel #4
0
def edit_entry(entry_id=None): 		
	if not current_user.is_authenticated():
		abort(401)

	if entry_id: 
		selected_entry=Entry.query.get(entry_id)		
	else:
		selected_entry = None
		abort(404)
		 
	if request.method == 'POST':
		# update data to database		
		selected_entry.title = request.form['title']
		selected_entry.text = request.form['text']
		db_session.commit()
		
		flash('The post was successfully updated')
		return render_template('show_entries.html', entries=Entry.query.all())
	elif request.method == 'GET':
		# transfer data to form				
		return render_template('show_entries.html', entries=Entry.query.all(), entry_id=entry_id, selected_entry=selected_entry)
Beispiel #5
0
def edit_tags(entry_id=None):	
	if not current_user.is_authenticated():
		abort(401)
		
	tag_arr=request.form['tags'].split(',')	
	tag_list_out=[]
	for index, a in enumerate(tag_arr):		
		a=a.strip()
		if a:
			tag_list_out.append(Tag(a))
			
	entry_content_list=EntryContent.query.filter_by(entry_id=entry_id).all()	
	
	for index, pre_entry_content_object in enumerate(entry_content_list):		
		pre_entry_content_object.active=0
			
	entry_content_object=EntryContent(tag_list_out, entry_id)
	selected_entry=Entry.query.get(entry_id)
	selected_entry.EntryContent=entry_content_object
	db_session.commit()
		
	flash('Tags were successfully updated')
	return render_template('show_entries.html', entries=Entry.query.all() )
Beispiel #6
0
from library.core.database import init_db
init_db()
from library.core.database import db_session
from library.core.models import User
admin = User(1,'leiksu', 'default')
db_session.add(admin)
db_session.commit()