示例#1
0
def contribution_requests_refuse():
    contribution_request_id = request.form.get('contribution_request_id', -1)
    contribution_request = Contribution_Request.select_by_id(
        contribution_request_id, 1)

    if len(contribution_request) is not 0:
        contribution_request = contribution_request[0]
        tale = Tale.select_by_id(contribution_request['tale_id'], 1)[0]

        if tale['creator_id'] is session.get('user_logged_id', None):
            Contribution_Request.update_was_accepted(
                contribution_request['id'], False)
            Tale.update_contribution_request_count(
                contribution_request['tale_id'], -1)

            creator = User.select_by_id(tale['creator_id'], 1)[0]
            contributor = User.select_by_id(contribution_request['user_id'],
                                            1)[0]

            email_object = strings.construct_contribution_request_refused_email_object(
                session.get('language', 'en'), tale, creator, contributor,
                contribution_request['id'])

            aux.send_email_to_followers(tale['id'], email_object['title'],
                                        email_object['body'])

            return redirect('/tale/' + str(contribution_request['tale_id']) +
                            '/0')
        else:
            return redirect('/404')
    else:
        return redirect('/404')
示例#2
0
def tale_delete(tale_id):
    tale = Tale.select_by_id(tale_id, 1)

    if request.is_xhr and len(tale) is not 0 and session.get(
            'user_logged_id', None) is tale[0]['creator_id']:
        tale = tale[0]
        creator = User.select_by_id(tale['creator_id'], 1)[0]

        email_object = strings.construct_delete_tale_email_object(
            session.get('language', 'en'), tale, creator)

        aux.send_email_to_followers(tale['id'], email_object['title'],
                                    email_object['body'])

        Chapter.delete_by_tale_id(tale['id'])
        Contribution_Request.delete_by_tale_id(tale['id'])
        Follow.delete_by_tale_id(tale['id'])
        Invitation.delete_by_tale_id(tale['id'])
        Star.delete_by_tale_id(tale['id'])
        Tale_Genre.delete_by_tale_id(tale['id'])
        Tale.delete(tale['id'])

        return jsonify(url='/profile/' + creator['username'])
    else:
        redirect('/404')
示例#3
0
def contribution_requests(tale_id):
    tale = aux.is_visible_tale(tale_id, session.get('user_logged_id', None))

    if tale:
        o_c_r = Contribution_Request.select_open_by_tale_id_order_by_datetime(
            tale_id)
        for contribution_request in o_c_r:
            contribution_request['user_username'] = User.select_by_id(
                contribution_request['user_id'], 1)[0]['username']
            contribution_request['datetime'] = aux.beautify_datetime(
                contribution_request['datetime'])

        c_c_r = Contribution_Request.select_closed_by_tale_id_order_by_datetime(
            tale_id)
        for contribution_request in c_c_r:
            contribution_request['user_username'] = User.select_by_id(
                contribution_request['user_id'], 1)[0]['username']
            contribution_request['datetime'] = aux.beautify_datetime(
                contribution_request['datetime'])

        return aux.return_rendered_tale_template(
            tale,
            'contribution_requests.html',
            open_contribution_requests_list=o_c_r,
            closed_contribution_requests_list=c_c_r)
    else:
        return redirect('/404')
示例#4
0
def collaboration_edit_post(contribution_request_id):
	contribution_request = Contribution_Request.select_by_id(contribution_request_id, 1)

	if (request.is_xhr and len(contribution_request) is not 0 and
			session.get('user_logged_id', None) is contribution_request[0]['user_id'] and
			not contribution_request[0]['was_closed']):
		contribution_request = contribution_request[0]
		title = request.form.get('collaboration-edit-title', '')
		content = request.form.get('collaboration-edit-content', '')
		language = session.get('language', 'en')

		error_list = list()

		if not Contribution_Request.is_title_valid(title):
			error_list.append(strings.STRINGS[language]['INVALID_TITLE'])

		if not Contribution_Request.is_content_valid(content):
			error_list.append(strings.STRINGS[language]['INVALID_CONTENT'])

		if len(error_list) is not 0:
			return make_response(jsonify(error_list = error_list), 400)
		else:
			Contribution_Request.update_title_and_content(contribution_request_id, title, content)

			return jsonify(url = '/collaboration/' + str(contribution_request_id))
	else:
		return redirect('/404')
