shopr

Check-in [4a0c02edd2]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add some logging
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:4a0c02edd21b7df9a7814e3cfb016bcbda54e854d25a08ceafdca32b3f1a30bd
User & Date: vandys 2019-06-27 17:20:58
Context
2019-07-13
16:35
Keep old state of R/G/Y toggles. Wake and refresh XHR once/minute to keep NAT alive. check-in: 9a6f41336a user: vandys tags: trunk
2019-06-27
17:20
Add some logging check-in: 4a0c02edd2 user: vandys tags: trunk
2019-06-26
16:23
Tune the repsonsive layout for that filter/create input text area check-in: d41d773bcf user: vandys tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to items.py.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
..
32
33
34
35
36
37
38












39
40
41
42
43
44
45
..
70
71
72
73
74
75
76


77
78
79
80
81
82
83
84

85
86
87
88
89
90
91
92
93
94
#
# items.py
#	Represent the items on a shopping list
#
import json, threading
import sqlite3
import pdb


class List(object):
    def __init__(self, approot, lid, isglob, name):
	self.approot = approot
	self.lid = lid
	self.isglob = isglob
	self.name = name
................................................................................

	c.close()
	db.close()

    # Return a DB connection
    def get_db(self):
	return sqlite3.connect(self.approot.dbname)













    # Allocate the next generational value for list state
    #
    # Since we release waiters on new versions of the list,
    #  be sure to put your changes in before rev'ing the
    #  generation counter.
    def next_gen(self):
................................................................................
	    # Don't share deleted
	    if i.deleted():
		continue
	    items.append(i.for_json())
	return res

    # Update idx for the given item


    def set_idx(self, iid, col):

	# Find this item ID
	l = self.items.get(iid)
	if l is None:
	    return False

	# Update item, which flags change to list

	l.assign(col)

	return True

    # Add an item to this list
    #
    # Return None on failure, else new Item
    def new_item(self, name):
	# No dups, please
	ln = name.lower()




|


>







 







>
>
>
>
>
>
>
>
>
>
>
>







 







>
>





|


>


|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
..
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
..
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#
# items.py
#	Represent the items on a shopping list
#
import json, threading, time
import sqlite3
import pdb


class List(object):
    def __init__(self, approot, lid, isglob, name):
	self.approot = approot
	self.lid = lid
	self.isglob = isglob
	self.name = name
................................................................................

	c.close()
	db.close()

    # Return a DB connection
    def get_db(self):
	return sqlite3.connect(self.approot.dbname)

    # Add a log event WRT this list
    # A specific item if @iid is not 0
    def log(self, uid, iid, msg):
	db = self.get_db()
	c = db.cursor()
	tm = time.time()
	c.execute("insert into logging values(NULL,?,?,?,?,?)",
	    (tm, uid, self.lid, iid, msg))
	db.commit()
	c.close()
	db.close()

    # Allocate the next generational value for list state
    #
    # Since we release waiters on new versions of the list,
    #  be sure to put your changes in before rev'ing the
    #  generation counter.
    def next_gen(self):
................................................................................
	    # Don't share deleted
	    if i.deleted():
		continue
	    items.append(i.for_json())
	return res

    # Update idx for the given item
    #
    # Return old index value, or None on error
    def set_idx(self, iid, col):

	# Find this item ID
	l = self.items.get(iid)
	if l is None:
	    return None

	# Update item, which flags change to list
	oval = l.idx
	l.assign(col)

	return oval

    # Add an item to this list
    #
    # Return None on failure, else new Item
    def new_item(self, name):
	# No dups, please
	ln = name.lower()

Changes to mkdb.sql.

21
22
23
24
25
26
27









create table items(
    iid integer primary key autoincrement,
    list integer,
    name text,
    idx integer,
    unique(list,name)
);
















>
>
>
>
>
>
>
>
>
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
create table items(
    iid integer primary key autoincrement,
    list integer,
    name text,
    idx integer,
    unique(list,name)
);

/* Logged events */
create table logging(
    tm real,
    who integer,
    lid integer,
    iid, integer,
    msg text
);

Changes to post.py.

55
56
57
58
59
60
61

62
63
64
	    if l is None:
		return True,self.send_error(404)

	    i = l.new_item(name)
	    if i is None:
		return True,self.send_error(400, "Item add failed")


	    return True,self.send_json({"ok": True})

	return False,None







>



55
56
57
58
59
60
61
62
63
64
65
	    if l is None:
		return True,self.send_error(404)

	    i = l.new_item(name)
	    if i is None:
		return True,self.send_error(400, "Item add failed")

	    l.log(self.uid, i.iid, "add")
	    return True,self.send_json({"ok": True})

	return False,None

Changes to put.py.

50
51
52
53
54
55
56
57


58
59
60
61
62
63

64
65
66
67
68
69
70
71
72
73
74

75
76
77
78
79
80
81
82
83
84
85

86
87
88
89
90
	    else:
		return True,self.send_error(400, "No such op")
	except:
	    return True,self.send_error(400, "Malformed JSON")

	# Update item, and churn the list
	if op == "idx":
	    if l.set_idx(iid, col):


		return True,self.send_json({"ok": True})
	    return True,self.send_error(400, "Bad item")

	# Delete item from this list
	if op == "del":
	    if l.del_item(iid):

		return True,self.send_json({"ok": True})
	    return True,self.send_error(400, "Bad item")

	# Change item's name
	if op == "rename":
	    i = l.items.get(iid)
	    if i is None:
		return True,self.send_error(400, "No such item")

	    # Just adjusting capitalization.  Since all comparisons
	    #  are case insensitive, this is always OK.

	    nl = name.lower()
	    if i.name.lower() != nl:

		# Can't name on top of another element
		for i2 in l.items.itervalues():
		    if i2.name.lower() == nl:
			return True,self.send_error(409, "Name exists")

	    # Our users see this change
	    i.name = name
	    l.next_gen()


	    return True,self.send_json({"ok": True})

	# "Can't Happen"
	return True,self.send_error(500)







|
>
>






>











>

|









>





50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
	    else:
		return True,self.send_error(400, "No such op")
	except:
	    return True,self.send_error(400, "Malformed JSON")

	# Update item, and churn the list
	if op == "idx":
	    oidx = l.set_idx(iid, col)
	    if oidx is not None:
		l.log(self.uid, iid, "idx %d -> %d" % (oidx, col))
		return True,self.send_json({"ok": True})
	    return True,self.send_error(400, "Bad item")

	# Delete item from this list
	if op == "del":
	    if l.del_item(iid):
		l.log(self.uid, iid, "del")
		return True,self.send_json({"ok": True})
	    return True,self.send_error(400, "Bad item")

	# Change item's name
	if op == "rename":
	    i = l.items.get(iid)
	    if i is None:
		return True,self.send_error(400, "No such item")

	    # Just adjusting capitalization.  Since all comparisons
	    #  are case insensitive, this is always OK.
	    oname = i.name
	    nl = name.lower()
	    if oname.lower() != nl:

		# Can't name on top of another element
		for i2 in l.items.itervalues():
		    if i2.name.lower() == nl:
			return True,self.send_error(409, "Name exists")

	    # Our users see this change
	    i.name = name
	    l.next_gen()
	    l.log(self.uid, iid, "rename %s -> %s" % (oname, name))

	    return True,self.send_json({"ok": True})

	# "Can't Happen"
	return True,self.send_error(500)