def index(cursor, config):
    current_row = cursor.execute("""
        SELECT 
            id,
            start_time,
            end_time, 
            description, 
            ROUND((COALESCE(end_time, strftime('%s', 'now')) - start_time) / CAST(3600 AS FLOAT), 2) AS hours
        FROM entry 
        WHERE start_time = (select max(start_time) from entry where sheet = 'default')
        """).fetchone()

    todays_tasks_rows = cursor.execute("""
        SELECT
            id, 
            start_time,
            end_time,
            description, 
            ROUND((COALESCE(end_time, strftime('%s', 'now')) - start_time) / CAST(3600 AS FLOAT), 2) AS hours
        FROM entry
        WHERE start_time > strftime('%s', strftime('%Y-%m-%d', 'now', 'localtime'), 'utc') AND sheet = 'default'
        ORDER BY start_time DESC
        """).fetchall()

    lookup_helper = ChiliprojectConnector(db = cursor)
    current = TimesheetRow.from_row(current_row)
    current.set_lookup_handler(lookup_helper)

    hours_total = 0
    todays_tasks = []
    for task_row in todays_tasks_rows:
        task = TimesheetRow.from_row(task_row)
        task.set_meta(
                    get_entry_meta(
                        cursor,
                        task.id
                    )
                )
        task.set_lookup_handler(lookup_helper)

        hours_total = hours_total + task.total_hours
        todays_tasks.append(task)

    template_name = "snapshot.html"
    try:
        template_name = config.get('template', 'snapshot')
    except (NoSectionError, NoOptionError):
        pass

    return render_template(template_name, 
            current = current,
            human_username = config.get('temp', 'human_name'),
            todays_tasks = todays_tasks,
            hours_total = hours_total
        )
Exemple #2
0
def index(cursor, config):
    current_row = cursor.execute("""
        SELECT 
            id,
            start_time,
            end_time, 
            description, 
            ROUND((COALESCE(end_time, strftime('%s', 'now')) - start_time) / CAST(3600 AS FLOAT), 2) AS hours
        FROM entry 
        WHERE start_time = (select max(start_time) from entry where sheet = 'default')
        """).fetchone()

    todays_tasks_rows = cursor.execute("""
        SELECT
            id, 
            start_time,
            end_time,
            description, 
            ROUND((COALESCE(end_time, strftime('%s', 'now')) - start_time) / CAST(3600 AS FLOAT), 2) AS hours
        FROM entry
        WHERE start_time > strftime('%s', strftime('%Y-%m-%d', 'now', 'localtime'), 'utc') AND sheet = 'default'
        ORDER BY start_time DESC
        """).fetchall()

    lookup_helper = ChiliprojectConnector(db=cursor)
    current = TimesheetRow.from_row(current_row)
    current.set_lookup_handler(lookup_helper)

    hours_total = 0
    todays_tasks = []
    for task_row in todays_tasks_rows:
        task = TimesheetRow.from_row(task_row)
        task.set_meta(get_entry_meta(cursor, task.id))
        task.set_lookup_handler(lookup_helper)

        hours_total = hours_total + task.total_hours
        todays_tasks.append(task)

    template_name = "snapshot.html"
    try:
        template_name = config.get('template', 'snapshot')
    except (NoSectionError, NoOptionError):
        pass

    return render_template(template_name,
                           current=current,
                           human_username=config.get('temp', 'human_name'),
                           todays_tasks=todays_tasks,
                           hours_total=hours_total)
Exemple #3
0
    def get_entries(self, day):
        self.db.execute("""
            SELECT
                id,
                start_time,
                COALESCE(end_time, STRFTIME('%s', 'now')) as end_time,
                description,
                ROUND(
                        (
                            COALESCE(end_time, strftime('%s', 'now'))
                            - start_time
                        )
                        / CAST(3600 AS FLOAT), 2
                    ) AS hours
            FROM
                entry
            WHERE
                start_time > STRFTIME('%s', ?, 'utc')
                AND
                start_time < STRFTIME('%s', ?, 'utc', '1 day')
                AND
                sheet = 'default'
            """, (day.strftime("%Y-%m-%d"), day.strftime("%Y-%m-%d"), ))
        results = self.db.fetchall()

        helper = ChiliprojectConnector(
                    self.db,
                    username=self.username,
                    password=self.password
                )

        final_results = []
        for result in results:
            entry = TimesheetRow.from_row(result)
            entry.set_lookup_handler(helper)
            entry.set_meta(
                        get_entry_meta(self.db, result[0])
                    )
            final_results.append(entry)
        return final_results
    def get_entries(self, day):
        self.db.execute("""
            SELECT
                id,
                start_time,
                COALESCE(end_time, STRFTIME('%s', 'now')) as end_time,
                description,
                ROUND(
                        (
                            COALESCE(end_time, strftime('%s', 'now'))
                            - start_time
                        )
                        / CAST(3600 AS FLOAT), 2
                    ) AS hours
            FROM
                entry
            WHERE
                start_time > STRFTIME('%s', ?, 'utc')
                AND
                start_time < STRFTIME('%s', ?, 'utc', '1 day')
                AND
                sheet = 'default'
            """, (day.strftime("%Y-%m-%d"), day.strftime("%Y-%m-%d"), ))
        results = self.db.fetchall()

        helper = ChiliprojectConnector(
                    self.db,
                    username=self.username,
                    password=self.password
                )

        final_results = []
        for result in results:
            entry = TimesheetRow.from_row(result)
            entry.set_lookup_handler(helper)
            entry.set_meta(
                        get_entry_meta(self.db, result[0])
                    )
            final_results.append(entry)
        return final_results