示例#5
0
def tale_delete(tale_id):
	tale = Tale.select_by_id(tale_id, 1)

	if request.is_xhr and len(tale) is not 0 and session.get('user_logged_id', None) is tale[0]['creator_id']:
		tale = tale[0]
		creator = User.select_by_id(tale['creator_id'], 1)[0]

		email_object = strings.construct_delete_tale_email_object(
			session.get('language', 'en'),
			tale,
			creator
		)

		aux.send_email_to_followers(tale['id'], email_object['title'], email_object['body'])

		Chapter.delete_by_tale_id(tale['id'])
		Contribution_Request.delete_by_tale_id(tale['id'])
		Follow.delete_by_tale_id(tale['id'])
		Invitation.delete_by_tale_id(tale['id'])
		Star.delete_by_tale_id(tale['id'])
		Tale_Genre.delete_by_tale_id(tale['id'])
		Tale.delete(tale['id'])

		return jsonify(url = '/profile/' + creator['username'])
	else:
		redirect('/404')
示例#6
0
def collaboration_edit_post(contribution_request_id):
    contribution_request = Contribution_Request.select_by_id(
        contribution_request_id, 1)

    if (request.is_xhr and len(contribution_request) is not 0 and session.get(
            'user_logged_id', None) is contribution_request[0]['user_id']
            and not contribution_request[0]['was_closed']):
        contribution_request = contribution_request[0]
        title = request.form.get('collaboration-edit-title', '')
        content = request.form.get('collaboration-edit-content', '')
        language = session.get('language', 'en')

        error_list = list()

        if not Contribution_Request.is_title_valid(title):
            error_list.append(strings.STRINGS[language]['INVALID_TITLE'])

        if not Contribution_Request.is_content_valid(content):
            error_list.append(strings.STRINGS[language]['INVALID_CONTENT'])

        if len(error_list) is not 0:
            return make_response(jsonify(error_list=error_list), 400)
        else:
            Contribution_Request.update_title_and_content(
                contribution_request_id, title, content)

            return jsonify(url='/collaboration/' +
                           str(contribution_request_id))
    else:
        return redirect('/404')
示例#7
0
def contribution_requests_refuse():
	contribution_request_id = request.form.get('contribution_request_id', -1)
	contribution_request = Contribution_Request.select_by_id(contribution_request_id, 1)

	if len(contribution_request) is not 0:
		contribution_request = contribution_request[0]
		tale = Tale.select_by_id(contribution_request['tale_id'], 1)[0]

		if tale['creator_id'] is session.get('user_logged_id', None):
			Contribution_Request.update_was_accepted(contribution_request['id'], False)
			Tale.update_contribution_request_count(contribution_request['tale_id'], -1)

			creator = User.select_by_id(tale['creator_id'], 1)[0]
			contributor = User.select_by_id(contribution_request['user_id'], 1)[0]

			email_object = strings.construct_contribution_request_refused_email_object(
				session.get('language', 'en'),
				tale,
				creator,
				contributor,
				contribution_request['id']
			)

			aux.send_email_to_followers(tale['id'], email_object['title'], email_object['body'])

			return redirect('/tale/' + str(contribution_request['tale_id']) + '/0')
		else:
			return redirect('/404')
	else:
		return redirect('/404')
示例#8
0
def collaboration_edit_get(contribution_request_id):
	contribution_request = Contribution_Request.select_by_id(contribution_request_id, 1)

	if (len(contribution_request) is not 0 and
			session.get('user_logged_id', None) is contribution_request[0]['user_id'] and
			not contribution_request[0]['was_closed']):
		return render_template('collaboration_edit.html', contribution_request = contribution_request[0])
	else:
		return redirect('/404')
示例#9
0
def collaboration_edit_get(contribution_request_id):
    contribution_request = Contribution_Request.select_by_id(
        contribution_request_id, 1)

    if (len(contribution_request) is not 0 and session.get(
            'user_logged_id', None) is contribution_request[0]['user_id']
            and not contribution_request[0]['was_closed']):
        return render_template('collaboration_edit.html',
                               contribution_request=contribution_request[0])
    else:
        return redirect('/404')
