예제 #1
0
파일: aux.py 프로젝트: tayllan/anaddventure
def return_rendered_tale_template(
		tale, template, contributions_object = None,
		branches_object = None, contributors_object = None,
		genres_list = None, licenses_list = None,
		open_contribution_requests_list = None,
		closed_contribution_requests_list = None, contribution = None
	):
	this_user_gave_star = did_the_logged_user_give_star(tale['id'])
	this_user_is_following = did_the_logged_user_follow(tale['id'])

	tale_genres = Tale_Genre.select_by_tale_id(tale['id'])
	tale_genres_list = list()

	for tale_genre in tale_genres:
		genre = Genre.select_by_id(tale_genre[1], 1)[0]
		tale_genres_list.append(genre)

	tale['genres'] = tale_genres_list

	return render_template(
		template,
		creator = User.select_by_id(tale['creator_id'], 1)[0],
		tale = tale,
		license = License.select_by_id(tale['license_id'], 1)[0],
		contributions = contributions_object,
		branches = branches_object,
		contributors = contributors_object,
		this_user_gave_star = this_user_gave_star,
		this_user_is_following = this_user_is_following,
		genres = genres_list,
		licenses = licenses_list,
		open_contribution_requests = open_contribution_requests_list,
		closed_contribution_requests = closed_contribution_requests_list,
		contribution = contribution
	).encode('utf-8')
예제 #2
0
def search_tales():
	content = request.args.get('c', '')
	genre_id = int(request.args.get('g', -1))

	if len(content) < 3 and genre_id is -1:
		return render_template('bad_search.html', search_page = 'tales')

	sort_value = int(request.args.get('s', 1))
	user_logged_id = session.get('user_logged_id', None)
	tales = Tale.select_viewable_by_title_and_creator_id(
		content, user_logged_id
	) if genre_id is -1 else Tale.select_viewable_by_title_creator_id_and_genre_id(
		content, user_logged_id, genre_id
	)
	tales_per_genre = dict()
	tales_list = list()

	for tale in tales:
		tale_genres = Tale_Genre.select_by_tale_id(tale['id'])
		tale_genres_list = list()

		for tale_genre in tale_genres:
			genre = Genre.select_by_id(tale_genre[1], 1)[0]
			tale_genres_list.append(genre)

			if genre['type'] in tales_per_genre:
				tales_per_genre[genre['type']]['count'] += 1
			else:
				tales_per_genre[genre['type']] = {'count': 1, 'id': genre['id']}

		last_update = Tale.select_last_update(tale['id'], 1)[0][0]
		tale['genres'] = tale_genres_list
		tale['creator_username'] = User.select_by_id(tale['creator_id'], 1)[0]['username']
		tale['last_update'] = False if last_update is None else aux.beautify_datetime(last_update)
		tale['ugly_last_update'] = datetime(1, 1, 1, 15, 11) if last_update is None else last_update
		tales_list.append(tale)

	if sort_value is 2:
		tales_list = sorted(tales_list, key = lambda tale: tale['stars'], reverse = True)
	elif sort_value is 3:
		tales_list = sorted(tales_list, key = lambda tale: tale['stars'])
	elif sort_value is 4:
		tales_list = sorted(tales_list, key = lambda tale: tale['ugly_last_update'], reverse = True)
	elif sort_value is 5:
		tales_list = sorted(tales_list, key = lambda tale: tale['ugly_last_update'])

	return render_template(
		'search_tales.html',
		content = content,
		tales = tales_list,
		amount_of_tales = len(tales_list),
		tales_per_genre = tales_per_genre,
		sort_value = sort_value,
		genre_id = genre_id,
	)
예제 #3
0
def search_tales():
    content = request.args.get('c', '')
    genre_id = int(request.args.get('g', -1))

    if len(content) < 3 and genre_id is -1:
        return render_template('bad_search.html', search_page='tales')

    sort_value = int(request.args.get('s', 1))
    user_logged_id = session.get('user_logged_id', None)
    tales = Tale.select_viewable_by_title_and_creator_id(
        content, user_logged_id
    ) if genre_id is -1 else Tale.select_viewable_by_title_creator_id_and_genre_id(
        content, user_logged_id, genre_id)
    tales_per_genre = dict()
    tales_list = list()

    for tale in tales:
        tale_genres = Tale_Genre.select_by_tale_id(tale['id'])
        tale_genres_list = list()

        for tale_genre in tale_genres:
            genre = Genre.select_by_id(tale_genre[1], 1)[0]
            tale_genres_list.append(genre)

            if genre['type'] in tales_per_genre:
                tales_per_genre[genre['type']]['count'] += 1
            else:
                tales_per_genre[genre['type']] = {
                    'count': 1,
                    'id': genre['id']
                }

        last_update = Tale.select_last_update(tale['id'], 1)[0][0]
        tale['genres'] = tale_genres_list
        tale['creator_username'] = User.select_by_id(tale['creator_id'],
                                                     1)[0]['username']
        tale[
            'last_update'] = False if last_update is None else aux.beautify_datetime(
                last_update)
        tale['ugly_last_update'] = datetime(
            1, 1, 1, 15, 11) if last_update is None else last_update
        tales_list.append(tale)

    if sort_value is 2:
        tales_list = sorted(tales_list,
                            key=lambda tale: tale['stars'],
                            reverse=True)
    elif sort_value is 3:
        tales_list = sorted(tales_list, key=lambda tale: tale['stars'])
    elif sort_value is 4:
        tales_list = sorted(tales_list,
                            key=lambda tale: tale['ugly_last_update'],
                            reverse=True)
    elif sort_value is 5:
        tales_list = sorted(tales_list,
                            key=lambda tale: tale['ugly_last_update'])

    return render_template(
        'search_tales.html',
        content=content,
        tales=tales_list,
        amount_of_tales=len(tales_list),
        tales_per_genre=tales_per_genre,
        sort_value=sort_value,
        genre_id=genre_id,
    )