<commit_before>from controller import Controller
from flask import render_template, abort, session
from libshowoff import Show, Paginator
import os, re

class PageController(Controller):
    def render_themed(self, template, **options):
        template_path = os.path.join(self.app.config['THEME'], template)
        return render_template(template_path, **options)

    def image_info(self, album, filename, template='image.html'):
        show = Show(self.app, album)
        exifdir = os.path.join(self.app.config['CACHE_DIR'], album, 'exif')
        f = open(os.path.join(exifdir, filename + '.exif'))
        exif_array = f.readlines()
        f.close()

        return self.render_themed(template, album=album, filename=filename,
                                  exif=exif_array, show=show)

    def paginated_overview(self, album, page, files, endpoint, template):
        ext = re.compile(".jpg$", re.IGNORECASE)
        all_files = os.listdir(os.path.join(self.app.config['ALBUMS_DIR'], album))
        all_files = filter(ext.search, all_files)
        all_files.sort()

        p = Paginator(album, files, self.app.config['THUMBNAILS_PER_PAGE'], page, endpoint, template)
        return self.render_themed(template + '.html', album=album,
                                  files=p.entries, paginator=p, page=page,
                                  all_files=all_files)

    def get_show(self, album, page, endpoint, template):
        show = Show(self.app, album)

        if len(show.data['files']) == 0:
            abort(404)

        files = show.data['files']
        return self.paginated_overview(album, page, files, endpoint, template)

    def get_nonpaginated_show(self, album, template):
        show = Show(self.app, album)

        if len(show.data['files']) == 0:
            abort(404)

        files = show.data['files']

        return self.render_themed(template + '.html', album=album, files=files)
<commit_msg>check if .exif file exists; use Show in paginated_overview<commit_after>from controller import Controller
from flask import render_template, abort, session
from libshowoff import Show, Paginator
import os, re

class PageController(Controller):
    def render_themed(self, template, **options):
        template_path = os.path.join(self.app.config['THEME'], template)
        return render_template(template_path, **options)

    def image_info(self, album, filename, template='image.html'):
        show = Show(self.app, album)
        exifdir = os.path.join(self.app.config['CACHE_DIR'], album, 'exif')
        exif_array = []
        if os.path.exists(os.path.join(exifdir, filename + '.exif')):
            f = open(os.path.join(exifdir, filename + '.exif'))
            exif_array = f.readlines()
            f.close()

        return self.render_themed(template, album=album, filename=filename,
                                  exif=exif_array, show=show)

    def paginated_overview(self, album, show, page, files, endpoint, template):
        ext = re.compile(".jpg$", re.IGNORECASE)
        all_files = os.listdir(os.path.join(self.app.config['ALBUMS_DIR'], album))
        all_files = filter(ext.search, all_files)
        all_files.sort()

        p = Paginator(album, files, self.app.config['THUMBNAILS_PER_PAGE'], page, endpoint, template)
        return self.render_themed(template + '.html', album=album,
                                  show=show, files=p.entries, paginator=p, page=page,
                                  all_files=all_files)

    def get_show(self, album, page, endpoint, template):
        show = Show(self.app, album)

        if len(show.data['files']) == 0:
            abort(404)

        files = show.data['files']
        return self.paginated_overview(album, show, page, files, endpoint, template)

    def get_nonpaginated_show(self, album, template):
        show = Show(self.app, album)

        if len(show.data['files']) == 0:
            abort(404)

        files = show.data['files']

        return self.render_themed(template + '.html', album=album, files=files)

{'fraction_non_alphanumeric': 0.12543124691966487, 'fraction_numerical': 0.003942828979793002, 'mean_word_length': 2.723853211009174, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7563976', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1198, 'n_words': 268}