示例#10
0
def contribution_requests(tale_id):
	tale = aux.is_visible_tale(tale_id, session.get('user_logged_id', None))

	if tale:
		o_c_r = Contribution_Request.select_open_by_tale_id_order_by_datetime(tale_id)
		for contribution_request in o_c_r:
			contribution_request['user_username'] = User.select_by_id(contribution_request['user_id'], 1)[0]['username']
			contribution_request['datetime'] = aux.beautify_datetime(contribution_request['datetime'])

		c_c_r = Contribution_Request.select_closed_by_tale_id_order_by_datetime(tale_id)
		for contribution_request in c_c_r:
			contribution_request['user_username'] = User.select_by_id(contribution_request['user_id'], 1)[0]['username']
			contribution_request['datetime'] = aux.beautify_datetime(contribution_request['datetime'])

		return aux.return_rendered_tale_template(
			tale,
			'contribution_requests.html',
			open_contribution_requests_list = o_c_r,
			closed_contribution_requests_list = c_c_r
		)
	else:
		return redirect('/404')
示例#11
0
def chapter_edit_post(chapter_id):
	chapter = Chapter.select_by_id(chapter_id, 1)
	creator_id = session.get('user_logged_id', None)

	if request.is_xhr and len(chapter) is not 0 and creator_id is chapter[0]['user_id']:
		chapter = chapter[0]
		title = request.form.get('chapter-edit-title', '')
		content = request.form.get('chapter-edit-content', '')
		language = session.get('language', 'en')

		error_list = list()

		if not Contribution_Request.is_title_valid(title):
			error_list.append(strings.STRINGS[language]['INVALID_TITLE'])

		if not Contribution_Request.is_content_valid(content):
			error_list.append(strings.STRINGS[language]['INVALID_CONTENT'])

		if len(error_list) is not 0:
			return make_response(jsonify(error_list = error_list), 400)
		else:
			Chapter.update_title_and_content(chapter_id, title, content)
			tale = Tale.select_by_id(chapter['tale_id'], 1)[0]

			email_object = strings.construct_updated_chapter_email_object(
				language,
				tale,
				User.select_by_id(creator_id, 1)[0]['username'],
				chapter['number'],
				chapter['id']
			)

			aux.send_email_to_followers(tale['id'], email_object['title'], email_object['body'])

			return jsonify(url = '/tale/' + str(chapter['tale_id']) + '/' + str(chapter_id))
	else:
		return redirect('/404')
示例#12
0
def collaboration(contribution_request_id):
	contribution_request = Contribution_Request.select_by_id(contribution_request_id, 1)

	if len(contribution_request) is not 0:
		contribution_request = contribution_request[0]
		tale = aux.is_visible_tale(contribution_request['tale_id'], session.get('user_logged_id', None))

		if tale:
			contribution_request['user_username'] = User.select_by_id(
				contribution_request['user_id'],
				1
			)[0]['username']
			contribution_request['datetime'] = aux.beautify_datetime(contribution_request['datetime'])

			return aux.return_rendered_tale_template(tale, 'collaboration.html', contribution = contribution_request)
		else:
			return redirect('/404')
	else:
		return redirect('/404')
示例#13
0
def collaboration(contribution_request_id):
    contribution_request = Contribution_Request.select_by_id(
        contribution_request_id, 1)

    if len(contribution_request) is not 0:
        contribution_request = contribution_request[0]
        tale = aux.is_visible_tale(contribution_request['tale_id'],
                                   session.get('user_logged_id', None))

        if tale:
            contribution_request['user_username'] = User.select_by_id(
                contribution_request['user_id'], 1)[0]['username']
            contribution_request['datetime'] = aux.beautify_datetime(
                contribution_request['datetime'])

            return aux.return_rendered_tale_template(
                tale, 'collaboration.html', contribution=contribution_request)
        else:
            return redirect('/404')
    else:
        return redirect('/404')
