lanto03 / couchdb-python

Automatically exported from code.google.com/p/couchdb-python
Other
0 stars 0 forks source link

ViewDefinition.sync_many for many views is very unhandy #127

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create about 30 types of document schemes
2. Add about 10-15 views for each document schema
3. Try to sync views with couchdb via couchdb.design.ViewDefinition.sync_many

What is the expected output? What do you see instead?
I expected way to sync all views by document class. Something like:
couchdb.design.ViewDefinition.sync_many(db,[Couteragents, Orders, Cars, ...])

Instead I must describe each view for each document:
couchdb.design.ViewDefinition.sync_many(db,
[Counteragents.by_name, Counteragents.list, Counteragents.by_discount,
Counteragents.by_car, Counteragents.address_info, ..., Cars.by_model,
Cars.list, Cars.by_year, Cars.by_owner, ...]
)

What version of the product are you using? On what operating system?
Linux 2.6.32.11-calculate, couchdb 0.11.0, couchdb-python 0.7.1@33d71d3080ba

Please provide any additional information below.
I see two problems there:
1. When I'm adding new view or removing old one I must also check up for
sync_many call and add/remove view to/from second argument.
2. I may suddenly forget for some view and I will have an error. With more
than 30 views it's an easy.

I don't see this method bad, but there must be much more easy solution to
sync up all Document views.

For now, we're using such solution:

from couchdb.mapping import Document,ViewField
class DocumentWhichKnowsOwnViews(Document):
  @classmethod
  def list_views(cls):
      return filter(lambda value: isinstance(value, ViewField),
                    cls.__dict__.values())

than all other documents are derived from DocumentWhichKnowsOwnViews and then:

couchdb.design.ViewDefinition.sync_many(db,[
Counteragents.list_views(),
Orders.list_views(),
...#etc
])

Not great solution, but it's solving this problem. And it will be great to
have such functionality by default.

Original issue reported on code.google.com by kxepal on 13 May 2010 at 2:41

GoogleCodeExporter commented 8 years ago
This issue has been migrated to GitHub. Please continue discussion here:

https://github.com/djc/couchdb-python/issues/127

Original comment by djc.ochtman on 15 Jul 2014 at 7:18