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
=== modified file 'desktopcouch/records/couchwidget.py'
--- desktopcouch/records/couchwidget.py 2009-07-24 16:54:41 +0000
+++ desktopcouch/records/couchwidget.py 2009-08-05 14:46:06 +0000
@@ -68,7 +68,7 @@
68 def headings(self, headings):68 def headings(self, headings):
69 self.__headings = headings69 self.__headings = headings
70 if self.record_type != None:70 if self.record_type != None:
71 self.set_record_type(self.record_type)71 self.__populate_treeview()(self.record_type)
7272
73 @property73 @property
74 def editable(self):74 def editable(self):
@@ -85,7 +85,7 @@
8585
86 #refresh the treeview if possible86 #refresh the treeview if possible
87 if self.record_type != None:87 if self.record_type != None:
88 self.set_record_type(self.record_type)88 self.__populate_treeview()(self.record_type)
8989
90 @property90 @property
91 def database(self):91 def database(self):
@@ -100,7 +100,7 @@
100 self.__db = CouchDatabase(db_name, create=True)100 self.__db = CouchDatabase(db_name, create=True)
101101
102 if self.record_type != None:102 if self.record_type != None:
103 self.set_record_type(self.record_type)103 self.__populate_treeview()(self.record_type)
104104
105 @property105 @property
106 def record_type(self):106 def record_type(self):
@@ -116,7 +116,9 @@
116116
117 #store the record type string117 #store the record type string
118 self.__record_type = record_type118 self.__record_type = record_type
119 self.__populate_treeview()
119120
121 def __populate_treeview(self):
120 #if the database is not set up, just return122 #if the database is not set up, just return
121 if self.__db == None:123 if self.__db == None:
122 return124 return
@@ -125,8 +127,7 @@
125 self.__reset_model()127 self.__reset_model()
126128
127 #retrieve the docs for the record_type, if any129 #retrieve the docs for the record_type, if any
128 filter = """function(doc) { if (doc.record_type == '%s') { emit(doc._id, doc); } }""" %record_type130 results = self.__db.get_records(record_type=self.__record_type,create_view=True)
129 results = self.__db.query(filter)
130131
131 #if headings are already assigned, set up headings and columns132 #if headings are already assigned, set up headings and columns
132 if self.headings != None:133 if self.headings != None:
133134
=== modified file 'desktopcouch/records/server.py'
--- desktopcouch/records/server.py 2009-07-30 15:57:52 +0000
+++ desktopcouch/records/server.py 2009-08-06 16:30:57 +0000
@@ -21,11 +21,12 @@
2121
22"""The Desktop Couch Records API."""22"""The Desktop Couch Records API."""
2323
24import urllib
24from couchdb import Server25from couchdb import Server
25from couchdb.client import ResourceNotFound, ResourceConflict26from couchdb.client import ResourceNotFound, ResourceConflict
26from couchdb.design import ViewDefinition27from couchdb.design import ViewDefinition
27import desktopcouch28import desktopcouch
28from desktopcouch.records.record import Record29from record import Record
2930
3031
31#DEFAULT_DESIGN_DOCUMENT = "design"32#DEFAULT_DESIGN_DOCUMENT = "design"
@@ -208,17 +209,19 @@
208 except KeyError:209 except KeyError:
209 return []210 return []
210211
211 def get_records_and_type(self, create_view=False,212 def get_records(self, record_type=None, create_view=False,
212 design_doc=DEFAULT_DESIGN_DOCUMENT):213 design_doc=DEFAULT_DESIGN_DOCUMENT):
213 """A convenience function to get records. We optionally create a view214 """A convenience function to get records. We optionally create a view
214 in the design document. C<create_view> may be True or False, and a215 in the design document. C<create_view> may be True or False, and a
215 special value, None, is analogous to O_EXCL|O_CREAT .216 special value, None, is analogous to O_EXCL|O_CREAT .
216 217
217 Use the view to return *all* records. If there is no view to use or we218 Set record_type to a string to retrieve records of only that
218 insist on creating a new view and cannot, raise KeyError .219 specified type. Otherwise, usse the view to return *all* records.
219220 If there is no view to use or we insist on creating a new view
220 Use index notation on the result to get rows with a particular record221 and cannot, raise KeyError .
221 type.222
223 You can use index notation on the result to get rows with a
224 particular record type.
222 =>> results = get_records_and_type()225 =>> results = get_records_and_type()
223 =>> for foo_document in results["foo"]:226 =>> for foo_document in results["foo"]:
224 ... print foo_document227 ... print foo_document
@@ -244,5 +247,10 @@
244247
245 if not exists:248 if not exists:
246 self.add_view(view_name, view_map_js, None, design_doc)249 self.add_view(view_name, view_map_js, None, design_doc)
250
251 viewdata = self.execute_view(view_name, design_doc)
252 if record_type is None:
253 return viewdata
254 else:
255 return viewdata[record_type]
247256
248 return self.execute_view(view_name, design_doc)
249257
=== modified file 'desktopcouch/records/tests/test_server.py' (properties changed: -x to +x)
--- desktopcouch/records/tests/test_server.py 2009-07-30 15:57:52 +0000
+++ desktopcouch/records/tests/test_server.py 2009-08-06 08:08:16 +0000
@@ -16,9 +16,11 @@
16#16#
17# Authors: Eric Casteleijn <eric.casteleijn@canonical.com>17# Authors: Eric Casteleijn <eric.casteleijn@canonical.com>
1818
19"""testing database/contact.py module"""19"""testing records/server.py module"""
2020
21import testtools, utils21#from twisted.trial.unittest import TestCase as TwistedTestCase
22
23import testtools
2224
23from desktopcouch.records.server import CouchDatabase25from desktopcouch.records.server import CouchDatabase
24from desktopcouch.records.record import Record26from desktopcouch.records.record import Record
@@ -41,10 +43,22 @@
41 self.dbname = self._testMethodName43 self.dbname = self._testMethodName
42 self.database = CouchDatabase(self.dbname, create=True)44 self.database = CouchDatabase(self.dbname, create=True)
4345
46 #create some records to pull out and test
47 self.database.put_record(Record({"key1_1":"val1_1","key1_2":"val1_2","key1_3":"val1_3","record_type":"test.com"}))
48 self.database.put_record(Record({"key2_1":"val2_1","key2_2":"val2_2","key2_3":"val2_3","record_type":"test.com"}))
49 self.database.put_record(Record({"key13_1":"va31_1","key3_2":"val3_2","key3_3":"val3_3","record_type":"test.com"}))
50
44 def tearDown(self):51 def tearDown(self):
45 """tear down each test"""52 """tear down each test"""
46 del self.database._server[self.dbname]53 del self.database._server[self.dbname]
4754
55 def test_get_records_by_record_type_save_view(self):
56 """Test getting mutliple records by type"""
57 records = self.database.get_records(record_type="test.com",create_view=True)
58 self.assertEqual(3,len(records))
59
60 #def test_get_all_records()
61
48 def test_get_record(self):62 def test_get_record(self):
49 """Test getting a record."""63 """Test getting a record."""
50 record = Record({'record_number': 0}, record_type="http://example.com/")64 record = Record({'record_number': 0}, record_type="http://example.com/")

Subscribers

People subscribed via source and target branches