示例#14
0
def collaboration_add_post(tale_id, chapter_id):
    tale = aux.is_visible_tale(tale_id, session.get('user_logged_id', None))
    chapter = Chapter.select_by_id(chapter_id, 1)

    if request.is_xhr and tale and 'user_logged_id' in session and (
        ((len(chapter) is not 0 and int(chapter[0]['tale_id']) is tale_id)) or
        (chapter_id is 0
         and len(Chapter.select_by_tale_id_and_previous_chapter_id(
             tale_id, -1)) is 0)):

        creator = tale['creator_id']
        user_id = session['user_logged_id']
        title = request.form.get('collaboration-add-title', '')
        content = request.form.get('collaboration-add-content', '')
        language = session.get('language', 'en')

        error_list = list()

        if not Contribution_Request.is_title_valid(title):
            error_list.append(strings.STRINGS[language]['INVALID_TITLE'])

        if not Contribution_Request.is_content_valid(content):
            error_list.append(strings.STRINGS[language]['INVALID_CONTENT'])

        if len(error_list) is not 0:
            return make_response(jsonify(error_list=error_list), 400)
        else:
            email_object = {}
            creator_username = User.select_by_id(user_id, 1)[0]['username']

            if creator is user_id:
                if chapter_id is 0:
                    new_chapter = Chapter(user_id, tale_id, 1, title, content,
                                          aux.get_current_datetime_as_string(),
                                          -1)
                    new_chapter.insert()

                    email_object = strings.construct_new_chapter_email_object(
                        language, tale, creator_username, 1, 0)
                else:
                    chapter = Chapter.select_by_id(chapter_id, 1)[0]
                    date = aux.get_current_datetime_as_string()
                    new_chapter = Chapter(user_id, tale_id,
                                          chapter['number'] + 1, title,
                                          content, date, chapter['id'])
                    new_chapter.insert()
                    new_chapter_id = Chapter.select_by_date(date, 1)[0]['id']

                    email_object = strings.construct_new_chapter_email_object(
                        language, tale, creator_username,
                        chapter['number'] + 1, new_chapter_id)
            else:
                chapter = Chapter.select_by_id(chapter_id, 1)[0]
                new_contribution_request = Contribution_Request(
                    user_id, tale_id, chapter['number'] + 1, title, content,
                    aux.get_current_datetime_as_string(), chapter['id'])
                new_contribution_request.insert()
                Tale.update_contribution_request_count(tale_id, 1)

                email_object = strings.construct_new_contribution_request_email_object(
                    language, tale, creator_username)

            aux.send_email_to_followers(tale_id, email_object['title'],
                                        email_object['body'])

            return jsonify(url='/tale/' + str(tale_id) + '/' + str(chapter_id))
    else:
        return redirect('/404')
示例#15
0
def collaboration_add_post(tale_id, chapter_id):
	tale = aux.is_visible_tale(tale_id, session.get('user_logged_id', None))
	chapter = Chapter.select_by_id(chapter_id, 1)

	if request.is_xhr and tale and 'user_logged_id' in session and (
		((len(chapter) is not 0 and int(chapter[0]['tale_id']) is tale_id)) or
		(chapter_id is 0 and len(Chapter.select_by_tale_id_and_previous_chapter_id(tale_id, -1)) is 0)):

		creator = tale['creator_id']
		user_id = session['user_logged_id']
		title = request.form.get('collaboration-add-title', '')
		content = request.form.get('collaboration-add-content', '')
		language = session.get('language', 'en')

		error_list = list()

		if not Contribution_Request.is_title_valid(title):
			error_list.append(strings.STRINGS[language]['INVALID_TITLE'])

		if not Contribution_Request.is_content_valid(content):
			error_list.append(strings.STRINGS[language]['INVALID_CONTENT'])

		if len(error_list) is not 0:
			return make_response(jsonify(error_list = error_list), 400)
		else:
			email_object = {}
			creator_username = User.select_by_id(user_id, 1)[0]['username']

			if creator is user_id:
				if chapter_id is 0:
					new_chapter = Chapter(
						user_id,
						tale_id,
						1,
						title,
						content,
						aux.get_current_datetime_as_string(),
						-1
					)
					new_chapter.insert()

					email_object = strings.construct_new_chapter_email_object(
						language,
						tale,
						creator_username,
						1,
						0
					)
				else:
					chapter = Chapter.select_by_id(chapter_id, 1)[0]
					date = aux.get_current_datetime_as_string()
					new_chapter = Chapter(
						user_id,
						tale_id,
						chapter['number'] + 1,
						title,
						content,
						date,
						chapter['id']
					)
					new_chapter.insert()
					new_chapter_id = Chapter.select_by_date(date, 1)[0]['id']

					email_object = strings.construct_new_chapter_email_object(
						language,
						tale,
						creator_username,
						chapter['number'] + 1,
						new_chapter_id
					)
			else:
				chapter = Chapter.select_by_id(chapter_id, 1)[0]
				new_contribution_request = Contribution_Request(
					user_id,
					tale_id,
					chapter['number'] + 1,
					title,
					content,
					aux.get_current_datetime_as_string(),
					chapter['id']
				)
				new_contribution_request.insert()
				Tale.update_contribution_request_count(tale_id, 1)

				email_object = strings.construct_new_contribution_request_email_object(
					language,
					tale,
					creator_username
				)

			aux.send_email_to_followers(tale_id, email_object['title'], email_object['body'])

			return jsonify(url = '/tale/' + str(tale_id) + '/' + str(chapter_id))
	else:
		return redirect('/404')