Beispiel #1
0
def files_action():

    data = []
    args = request.args
    pixel_ratio = 1
    models = FileModel.all().limit(240)

    for arg in args.keys():
        if arg == 'retina':
            val = args.get(arg)
            if val and val.lower() != 'false':
                pixel_ratio = 2
            continue
        vals = args.get(arg).split(',')
        if arg == 'device':
            models.add_filter(arg, {'in': vals})
        else:
            FilterHelper.apply_filter(arg, vals, models)

    ImageHelper().join_file_thumbnails(models, 'm.%s' % FileModel._pk,
                                       260 * pixel_ratio, 260 * pixel_ratio)
    ImageHelper().add_file_icons(models, 48 * pixel_ratio, 128 * pixel_ratio)
    for model in models:
        data.append(model.get_data())

    return jsonify({'files': data, 'sql': models.render()})
Beispiel #2
0
def files_action():

    data = []
    args = request.args
    pixel_ratio = 1
    models = FileModel.all().limit(240)

    for arg in args.keys():
        if arg == 'retina':
            val = args.get(arg)
            if val and val.lower() != 'false':
                pixel_ratio = 2
            continue
        vals = args.get(arg).split(',')
        if arg == 'device':
            models.add_filter(arg, {'in': vals})
        else:
            FilterHelper.apply_filter(arg, vals, models)

    ImageHelper().join_file_thumbnails(
        models,
        'm.%s' % FileModel._pk,
        260*pixel_ratio,
        260*pixel_ratio
    )
    ImageHelper().add_file_icons(models, 48*pixel_ratio, 128*pixel_ratio)
    for model in models:
        data.append(model.get_data())

    return jsonify({'files': data, 'sql': models.render()})
Beispiel #3
0
    def setUp(self):
        """FilterHelper test set up"""

        if os.path.isfile('/tmp/box.db'):
            os.unlink('/tmp/box.db')
        DBHelper().set_db('/tmp/box.db')
        InstallHelper.reset()
        FilterHelper.install()
Beispiel #4
0
    def setUp(self):
        """FilterHelper test set up"""

        if os.path.isfile('/tmp/box.db'):
            os.unlink('/tmp/box.db')
        DBHelper().set_db('/tmp/box.db')
        InstallHelper.reset()
        FilterHelper.install()
Beispiel #5
0
def file_filters_action():

    filters = FilterHelper.get_all_filters()

    device_opts = {}
    for device in DeviceModel.all():
        device_opts[device.id()] = device.product_name()
    if len(device_opts) > 1:
        filters.insert(0, {
            'label': 'Device',
            'multi': True,
            'param': 'device',
            'options': device_opts
        })

    return jsonify({'filters': filters})
Beispiel #6
0
def file_filters_action():

    filters = FilterHelper.get_all_filters()

    device_opts = {}
    for device in DeviceModel.all():
        device_opts[device.id()] = device.product_name()
    if len(device_opts) > 1:
        filters.insert(
            0, {
                'label': 'Device',
                'multi': True,
                'param': 'device',
                'options': device_opts
            })

    return jsonify({'filters': filters})
Beispiel #7
0
    def index_time_of_day():
        """Figure out time of day for files with timestamps"""

        FileTimeIndexer.install()

        filter_code = 'tod' # time-of-day
        FilterHelper.create_filter(filter_code, 'Time of Day')
        FilterHelper.add_filter_option(filter_code, 0, 'Morning')
        FilterHelper.add_filter_option(filter_code, 1, 'Noon')
        FilterHelper.add_filter_option(filter_code, 2, 'Afternoon')
        FilterHelper.add_filter_option(filter_code, 3, 'Evening')
        FilterHelper.add_filter_option(filter_code, 4, 'Night')

        time_select = FileTimeIndexer.get_time_attr_select()

        # join on value table to find not yet indexed files
        FilterHelper.join_filter_values(time_select, filter_code, 'tt.parent')
        time_select.where('fv.file IS NULL').limit(100)

        for time in time_select.query().fetchall():
            try:
                hour = int(datetime.fromtimestamp(time['value']).strftime('%H'))
                tod = 4 # Night
                if hour >= 5 and hour <= 10:
                    tod = 0 # Morning
                elif hour >= 11 and hour <= 13:
                    tod = 1 # Noon
                elif hour >= 14 and hour <= 17:
                    tod = 2 # Afternoon
                elif hour >= 18 and hour <= 21:
                    tod = 3 # Evening

                FilterHelper.set_filter_values(
                    time['parent'], filter_code, tod)
            except ValueError:
                pass # invalid format
