Exemplo n.º 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')
Exemplo n.º 2
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')
Exemplo n.º 3
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')
Exemplo n.º 4
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')