<commit_before>#! /usr/bin/env python
# -*- coding: UTF-8 -*-
#

from __future__ import absolute_import, unicode_literals, division

from datetime import date

from flask import (
    Blueprint, render_template, url_for, abort, request, redirect, flash
)
from flask_login import current_user, login_required

from oclubs.enums import UserType, ClubType, ActivityTime
from oclubs.shared import (
    get_callsign, special_access_required, Pagination, render_email_template,
    download_xlsx, partition
)
from oclubs.objs import User, Club, Activity, Upload, FormattedText
from oclubs.exceptions import UploadNotSupported, AlreadyExists, NoRow

actblueprint = Blueprint('actblueprint', __name__)


@actblueprint.route('/all_activities/<club_type>/<int:page>')
def allactivities(club_type, page):
    '''All Activities'''
    act_num = 20
    if club_type == 'all':
        count, acts = Activity.get_activities_conditions(
            limit=((page-1)*act_num, act_num))
    else:
        try:
            count, acts = Activity.get_activities_conditions(
                club_types=[ClubType[club_type.upper()]],
                limit=((page-1)*act_num, act_num))
        except KeyError:
            abort(404)
    pagination = Pagination(page, act_num, count)
    return render_template('activity/allact.html',
                           is_allact=True,
                           acts=acts,
                           club_type=club_type,
                           pagination=pagination)


@actblueprint.route('/<club>/club_activities/<int:page>')
@get_callsign(Club, 'club')
def clubactivities(club, page):
    '''One Club's Activities'''
    act_num = 20
    acts = club.activities()

    pagination = Pagination(page, act_num, len(acts))
    acts = acts[(page-1)*act_num: page*act_num]
    club_pic = []
    club_pic.extend(club.allactphotos(limit=3)[1])
    club_pic.extend([Upload(-101) for _ in range(3 - len(club_pic))])
    return render_template('activity/clubact.html',
                           club_pic=club_pic,
                           acts=acts,
                           pagination=pagination)


@actblueprint.route('/photos/<int:page>')
def allphotos(page):
    pic_num = 20
    count, acts = Activity.get_activities_conditions(
        require_photos=True,
        limit=((page-1)*pic_num, pic_num))
    act_recent = ''
    if page == 1:
        try:
            act_recent = acts[0]
        except IndexError:
            pass
    pagination = Pagination(page, pic_num, count)
    return render_template('activity/photos.html',
                           is_photos=True,
                           act_recent=act_recent,
                           acts=acts,
                           pagination=pagination)


@actblueprint.route('/<club>/club_photo/<int:page>')
@get_callsign(Club, 'club')
def clubphoto(club, page):<commit_msg>redundancy modified<commit_after>#! /usr/bin/env python
# -*- coding: UTF-8 -*-
#

from __future__ import absolute_import, unicode_literals, division

from datetime import date

from flask import (
    Blueprint, render_template, url_for, abort, request, redirect, flash
)
from flask_login import current_user, login_required

from oclubs.enums import UserType, ClubType, ActivityTime
from oclubs.shared import (
    get_callsign, special_access_required, Pagination, render_email_template,
    download_xlsx, partition
)
from oclubs.objs import User, Club, Activity, Upload, FormattedText
from oclubs.exceptions import UploadNotSupported, AlreadyExists, NoRow

actblueprint = Blueprint('actblueprint', __name__)


@actblueprint.route('/all_activities/<club_type>/<int:page>')
def allactivities(club_type, page):
    '''All Activities'''
    act_num = 20
    if club_type == 'all':
        count, acts = Activity.get_activities_conditions(
            limit=((page-1)*act_num, act_num))
    else:
        try:
            count, acts = Activity.get_activities_conditions(
                club_types=[ClubType[club_type.upper()]],
                limit=((page-1)*act_num, act_num))
        except KeyError:
            abort(404)
    pagination = Pagination(page, act_num, count)
    return render_template('activity/allact.html',
                           is_allact=True,
                           acts=acts,
                           club_type=club_type,
                           pagination=pagination)


@actblueprint.route('/<club>/club_activities/<int:page>')
@get_callsign(Club, 'club')
def clubactivities(club, page):
    '''One Club's Activities'''
    act_num = 20
    acts = club.activities()

    pagination = Pagination(page, act_num, len(acts))
    acts = acts[(page-1)*act_num: page*act_num]
    club_pic = []
    club_pic.extend(club.allactphotos(limit=3)[1])
    club_pic.extend([Upload(-101) for _ in range(3 - len(club_pic))])
    return render_template('activity/clubact.html',
                           club_pic=club_pic,
                           acts=acts,
                           pagination=pagination)


@actblueprint.route('/photos/<int:page>')
def allphotos(page):
    pic_num = 20
    count, acts = Activity.get_activities_conditions(
        require_photos=True,
        limit=((page-1)*pic_num, pic_num))
    if page == 1:
        try:
            act_recent = acts[0]
        except IndexError:
            act_recent = ''
    pagination = Pagination(page, pic_num, count)
    return render_template('activity/photos.html',
                           is_photos=True,
                           act_recent=act_recent,
                           acts=acts,
                           pagination=pagination)


@actblueprint.route('/<club>/club_photo/<int:page>')
@get_callsign(Club, 'club')
def clubphoto(club, page):
{'fraction_non_alphanumeric': 0.11070239971974076, 'fraction_numerical': 0.007707129094412331, 'mean_word_length': 2.5844318895166354, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5265879', 'n_tokens_mistral': 1791, 'n_tokens_neox': 1706, 'n_words': 335}