Beispiel #8
0
    def index_seasons():
        """Figure out season for files with timestamps"""

        FileTimeIndexer.install()

        filter_code = 'season'
        FilterHelper.create_filter(filter_code, 'Season')
        FilterHelper.add_filter_option(filter_code, 0, 'Spring')
        FilterHelper.add_filter_option(filter_code, 1, 'Summer')
        FilterHelper.add_filter_option(filter_code, 2, 'Fall')
        FilterHelper.add_filter_option(filter_code, 3, 'Winter')

        time_select = FileTimeIndexer.get_time_attr_select()

        # join on value table to find not yet indexed files
        FilterHelper.join_filter_values(time_select, filter_code, 'tt.parent')
        time_select.where('fv.file IS NULL').limit(100)

        for time in time_select.query().fetchall():
            try:
                month = int(datetime.fromtimestamp(time['value']).strftime('%m'))
                shifted = (month - 3)%12 # makes march = 0, first month of spring
                FilterHelper.set_filter_values(
                    time['parent'], filter_code, shifted/3)
            except ValueError:
                pass # invalid format
Beispiel #9
0
    def install():
        """Install dependencies"""

        FileModel.install()
        FilterHelper.install()
Beispiel #10
0
    def test_filter(self):
        """Test FilterHelper functions"""

        # create a type filter
        type_filter = FilterHelper.create_filter('type', 'Type')
        FilterHelper.add_filter_option(type_filter, 1, 'Text')
        FilterHelper.add_filter_option(type_filter, 2, 'Audio')
        FilterHelper.add_filter_option(type_filter, 3, 'Image')

        # create a size filter
        size_filter = FilterHelper.create_filter('size', 'Size')
        FilterHelper.add_filter_option(size_filter, 1, 'Small')
        FilterHelper.add_filter_option(size_filter, 2, 'Medium')
        FilterHelper.add_filter_option(size_filter, 3, 'Large')

        f = FileModel({
            'name': 'textfile',
            'type': 'text',
            'size': '10'
        }).save()
        FilterHelper.set_filter_values(f, 'type', 1)
        FilterHelper.set_filter_values(f, 'size', 1)

        f = FileModel({
            'name': 'audiofile',
            'type': 'audio',
            'size': '100'
        }).save()
        FilterHelper.set_filter_values(f, 'type', 2)
        FilterHelper.set_filter_values(f, 'size', 2)

        f = FileModel({
            'name': 'hybridfile',
            'type': 'hybrid',
            'size': '1000'
        }).save()
        FilterHelper.set_filter_values(f, 'type', (1, 3))
        FilterHelper.set_filter_values(f, 'size', (2, 3))

        fileset = FileModel.all()
        FilterHelper.apply_filter('type', 1, fileset)

        # fileset should contain 'textfile' and 'hybridfile'
        self.assertEqual(len(fileset), 2)
        self.assertIn(fileset[0].name(), ('textfile', 'hybridfile'))
        self.assertIn(fileset[1].name(), ('textfile', 'hybridfile'))

        fileset = FileModel.all()
        FilterHelper.apply_filter('size', 2, fileset)

        # fileset should contain 'audiofile' and 'hybridfile'
        self.assertEqual(len(fileset), 2)
        self.assertIn(fileset[0].name(), ('audiofile', 'hybridfile'))
        self.assertIn(fileset[1].name(), ('audiofile', 'hybridfile'))

        fileset = FileModel.all()
        FilterHelper.apply_filter('type', 1, fileset)
        FilterHelper.apply_filter('size', 2, fileset)

        # fileset should only contain 'hybridfile'
        self.assertEqual(len(fileset), 1)
        self.assertEqual(fileset[0].name(), 'hybridfile')
Beispiel #11
0
    def index_time_of_day():
        """Figure out time of day for files with timestamps"""

        FileTimeIndexer.install()

        filter_code = 'tod'  # time-of-day
        FilterHelper.create_filter(filter_code, 'Time of Day')
        FilterHelper.add_filter_option(filter_code, 0, 'Morning')
        FilterHelper.add_filter_option(filter_code, 1, 'Noon')
        FilterHelper.add_filter_option(filter_code, 2, 'Afternoon')
        FilterHelper.add_filter_option(filter_code, 3, 'Evening')
        FilterHelper.add_filter_option(filter_code, 4, 'Night')

        time_select = FileTimeIndexer.get_time_attr_select()

        # join on value table to find not yet indexed files
        FilterHelper.join_filter_values(time_select, filter_code, 'tt.parent')
        time_select.where('fv.file IS NULL').limit(100)

        for time in time_select.query().fetchall():
            try:
                hour = int(
                    datetime.fromtimestamp(time['value']).strftime('%H'))
                tod = 4  # Night
                if hour >= 5 and hour <= 10:
                    tod = 0  # Morning
                elif hour >= 11 and hour <= 13:
                    tod = 1  # Noon
                elif hour >= 14 and hour <= 17:
                    tod = 2  # Afternoon
                elif hour >= 18 and hour <= 21:
                    tod = 3  # Evening

                FilterHelper.set_filter_values(time['parent'], filter_code,
                                               tod)
            except ValueError:
                pass  # invalid format
