コード例 #1
0
ファイル: Generic.py プロジェクト: tayllan/anaddventure
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
ファイル: Tale.py プロジェクト: tayllan/anaddventure
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
ファイル: Tale.py プロジェクト: tayllan/anaddventure
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')
コード例 #4
0
ファイル: Generic.py プロジェクト: tayllan/anaddventure
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')
コード例 #5
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')
コード例 #6
0
ファイル: Collaboration.py プロジェクト: tayllan/anaddventure
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')
コード例 #7
0
ファイル: Collaboration.py プロジェクト: tayllan/anaddventure
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')