Merge lp:~sil/desktopcouch/urllibquote into lp:desktopcouch

Proposed by Stuart Langridge
Status: Rejected
Rejected by: Elliot Murphy
Proposed branch: lp:~sil/desktopcouch/urllibquote
Merge into: lp:desktopcouch
Diff against target: None lines
To merge this branch: bzr merge lp:~sil/desktopcouch/urllibquote
Reviewer Review Type Date Requested Status
Elliot Murphy (community) Approve
dobey (community) Needs Fixing
Joshua Blount (community) Approve
Review via email: mp+9778@code.launchpad.net

Commit message

Don't create a view per record-type; instead, call the standard return-all-records-keyed-by-record-type and use slice notation on the viewresults to only get back the records with that type, which does the same thing but more elegantly.

To post a comment you must log in.
Revision history for this message
Stuart Langridge (sil) wrote :

Don't create a view per record-type; instead, call the standard return-all-records-keyed-by-record-type and use slice notation on the viewresults to only get back the records with that type, which does the same thing but more elegantly.

Revision history for this message
Joshua Blount (jblount) wrote :

That, is a handsome branch. Well done sir, well done.

review: Approve
Revision history for this message
dobey (dobey) wrote :

+#from twisted.trial.unittest import TestCase as TwistedTestCase

Not sure why this was added as a commented line. Should be removed probably.

review: Needs Fixing
Revision history for this message
Elliot Murphy (statik) wrote :

i'd like this to land now, and i'll submit another branch removing the two commented out lines.

review: Approve
Revision history for this message
Elliot Murphy (statik) wrote :

text conflict in desktopcouch/records/tests/test_server.py

Revision history for this message
Elliot Murphy (statik) wrote :

text conflict in desktopcouch/records/tests/test_server.py

Revision history for this message
Elliot Murphy (statik) wrote :

> text conflict in desktopcouch/records/tests/test_server.py

