Mercurial > getan > getan
annotate getan/backend.py @ 401:a487535e7844
Adjusting starting datetime:
update_entry() now also updatest start and end time.
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Mon, 12 Sep 2016 11:06:46 +0200 |
parents | 90c09cca49c3 |
children | 59d9c5840273 |
rev | line source |
---|---|
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
2 # |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
3 # (c) 2008, 2009, 2010 by |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
4 # Sascha L. Teichmann <sascha.teichmann@intevation.de> |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
5 # Ingo Weinzierl <ingo.weinzierl@intevation.de> |
97
99639833968d
Add me as author in files that I did touch
Björn Ricks <bjoern.ricks@intevation.de>
parents:
68
diff
changeset
|
6 # (c) 2011 Björn Ricks <bjoern.ricks@intevation.de> |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
7 # |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
8 # This is Free Software licensed unter the terms of GPLv3 or later. |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
9 # For details see LICENSE coming with the source of 'getan'. |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
10 # |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
11 |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
12 import logging |
40
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
13 import os |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
14 |
33
f96a18c10836
Made getan python-2.4 compatible.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
23
diff
changeset
|
15 try: |
f96a18c10836
Made getan python-2.4 compatible.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
23
diff
changeset
|
16 import sqlite3 as db |
f96a18c10836
Made getan python-2.4 compatible.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
23
diff
changeset
|
17 except ImportError: |
f96a18c10836
Made getan python-2.4 compatible.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
23
diff
changeset
|
18 from pysqlite2 import dbapi2 as db |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
19 |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
20 from getan.project import Project, Entry |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
21 |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
22 DEFAULT_DATABASE = "time.db" |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
23 |
40
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
24 CREATE_TABLES = [ |
348
328ec66517b0
Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
284
diff
changeset
|
25 """ |
40
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
26 CREATE TABLE projects ( |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
27 id INTEGER PRIMARY KEY AUTOINCREMENT, |
284
561441fde2ac
Set unique constraint on project key
Björn Ricks <bjoern.ricks@intevation.de>
parents:
174
diff
changeset
|
28 key VARCHAR(16) NOT NULL CONSTRAINT unique_key UNIQUE, |
40
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
29 description VARCHAR(256), |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
30 active BOOLEAN DEFAULT 1 |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
31 ) |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
32 """, |
348
328ec66517b0
Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
284
diff
changeset
|
33 """ |
40
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
34 CREATE TABLE entries ( |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
35 id INTEGER PRIMARY KEY AUTOINCREMENT, |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
36 project_id INTEGER REFERENCES projects(id), |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
37 start_time TIMESTAMP NOT NULL, |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
38 stop_time TIMESTAMP NOT NULL, |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
39 description VARCHAR(256), |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
40 |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
41 CHECK (strftime('%s', start_time) <= strftime('%s', stop_time)) |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
42 ) |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
43 """ |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
44 ] |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
45 |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
46 LOAD_ACTIVE_PROJECTS = ''' |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
47 SELECT id, key, description, total |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
48 FROM projects LEFT JOIN |
144 | 49 (SELECT |
50 project_id, | |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
51 sum(strftime('%s', stop_time) - strftime('%s', start_time)) AS total |
144 | 52 FROM entries |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
53 GROUP BY project_id) ON project_id = id |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
54 WHERE active |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
55 ''' |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
56 |
351
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
57 LOAD_ACTIVE_PROJECT = ''' |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
58 SELECT id, key, description, total |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
59 FROM projects LEFT JOIN |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
60 (SELECT |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
61 project_id, |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
62 sum(strftime('%s', stop_time) - strftime('%s', start_time)) AS total |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
63 FROM entries |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
64 GROUP BY project_id) ON project_id = id |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
65 WHERE active and key = :project_id |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
66 ''' |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
67 |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
68 LOAD_PROJECT_ENTRIES = ''' |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
69 SELECT |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
70 id, |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
71 project_id, |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
72 start_time as "[timestamp]", |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
73 stop_time as "[timestamp]", |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
74 description |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
75 FROM |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
76 entries |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
77 WHERE |
350
f581752317fd
Correctly escape sql query
Björn Ricks <bjoern.ricks@intevation.de>
parents:
349
diff
changeset
|
78 project_id = :project_id |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
79 ORDER BY |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
80 id |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
81 DESC |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
82 ''' |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
83 |
351
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
84 LOAD_PROJECT_ENTRIES_YEAR = ''' |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
85 SELECT |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
86 id, |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
87 project_id, |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
88 start_time as "[timestamp]", |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
89 stop_time as "[timestamp]", |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
90 'no description' AS description |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
91 FROM entries |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
92 WHERE |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
93 project_id = :project_id AND |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
94 (description IS NULL or length(description) = 0) |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
95 GROUP BY round(julianday(start_time)) |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
96 UNION |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
97 SELECT |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
98 id, |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
99 project_id, |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
100 start_time as "[timestamp]", |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
101 stop_time as "[timestamp]", |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
102 description |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
103 FROM entries |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
104 WHERE |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
105 project_id = :project_id AND |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
106 (strftime('%Y', start_time) ) = :year AND |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
107 description IS NOT NULL AND length(description) > 0 |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
108 ''' |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
109 |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
110 LOAD_PROJECT_ENTRIES_WEEK = ''' |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
111 SELECT |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
112 id, |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
113 project_id, |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
114 start_time as "[timestamp]", |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
115 stop_time as "[timestamp]", |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
116 'no description' AS description |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
117 FROM entries |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
118 WHERE |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
119 project_id = :project_id AND |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
120 (strftime('%Y', start_time) ) = :year AND |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
121 (description IS NULL or length(description) = 0) |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
122 AND (strftime('%W', start_time) = :week |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
123 OR strftime('%W', stop_time) = :week) |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
124 GROUP BY round(julianday(start_time)) |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
125 UNION |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
126 SELECT |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
127 id, |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
128 project_id, |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
129 start_time as "[timestamp]", |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
130 stop_time as "[timestamp]", |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
131 description |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
132 FROM entries |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
133 WHERE |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
134 project_id = :project_id AND |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
135 (strftime('%Y', start_time) ) = :year AND |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
136 description IS NOT NULL AND length(description) > 0 |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
137 AND (strftime('%W', start_time) = :week |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
138 OR strftime('%W', stop_time) = :week) |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
139 ORDER BY start_time |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
140 ''' |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
141 |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
142 INSERT_PROJECT_ENTRY = ''' |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
143 INSERT INTO entries (project_id, start_time, stop_time, description) |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
144 VALUES(?,?,?,?) |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
145 ''' |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
146 |
49
062ce001abd1
add backend method to create new projects
Björn Ricks <bjoern.ricks@intevation.de>
parents:
40
diff
changeset
|
147 INSERT_PROJECT = ''' |
52
9cb57c37369a
fix insert new project sql statemenent and api
Björn Ricks <bjoern.ricks@intevation.de>
parents:
50
diff
changeset
|
148 INSERT INTO projects (key, description, active) VALUES (?,?,1) |
49
062ce001abd1
add backend method to create new projects
Björn Ricks <bjoern.ricks@intevation.de>
parents:
40
diff
changeset
|
149 ''' |
062ce001abd1
add backend method to create new projects
Björn Ricks <bjoern.ricks@intevation.de>
parents:
40
diff
changeset
|
150 |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
151 DELETE_PROJECT_ENTRY = 'DELETE FROM entries WHERE id = %i' |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
152 |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
153 MOVE_ENTRY = 'UPDATE entries SET project_id = ? WHERE id = ?' |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
154 |
401
a487535e7844
Adjusting starting datetime:
Bernhard Reiter <bernhard@intevation.de>
parents:
362
diff
changeset
|
155 UPDATE_ENTRY = ''' |
a487535e7844
Adjusting starting datetime:
Bernhard Reiter <bernhard@intevation.de>
parents:
362
diff
changeset
|
156 UPDATE entries |
a487535e7844
Adjusting starting datetime:
Bernhard Reiter <bernhard@intevation.de>
parents:
362
diff
changeset
|
157 SET description = ?, start_time = ?, stop_time = ? |
a487535e7844
Adjusting starting datetime:
Bernhard Reiter <bernhard@intevation.de>
parents:
362
diff
changeset
|
158 WHERE id = ? |
a487535e7844
Adjusting starting datetime:
Bernhard Reiter <bernhard@intevation.de>
parents:
362
diff
changeset
|
159 ''' |
68
a25dab413260
Add new method to update a description of an entry in the database backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
52
diff
changeset
|
160 |
401
a487535e7844
Adjusting starting datetime:
Bernhard Reiter <bernhard@intevation.de>
parents:
362
diff
changeset
|
161 UPDATE_PROJECT = 'UPDATE projects SET key = ?, description = ? WHERE id = ?' |
174
36b9f2d31810
Add backend method to update a project in the database
Björn Ricks <bjoern.ricks@intevation.de>
parents:
165
diff
changeset
|
162 |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
163 logger = logging.getLogger() |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
164 |
348
328ec66517b0
Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
284
diff
changeset
|
165 |
165
83ba64c9a51e
A project entry in the db must have a key
Björn Ricks <bjoern.ricks@intevation.de>
parents:
146
diff
changeset
|
166 class InvalidProjectKeyError(Exception): |
83ba64c9a51e
A project entry in the db must have a key
Björn Ricks <bjoern.ricks@intevation.de>
parents:
146
diff
changeset
|
167 pass |
83ba64c9a51e
A project entry in the db must have a key
Björn Ricks <bjoern.ricks@intevation.de>
parents:
146
diff
changeset
|
168 |
348
328ec66517b0
Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
284
diff
changeset
|
169 |
143
9f4da22fb1f1
Use new style class for backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
135
diff
changeset
|
170 class Backend(object): |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
171 |
348
328ec66517b0
Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
284
diff
changeset
|
172 def __init__(self, database=DEFAULT_DATABASE): |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
173 self.database = database |
40
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
174 self.ensure_exists() |
348
328ec66517b0
Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
284
diff
changeset
|
175 self.con = db.connect(database, |
328ec66517b0
Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
284
diff
changeset
|
176 detect_types=db.PARSE_DECLTYPES | |
328ec66517b0
Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
284
diff
changeset
|
177 db.PARSE_COLNAMES) |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
178 self.con.text_factory = lambda x: unicode(x, "utf-8", "ignore") |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
179 |
40
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
180 def ensure_exists(self): |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
181 """ Creates the database file if it does not exist. """ |
348
328ec66517b0
Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
284
diff
changeset
|
182 if os.path.isfile(self.database): |
328ec66517b0
Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
284
diff
changeset
|
183 return |
40
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
184 |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
185 con, cur = None, None |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
186 try: |
348
328ec66517b0
Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
284
diff
changeset
|
187 con = db.connect(self.database) |
40
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
188 cur = con.cursor() |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
189 try: |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
190 for sql in CREATE_TABLES: |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
191 cur.execute(sql) |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
192 con.commit() |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
193 except: |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
194 con.rollback() |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
195 raise |
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
196 finally: |
348
328ec66517b0
Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
284
diff
changeset
|
197 if cur: |
328ec66517b0
Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
284
diff
changeset
|
198 cur.close() |
328ec66517b0
Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
284
diff
changeset
|
199 if con: |
328ec66517b0
Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
284
diff
changeset
|
200 con.close() |
40
e4759cc8f5e7
Create database file if it does not exist.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
201 |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
202 def load_projects(self): |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
203 """ Loads active projects from database and returns them as array """ |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
204 logger.debug("load active projects from database.") |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
205 cur = None |
348
328ec66517b0
Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
284
diff
changeset
|
206 try: |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
207 cur = self.con.cursor() |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
208 cur.execute(LOAD_ACTIVE_PROJECTS) |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
209 |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
210 projects = [] |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
211 while True: |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
212 row = cur.fetchone() |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
213 |
135
ce707fbb9666
Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents:
97
diff
changeset
|
214 if not row: |
ce707fbb9666
Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents:
97
diff
changeset
|
215 break |
165
83ba64c9a51e
A project entry in the db must have a key
Björn Ricks <bjoern.ricks@intevation.de>
parents:
146
diff
changeset
|
216 # check key |
83ba64c9a51e
A project entry in the db must have a key
Björn Ricks <bjoern.ricks@intevation.de>
parents:
146
diff
changeset
|
217 if not row[1]: |
348
328ec66517b0
Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
284
diff
changeset
|
218 raise InvalidProjectKeyError("Project with id %s needs " |
328ec66517b0
Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
284
diff
changeset
|
219 "a key" % row[0]) |
353
5ded6192b85b
Pass the Backend to the Project constructor
Björn Ricks <bjoern.ricks@intevation.de>
parents:
351
diff
changeset
|
220 proj = Project(self, *row) |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
221 projects.append(proj) |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
222 |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
223 logger.info("found %i active projects." % len(projects)) |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
224 return projects |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
225 |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
226 finally: |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
227 close(cur) |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
228 |
351
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
229 def load_project(self, key): |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
230 logger.debug("load active projects from database.") |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
231 cur = None |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
232 try: |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
233 cur = self.con.cursor() |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
234 cur.execute(LOAD_ACTIVE_PROJECT, {"project_id": key}) |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
235 row = cur.fetchone() |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
236 if not row: |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
237 raise InvalidProjectKeyError("Project with key %s not " |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
238 "found." % key) |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
239 # check key |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
240 if not row[1]: |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
241 raise InvalidProjectKeyError("Project with id %s needs " |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
242 "a key" % row[0]) |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
243 return Project(self, *row) |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
244 |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
245 finally: |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
246 close(cur) |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
247 |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
248 def load_entries(self, project_id, year=None, week=None): |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
249 """ Loads all entries that belong to a specific project """ |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
250 logger.debug("load entries that belong to project %s" % project_id) |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
251 cur = None |
351
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
252 |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
253 if week and isinstance(week, int): |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
254 week = "%02d" % (week) |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
255 |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
256 try: |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
257 cur = self.con.cursor() |
351
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
258 |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
259 if year is None and week is None: |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
260 cur.execute(LOAD_PROJECT_ENTRIES, |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
261 {"project_id": project_id}) |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
262 elif week is None: |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
263 cur.execute(LOAD_PROJECT_ENTRIES_YEAR, |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
264 {'project_id': project_id, 'year': str(year)}) |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
265 else: |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
266 cur.execute(LOAD_PROJECT_ENTRIES_WEEK, |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
267 {'project_id': project_id, |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
268 'week': week, |
b5dc92631561
Allow to load one project and specific entries from the Backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
350
diff
changeset
|
269 'year': str(year)}) |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
270 |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
271 entries = [] |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
272 while True: |
146
bb70dde875fd
Always fail if an entry couldn't be loaded
Björn Ricks <bjoern.ricks@intevation.de>
parents:
144
diff
changeset
|
273 row = cur.fetchone() |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
274 |
146
bb70dde875fd
Always fail if an entry couldn't be loaded
Björn Ricks <bjoern.ricks@intevation.de>
parents:
144
diff
changeset
|
275 if not row: |
bb70dde875fd
Always fail if an entry couldn't be loaded
Björn Ricks <bjoern.ricks@intevation.de>
parents:
144
diff
changeset
|
276 break |
bb70dde875fd
Always fail if an entry couldn't be loaded
Björn Ricks <bjoern.ricks@intevation.de>
parents:
144
diff
changeset
|
277 entries.append(Entry(*row)) |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
278 |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
279 logger.debug("Found %i entries that belong to project '%i'" |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
280 % (len(entries), project_id)) |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
281 return entries |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
282 finally: |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
283 close(cur) |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
284 |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
285 def insert_project_entry(self, project, stop_time, desc): |
135
ce707fbb9666
Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents:
97
diff
changeset
|
286 if project is None: |
ce707fbb9666
Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents:
97
diff
changeset
|
287 return |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
288 cur = None |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
289 try: |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
290 cur = self.con.cursor() |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
291 cur.execute(INSERT_PROJECT_ENTRY, ( |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
292 project.id, project.start, stop_time, desc)) |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
293 self.con.commit() |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
294 logger.debug("Added new entry '%s' of project '%s' into db" |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
295 % (desc, project.desc)) |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
296 |
362
90c09cca49c3
Fix loading entries of a project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
353
diff
changeset
|
297 project.load_entries() |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
298 finally: |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
299 close(cur) |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
300 |
52
9cb57c37369a
fix insert new project sql statemenent and api
Björn Ricks <bjoern.ricks@intevation.de>
parents:
50
diff
changeset
|
301 def insert_project(self, key, description): |
9cb57c37369a
fix insert new project sql statemenent and api
Björn Ricks <bjoern.ricks@intevation.de>
parents:
50
diff
changeset
|
302 if key is None or description is None: |
49
062ce001abd1
add backend method to create new projects
Björn Ricks <bjoern.ricks@intevation.de>
parents:
40
diff
changeset
|
303 return |
062ce001abd1
add backend method to create new projects
Björn Ricks <bjoern.ricks@intevation.de>
parents:
40
diff
changeset
|
304 cur = None |
50
9dbb6ee443a4
don't forget to save before commit :-/
Björn Ricks <bjoern.ricks@intevation.de>
parents:
49
diff
changeset
|
305 try: |
49
062ce001abd1
add backend method to create new projects
Björn Ricks <bjoern.ricks@intevation.de>
parents:
40
diff
changeset
|
306 cur = self.con.cursor() |
52
9cb57c37369a
fix insert new project sql statemenent and api
Björn Ricks <bjoern.ricks@intevation.de>
parents:
50
diff
changeset
|
307 cur.execute(INSERT_PROJECT, (key, description)) |
49
062ce001abd1
add backend method to create new projects
Björn Ricks <bjoern.ricks@intevation.de>
parents:
40
diff
changeset
|
308 self.con.commit() |
52
9cb57c37369a
fix insert new project sql statemenent and api
Björn Ricks <bjoern.ricks@intevation.de>
parents:
50
diff
changeset
|
309 logger.debug("Added a new project '%s' into db" % description) |
50
9dbb6ee443a4
don't forget to save before commit :-/
Björn Ricks <bjoern.ricks@intevation.de>
parents:
49
diff
changeset
|
310 finally: |
9dbb6ee443a4
don't forget to save before commit :-/
Björn Ricks <bjoern.ricks@intevation.de>
parents:
49
diff
changeset
|
311 close(cur) |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
312 |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
313 def delete_entries(self, entries): |
135
ce707fbb9666
Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents:
97
diff
changeset
|
314 if entries is None: |
ce707fbb9666
Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents:
97
diff
changeset
|
315 return |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
316 |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
317 cur = None |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
318 try: |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
319 cur = self.con.cursor() |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
320 for entry in entries: |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
321 cur.execute(DELETE_PROJECT_ENTRY % entry.id) |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
322 logger.debug("Deleted entry: %s (%d)" % (entry.desc, entry.id)) |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
323 self.con.commit() |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
324 finally: |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
325 close(cur) |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
326 |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
327 def move_entries(self, entries, new_project_id): |
135
ce707fbb9666
Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents:
97
diff
changeset
|
328 if entries is None or new_project_id is None: |
ce707fbb9666
Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents:
97
diff
changeset
|
329 return |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
330 |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
331 cur = None |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
332 try: |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
333 cur = self.con.cursor() |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
334 for entry in entries: |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
335 cur.execute(MOVE_ENTRY, (new_project_id, entry.id)) |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
336 logger.debug("Moved entry '%s' (id=%d) to project with id %d." |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
337 % (entry.desc, entry.id, new_project_id)) |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
338 self.con.commit() |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
339 finally: |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
340 close(cur) |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
341 |
68
a25dab413260
Add new method to update a description of an entry in the database backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
52
diff
changeset
|
342 def update_entry(self, entry): |
a25dab413260
Add new method to update a description of an entry in the database backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
52
diff
changeset
|
343 if not entry: |
a25dab413260
Add new method to update a description of an entry in the database backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
52
diff
changeset
|
344 return |
a25dab413260
Add new method to update a description of an entry in the database backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
52
diff
changeset
|
345 |
a25dab413260
Add new method to update a description of an entry in the database backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
52
diff
changeset
|
346 cur = None |
a25dab413260
Add new method to update a description of an entry in the database backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
52
diff
changeset
|
347 try: |
a25dab413260
Add new method to update a description of an entry in the database backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
52
diff
changeset
|
348 cur = self.con.cursor() |
401
a487535e7844
Adjusting starting datetime:
Bernhard Reiter <bernhard@intevation.de>
parents:
362
diff
changeset
|
349 cur.execute(UPDATE_ENTRY, (entry.desc, entry.start, |
a487535e7844
Adjusting starting datetime:
Bernhard Reiter <bernhard@intevation.de>
parents:
362
diff
changeset
|
350 entry.end, entry.id)) |
68
a25dab413260
Add new method to update a description of an entry in the database backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
52
diff
changeset
|
351 self.con.commit() |
401
a487535e7844
Adjusting starting datetime:
Bernhard Reiter <bernhard@intevation.de>
parents:
362
diff
changeset
|
352 logger.debug("Updated entry to: '%s'" % (entry)) |
68
a25dab413260
Add new method to update a description of an entry in the database backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
52
diff
changeset
|
353 finally: |
a25dab413260
Add new method to update a description of an entry in the database backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
52
diff
changeset
|
354 close(cur) |
a25dab413260
Add new method to update a description of an entry in the database backend
Björn Ricks <bjoern.ricks@intevation.de>
parents:
52
diff
changeset
|
355 |
174
36b9f2d31810
Add backend method to update a project in the database
Björn Ricks <bjoern.ricks@intevation.de>
parents:
165
diff
changeset
|
356 def update_project(self, project): |
36b9f2d31810
Add backend method to update a project in the database
Björn Ricks <bjoern.ricks@intevation.de>
parents:
165
diff
changeset
|
357 if not project: |
36b9f2d31810
Add backend method to update a project in the database
Björn Ricks <bjoern.ricks@intevation.de>
parents:
165
diff
changeset
|
358 return |
36b9f2d31810
Add backend method to update a project in the database
Björn Ricks <bjoern.ricks@intevation.de>
parents:
165
diff
changeset
|
359 |
36b9f2d31810
Add backend method to update a project in the database
Björn Ricks <bjoern.ricks@intevation.de>
parents:
165
diff
changeset
|
360 cur = None |
36b9f2d31810
Add backend method to update a project in the database
Björn Ricks <bjoern.ricks@intevation.de>
parents:
165
diff
changeset
|
361 try: |
36b9f2d31810
Add backend method to update a project in the database
Björn Ricks <bjoern.ricks@intevation.de>
parents:
165
diff
changeset
|
362 cur = self.con.cursor() |
348
328ec66517b0
Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
284
diff
changeset
|
363 cur.execute( |
328ec66517b0
Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
284
diff
changeset
|
364 UPDATE_PROJECT, (project.key, project.desc, project.id)) |
174
36b9f2d31810
Add backend method to update a project in the database
Björn Ricks <bjoern.ricks@intevation.de>
parents:
165
diff
changeset
|
365 self.con.commit() |
36b9f2d31810
Add backend method to update a project in the database
Björn Ricks <bjoern.ricks@intevation.de>
parents:
165
diff
changeset
|
366 logger.debug("Updated project: (%d) %s %s" % (project.id, |
349
c97a4b6a6887
Fix textwidth <= 80
Björn Ricks <bjoern.ricks@intevation.de>
parents:
348
diff
changeset
|
367 project.key, |
c97a4b6a6887
Fix textwidth <= 80
Björn Ricks <bjoern.ricks@intevation.de>
parents:
348
diff
changeset
|
368 project.desc)) |
174
36b9f2d31810
Add backend method to update a project in the database
Björn Ricks <bjoern.ricks@intevation.de>
parents:
165
diff
changeset
|
369 finally: |
36b9f2d31810
Add backend method to update a project in the database
Björn Ricks <bjoern.ricks@intevation.de>
parents:
165
diff
changeset
|
370 close(cur) |
36b9f2d31810
Add backend method to update a project in the database
Björn Ricks <bjoern.ricks@intevation.de>
parents:
165
diff
changeset
|
371 |
348
328ec66517b0
Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
284
diff
changeset
|
372 |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
373 def close(cur): |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
374 """ This function closes a database cursor if it is existing """ |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
375 if cur: |
135
ce707fbb9666
Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents:
97
diff
changeset
|
376 try: |
ce707fbb9666
Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents:
97
diff
changeset
|
377 cur.close() |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
378 except: |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
379 logger.warn("could not close database cursor.") |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
380 |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
381 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: |