Exemple #1
0
def getHistory(id):
	h = HistoryModel()
	result = h.getHistoryById(id)

	if result is None:
		abort(404)

	return jsonify({'result': result})
Exemple #2
0
def deleteHistory(id):
	h = HistoryModel()
	history = h.getHistoryById(id)
	h.deleteHistory(id)

	# Send email to admins and author
	u = UserModel()
	user = u.getUserByUsername(history['username'])
	admins = u.getAllAdmins()
	for admin in admins:
		sendDeletedHistoryNotification(admin, history)
	if not user['admin']:
		sendDeletedHistoryNotification(user, history)

	return jsonify({'result': 'true'})
Exemple #3
0
def editHistory(id):
	data = json.loads(request.data)

	h = HistoryModel()
	old_history = h.getHistoryById(id)
	h.updateHistory(id, data)

	i = ImageModel()
	# Unlink deleted images
	if len(data['images']) > 0:
		old_imagelist = old_history['images']
		new_imagelist = data['images']
		if isinstance(new_imagelist[0], dict):
			new_imagelist = [el['href'] for el in new_imagelist]
		for image in old_imagelist:
			if image['href'] not in new_imagelist:
				i.deleteImageByFilename(image['href'])

	# Save new images and link in DB
	if 'newImages' in data:
		imagelist = data['newImages']
		resizeImages(imagelist)
		i.addImages(imagelist, id)

	#Publish twitter
	if old_history['twitter'] != data['twitter'] and data['twitter']:
		auth = tweepy.OAuthHandler(app.config['consumer_key'], app.config['consumer_secret'])
		auth.set_access_token(app.config['access_token'], app.config['access_token_secret'])
		apiTwitter = tweepy.API(auth)
		maxLength = 117
		if len(old_history["images"]) > 0:
			maxLength = 93

		maxLength -= (len(app.config['hashtag']) + 1)

		tweet = data["text_history"]
		if(len(tweet) > maxLength):
			maxLength -= 3
			tweet = tweet[0:maxLength]
			tweet += "..."

		tweet += app.config['baseURL'] + data["historyUrl"] + str(data["id_history"]) + " " + app.config['hashtag']

		if len(old_history["images"]) > 0:
			imageTwitter = app.config['IMAGES_FOLDER'] + old_history["images"][0]["href"]
			apiTwitter.update_with_media(imageTwitter,status=tweet)
		else:
			status = apiTwitter.update_status(status=tweet)

	# Send email to admins and author
	u = UserModel()
	user = u.getUserByUsername(data['username'])
	admins = u.getAllAdmins()
	if old_history['status'] == data['status']:
		for admin in admins:
			sendEditedHistoryNotification(admin, data)
		if not user['admin']:
			sendEditedHistoryNotification(user, data)
	else:
		for admin in admins:
			sendPublishedHistoryNotification(admin, data)
		if not user['admin']:
			sendPublishedHistoryNotification(user, data)

	return jsonify({'result': 'true'})