Since I can't fix the conflict in this branch directly, I am rejecting this branch, and pushing my own copy of it with the merge conflict resolved.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'desktopcouch/records/couchwidget.py'
2--- desktopcouch/records/couchwidget.py 2009-07-24 16:54:41 +0000
3+++ desktopcouch/records/couchwidget.py 2009-08-05 14:46:06 +0000
4@@ -68,7 +68,7 @@
5 def headings(self, headings):
6 self.__headings = headings
7 if self.record_type != None:
8- self.set_record_type(self.record_type)
9+ self.__populate_treeview()(self.record_type)
10
11 @property
12 def editable(self):
13@@ -85,7 +85,7 @@
14
15 #refresh the treeview if possible
16 if self.record_type != None:
17- self.set_record_type(self.record_type)
18+ self.__populate_treeview()(self.record_type)
19
20 @property
21 def database(self):
22@@ -100,7 +100,7 @@
23 self.__db = CouchDatabase(db_name, create=True)
24
25 if self.record_type != None:
26- self.set_record_type(self.record_type)
27+ self.__populate_treeview()(self.record_type)
28
29 @property
30 def record_type(self):
31@@ -116,7 +116,9 @@
32
33 #store the record type string
34 self.__record_type = record_type
35+ self.__populate_treeview()
36
37+ def __populate_treeview(self):
38 #if the database is not set up, just return
39 if self.__db == None:
40 return
41@@ -125,8 +127,7 @@
42 self.__reset_model()
43
44 #retrieve the docs for the record_type, if any
45- filter = """function(doc) { if (doc.record_type == '%s') { emit(doc._id, doc); } }""" %record_type
46- results = self.__db.query(filter)
47+ results = self.__db.get_records(record_type=self.__record_type,create_view=True)
48
49 #if headings are already assigned, set up headings and columns
50 if self.headings != None:
51
52=== modified file 'desktopcouch/records/server.py'
53--- desktopcouch/records/server.py 2009-07-30 15:57:52 +0000
54+++ desktopcouch/records/server.py 2009-08-06 16:30:57 +0000
55@@ -21,11 +21,12 @@
56
57 """The Desktop Couch Records API."""
58
59+import urllib
60 from couchdb import Server
61 from couchdb.client import ResourceNotFound, ResourceConflict
62 from couchdb.design import ViewDefinition
63 import desktopcouch
64-from desktopcouch.records.record import Record
65+from record import Record
66
67
68 #DEFAULT_DESIGN_DOCUMENT = "design"
69@@ -208,17 +209,19 @@
70 except KeyError:
71 return []
72
73- def get_records_and_type(self, create_view=False,
74+ def get_records(self, record_type=None, create_view=False,
75 design_doc=DEFAULT_DESIGN_DOCUMENT):
76 """A convenience function to get records. We optionally create a view
77 in the design document. C<create_view> may be True or False, and a
78 special value, None, is analogous to O_EXCL|O_CREAT .
79-
80- Use the view to return *all* records. If there is no view to use or we
81- insist on creating a new view and cannot, raise KeyError .
82-
83- Use index notation on the result to get rows with a particular record
84- type.
85+
86+ Set record_type to a string to retrieve records of only that
87+ specified type. Otherwise, usse the view to return *all* records.
88+ If there is no view to use or we insist on creating a new view
89+ and cannot, raise KeyError .
90+
91+ You can use index notation on the result to get rows with a
92+ particular record type.
93 =>> results = get_records_and_type()
94 =>> for foo_document in results["foo"]:
95 ... print foo_document
96@@ -244,5 +247,10 @@
97
98 if not exists:
99 self.add_view(view_name, view_map_js, None, design_doc)
100+
101+ viewdata = self.execute_view(view_name, design_doc)
102+ if record_type is None:
103+ return viewdata
104+ else:
105+ return viewdata[record_type]
106
107- return self.execute_view(view_name, design_doc)
108
109=== modified file 'desktopcouch/records/tests/test_server.py' (properties changed: -x to +x)
110--- desktopcouch/records/tests/test_server.py 2009-07-30 15:57:52 +0000
111+++ desktopcouch/records/tests/test_server.py 2009-08-06 08:08:16 +0000
112@@ -16,9 +16,11 @@
113 #
114 # Authors: Eric Casteleijn <eric.casteleijn@canonical.com>
115
116-"""testing database/contact.py module"""
117-
118-import testtools, utils
119+"""testing records/server.py module"""
120+
121+#from twisted.trial.unittest import TestCase as TwistedTestCase
122+
123+import testtools
124
125 from desktopcouch.records.server import CouchDatabase
126 from desktopcouch.records.record import Record
127@@ -41,10 +43,22 @@
128 self.dbname = self._testMethodName
129 self.database = CouchDatabase(self.dbname, create=True)
130
131+ #create some records to pull out and test
132+ self.database.put_record(Record({"key1_1":"val1_1","key1_2":"val1_2","key1_3":"val1_3","record_type":"test.com"}))
133+ self.database.put_record(Record({"key2_1":"val2_1","key2_2":"val2_2","key2_3":"val2_3","record_type":"test.com"}))
134+ self.database.put_record(Record({"key13_1":"va31_1","key3_2":"val3_2","key3_3":"val3_3","record_type":"test.com"}))
135+
136 def tearDown(self):
137 """tear down each test"""
138 del self.database._server[self.dbname]
139
140+ def test_get_records_by_record_type_save_view(self):
141+ """Test getting mutliple records by type"""
142+ records = self.database.get_records(record_type="test.com",create_view=True)
143+ self.assertEqual(3,len(records))
144+
145+ #def test_get_all_records()
146+
147 def test_get_record(self):
148 """Test getting a record."""
149 record = Record({'record_number': 0}, record_type="http://example.com/")

Subscribers

People subscribed via source and target branches