Exemplo n.º 1
0
def tale_edit_post(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]
		title = request.form.get('tale-edit-title', '')
		description = request.form.get('tale-edit-description', '')
		category = 2 if int(request.form.get('tale-edit-type', 1)) is not 1 else 1
		genres = request.form.getlist('tale-edit-genres')
		license_id = request.form.get('tale-edit-license', -1)
		creator_id = session['user_logged_id']
		language = session.get('language', 'en')

		error_list = list()

		if tale['title'] == title or Tale.is_title_available(creator_id, title):
			if not Tale.is_title_valid(title):
				error_list.append(strings.STRINGS[language]['INVALID_TITLE'])
		else:
			error_list.append(strings.STRINGS[language]['TITLE_TAKEN'])

		if not Tale.is_description_valid(description):
			error_list.append(strings.STRINGS[language]['INVALID_DESCRIPTION'])

		if not License.is_license_id_valid(license_id):
			error_list.append(strings.STRINGS[language]['INVALID_LICENSE'])

		if len(genres) is not 0:
			for genre_id in genres:
				if not Genre.is_genre_id_valid(genre_id):
					error_list.append(strings.STRINGS[language]['INVALID_GENRE'])
					break
		else:
			error_list.append(strings.STRINGS[language]['NO_GENRES'])

		if len(error_list) is not 0:
			return make_response(jsonify(error_list = error_list), 400)
		else:
			tale_last_category = int(tale['category'])

			if tale_last_category is not category:
				if tale_last_category is 1:
					contributors = Tale.select_contributors_id(tale_id)

					for contributor_id in contributors:
						new_invitation = Invitation(creator_id, contributor_id, tale_id)
						new_invitation.insert()
				else:
					Invitation.delete_by_tale_id(tale_id)

			Tale.update_all(tale_id, title, description, category, license_id)
			Tale_Genre.delete_by_tale_id(tale_id)

			for genre_id in genres:
				new_tale_genre = Tale_Genre(tale_id, genre_id)
				new_tale_genre.insert()

			return jsonify(url = '/tale/' + str(tale_id) + '/0')
	else:
		return redirect('/404')
Exemplo n.º 2
0
def tale_add_post():
    if request.is_xhr and 'user_logged_id' in session:
        title = request.form.get('tale-add-title', '')
        description = request.form.get('tale-add-description', '')
        category = 2 if int(request.form.get('tale-add-type',
                                             1)) is not 1 else 1
        genres = request.form.getlist('tale-add-genres')
        license_id = request.form.get('tale-add-license', -1)
        creator_id = session['user_logged_id']
        language = session.get('language', 'en')

        error_list = list()

        if Tale.is_title_available(creator_id, title):
            if not Tale.is_title_valid(title):
                error_list.append(strings.STRINGS[language]['INVALID_TITLE'])
        else:
            error_list.append(strings.STRINGS[language]['TITLE_TAKEN'])

        if not Tale.is_description_valid(description):
            error_list.append(strings.STRINGS[language]['INVALID_DESCRIPTION'])

        if not License.is_license_id_valid(license_id):
            error_list.append(strings.STRINGS[language]['INVALID_LICENSE'])

        if len(genres) is not 0:
            for genre_id in genres:
                if not Genre.is_genre_id_valid(genre_id):
                    error_list.append(
                        strings.STRINGS[language]['INVALID_GENRE'])
                    break
        else:
            error_list.append(strings.STRINGS[language]['NO_GENRES'])

        if len(error_list) is not 0:
            return make_response(jsonify(error_list=error_list), 400)
        else:
            new_tale = Tale(title, description, category, creator_id,
                            license_id, aux.get_current_datetime_as_string())
            new_tale.insert()

            tale_id = Tale.select_by_creator_id_and_full_title(
                creator_id, title, 1)[0]['id']

            for genre_id in genres:
                new_tale_genre = Tale_Genre(tale_id, genre_id)
                new_tale_genre.insert()

            if category is 2:
                invitation = Invitation(creator_id, creator_id, tale_id)
                invitation.insert()

            return jsonify(url='/tale/' + str(tale_id) + '/0')
    else:
        return redirect('/404')