Beispiel #12
0
    def index_seasons():
        """Figure out season for files with timestamps"""

        FileTimeIndexer.install()

        filter_code = 'season'
        FilterHelper.create_filter(filter_code, 'Season')
        FilterHelper.add_filter_option(filter_code, 0, 'Spring')
        FilterHelper.add_filter_option(filter_code, 1, 'Summer')
        FilterHelper.add_filter_option(filter_code, 2, 'Fall')
        FilterHelper.add_filter_option(filter_code, 3, 'Winter')

        time_select = FileTimeIndexer.get_time_attr_select()

        # join on value table to find not yet indexed files
        FilterHelper.join_filter_values(time_select, filter_code, 'tt.parent')
        time_select.where('fv.file IS NULL').limit(100)

        for time in time_select.query().fetchall():
            try:
                month = int(
                    datetime.fromtimestamp(time['value']).strftime('%m'))
                shifted = (month -
                           3) % 12  # makes march = 0, first month of spring
                FilterHelper.set_filter_values(time['parent'], filter_code,
                                               shifted / 3)
            except ValueError:
                pass  # invalid format
Beispiel #13
0
    def install():
        """Install dependencies"""

        FileModel.install()
        FilterHelper.install()
Beispiel #14
0
from flask import Flask, render_template, request, jsonify, abort, Response
from helper.db import DBHelper, DBSelect
from helper.filter import FilterHelper
from helper.image import ImageHelper
from model.device import DeviceModel
from model.file import FileModel
import os

app = Flask(__name__)
app.debug = True

DBHelper('../../data/index.db')
ImageHelper('static/images', 'mint')
DeviceModel.install()
FileModel.install()
FilterHelper.install()

# Start page route
@app.route('/')
def index_action():
    return render_template('index.html')

@app.route('/files')
def files_action():

    data = []
    args = request.args
    pixel_ratio = 1
    models = FileModel.all().limit(240)

    for arg in args.keys():
Beispiel #15
0
from flask import Flask, render_template, request, jsonify, abort, Response
from helper.db import DBHelper, DBSelect
from helper.filter import FilterHelper
from helper.image import ImageHelper
from model.device import DeviceModel
from model.file import FileModel
import os

app = Flask(__name__)
app.debug = True

DBHelper('../../data/index.db')
ImageHelper('static/images', 'mint')
DeviceModel.install()
FileModel.install()
FilterHelper.install()


# Start page route
@app.route('/')
def index_action():
    return render_template('index.html')


@app.route('/files')
def files_action():

    data = []
    args = request.args
    pixel_ratio = 1
    models = FileModel.all().limit(240)
Beispiel #16
0
    def test_filter(self):
        """Test FilterHelper functions"""

        # create a type filter
        type_filter = FilterHelper.create_filter('type', 'Type')
        FilterHelper.add_filter_option(type_filter, 1, 'Text')
        FilterHelper.add_filter_option(type_filter, 2, 'Audio')
        FilterHelper.add_filter_option(type_filter, 3, 'Image')

        # create a size filter
        size_filter = FilterHelper.create_filter('size', 'Size')
        FilterHelper.add_filter_option(size_filter, 1, 'Small')
        FilterHelper.add_filter_option(size_filter, 2, 'Medium')
        FilterHelper.add_filter_option(size_filter, 3, 'Large')

        f = FileModel({
            'name': 'textfile',
            'type': 'text',
            'size': '10'
        }).save()
        FilterHelper.set_filter_values(f, 'type', 1)
        FilterHelper.set_filter_values(f, 'size', 1)

        f = FileModel({
            'name': 'audiofile',
            'type': 'audio',
            'size': '100'
        }).save()
        FilterHelper.set_filter_values(f, 'type', 2)
        FilterHelper.set_filter_values(f, 'size', 2)

        f = FileModel({
            'name': 'hybridfile',
            'type': 'hybrid',
            'size': '1000'
        }).save()
        FilterHelper.set_filter_values(f, 'type', (1, 3))
        FilterHelper.set_filter_values(f, 'size', (2, 3))

        fileset = FileModel.all()
        FilterHelper.apply_filter('type', 1, fileset)

        # fileset should contain 'textfile' and 'hybridfile'
        self.assertEqual(len(fileset), 2)
        self.assertIn(fileset[0].name(), ('textfile', 'hybridfile'))
        self.assertIn(fileset[1].name(), ('textfile', 'hybridfile'))

        fileset = FileModel.all()
        FilterHelper.apply_filter('size', 2, fileset)

        # fileset should contain 'audiofile' and 'hybridfile'
        self.assertEqual(len(fileset), 2)
        self.assertIn(fileset[0].name(), ('audiofile', 'hybridfile'))
        self.assertIn(fileset[1].name(), ('audiofile', 'hybridfile'))

        fileset = FileModel.all()
        FilterHelper.apply_filter('type', 1, fileset)
        FilterHelper.apply_filter('size', 2, fileset)

        # fileset should only contain 'hybridfile'
        self.assertEqual(len(fileset), 1)
        self.assertEqual(fileset[0].name(), 'hybridfile')