Exemplo n.º 3
0
def tale_add_post():
	if request.is_xhr and 'user_logged_id' in session:
		title = request.form.get('tale-add-title', '')
		description = request.form.get('tale-add-description', '')
		category = 2 if int(request.form.get('tale-add-type', 1)) is  not 1 else 1
		genres = request.form.getlist('tale-add-genres')
		license_id = request.form.get('tale-add-license', -1)
		creator_id = session['user_logged_id']
		language = session.get('language', 'en')

		error_list = list()

		if Tale.is_title_available(creator_id, title):
			if not Tale.is_title_valid(title):
				error_list.append(strings.STRINGS[language]['INVALID_TITLE'])
		else:
			error_list.append(strings.STRINGS[language]['TITLE_TAKEN'])

		if not Tale.is_description_valid(description):
			error_list.append(strings.STRINGS[language]['INVALID_DESCRIPTION'])

		if not License.is_license_id_valid(license_id):
			error_list.append(strings.STRINGS[language]['INVALID_LICENSE'])

		if len(genres) is not 0:
			for genre_id in genres:
				if not Genre.is_genre_id_valid(genre_id):
					error_list.append(strings.STRINGS[language]['INVALID_GENRE'])
					break
		else:
			error_list.append(strings.STRINGS[language]['NO_GENRES'])

		if len(error_list) is not 0:
			return make_response(jsonify(error_list = error_list), 400)
		else:
			new_tale = Tale(title, description, category, creator_id, license_id, aux.get_current_datetime_as_string())
			new_tale.insert()

			tale_id = Tale.select_by_creator_id_and_full_title(creator_id, title, 1)[0]['id']

			for genre_id in genres:
				new_tale_genre = Tale_Genre(tale_id, genre_id)
				new_tale_genre.insert()

			if category is 2:
				invitation = Invitation(creator_id, creator_id, tale_id)
				invitation.insert()

			return jsonify(url = '/tale/' + str(tale_id) + '/0')
	else:
		return redirect('/404')
Exemplo n.º 4
0
def tale_edit_post(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]
        title = request.form.get('tale-edit-title', '')
        description = request.form.get('tale-edit-description', '')
        category = 2 if int(request.form.get('tale-edit-type',
                                             1)) is not 1 else 1
        genres = request.form.getlist('tale-edit-genres')
        license_id = request.form.get('tale-edit-license', -1)
        creator_id = session['user_logged_id']
        language = session.get('language', 'en')

        error_list = list()

        if tale['title'] == title or Tale.is_title_available(
                creator_id, title):
            if not Tale.is_title_valid(title):
                error_list.append(strings.STRINGS[language]['INVALID_TITLE'])
        else:
            error_list.append(strings.STRINGS[language]['TITLE_TAKEN'])

        if not Tale.is_description_valid(description):
            error_list.append(strings.STRINGS[language]['INVALID_DESCRIPTION'])

        if not License.is_license_id_valid(license_id):
            error_list.append(strings.STRINGS[language]['INVALID_LICENSE'])

        if len(genres) is not 0:
            for genre_id in genres:
                if not Genre.is_genre_id_valid(genre_id):
                    error_list.append(
                        strings.STRINGS[language]['INVALID_GENRE'])
                    break
        else:
            error_list.append(strings.STRINGS[language]['NO_GENRES'])

        if len(error_list) is not 0:
            return make_response(jsonify(error_list=error_list), 400)
        else:
            tale_last_category = int(tale['category'])

            if tale_last_category is not category:
                if tale_last_category is 1:
                    contributors = Tale.select_contributors_id(tale_id)

                    for contributor_id in contributors:
                        new_invitation = Invitation(creator_id, contributor_id,
                                                    tale_id)
                        new_invitation.insert()
                else:
                    Invitation.delete_by_tale_id(tale_id)

            Tale.update_all(tale_id, title, description, category, license_id)
            Tale_Genre.delete_by_tale_id(tale_id)

            for genre_id in genres:
                new_tale_genre = Tale_Genre(tale_id, genre_id)
                new_tale_genre.insert()

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