Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Methods and Document Class
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
burli  
View profile  
 More options Dec 5 2011, 7:24 am
From: burli <m...@embedit.de>
Date: Mon, 5 Dec 2011 04:24:58 -0800 (PST)
Local: Mon, Dec 5 2011 7:24 am
Subject: Methods and Document Class

Hi, how can I add methods/functions to a Document Class? For example

class User(Document):
    name = TextField()

    def is_active(self):
        return True

user = User(name = "Foo")

If I call user.is_active() I dont get "True". The result is

<bound method User.is_active of <User 'Foo' ....[snip]....>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kxepal  
View profile  
 More options Dec 5 2011, 7:53 am
From: Kxepal <kxe...@gmail.com>
Date: Mon, 5 Dec 2011 04:53:32 -0800 (PST)
Local: Mon, Dec 5 2011 7:53 am
Subject: Re: Methods and Document Class

Hi,

Everything seems to be working for me:

from couchdb.mapping import Document, TextField

class User(Document):
    name = TextField()

    def is_active(self):
        return True

user = User(name = "Foo")
assert user.is_active() is True

even if you have mistyped Document class:

from couchdb.mapping import TextField
from couchdb.client import Document

class User(Document):
    name = TextField()

    def is_active(self):
        return True

user = User(name = "Foo")
assert user.is_active() is True

All should works well. Could you provide standalone example that could
reproduce problem?

--
,,,^..^,,,


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
burli  
View profile  
 More options Dec 5 2011, 8:06 am
From: burli <m...@embedit.de>
Date: Mon, 5 Dec 2011 05:06:36 -0800 (PST)
Local: Mon, Dec 5 2011 8:06 am
Subject: Re: Methods and Document Class

> from couchdb.client import Document

This is not documented. And if I add this I get the Error Message

AttributeError: 'User' object has no attribute 'store'


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alexander Shorin  
View profile  
 More options Dec 5 2011, 8:09 am
From: Alexander Shorin <kxe...@gmail.com>
Date: Mon, 5 Dec 2011 16:09:53 +0300
Local: Mon, Dec 5 2011 8:09 am
Subject: Re: Methods and Document Class

On Mon, Dec 5, 2011 at 5:06 PM, burli <m...@embedit.de> wrote:
>> from couchdb.client import Document
> This is not documented. And if I add this I get the Error Message

> AttributeError: 'User' object has no attribute 'store'

This is the same as
from couchdb import Document

Just quite common error(: Anyway, what's about document method call problem?

--
,,,^..^,,,


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
burli  
View profile  
 More options Dec 5 2011, 8:17 am
From: burli <m...@embedit.de>
Date: Mon, 5 Dec 2011 05:17:54 -0800 (PST)
Local: Mon, Dec 5 2011 8:17 am
Subject: Re: Methods and Document Class

Here is the complete program

import couchdb
from couchdb.mapping import *

from uuid import uuid4

class User(Document):
    name = TextField()
    active = BooleanField(default=True)
    password = TextField()
    type = TextField(default="User")

    def is_active(self):
        return self.active

    def is_anonymous(self):
        return False

    def is_authenticated(self):
        return self.is_authenticated

couch = couchdb.Server()

try:
    db = couch.delete("mydb")
    db = couch.create("mydb")
except:
    db = couch.create("mydb")

u=User(name = u"Notch", password = u"ü")
u.id = u"Notch"
u.store(db)
u=User(name = u"Steve", password = u"b")
u.id = u"Steve"
u.store(db)
u=User(name = u"Creeper", active = False, password = u"c")
u.id = u"Creeper"
u.store(db)

user = User.load(db, "Notch")
print user.is_authenticated()


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
burli  
View profile  
 More options Dec 5 2011, 8:29 am
From: burli <m...@embedit.de>
Date: Mon, 5 Dec 2011 05:29:54 -0800 (PST)
Local: Mon, Dec 5 2011 8:29 am
Subject: Re: Methods and Document Class

Something went wrong with my last post. Here again

Here is the complete program

import couchdb
from couchdb.mapping import *

from uuid import uuid4

class User(Document):
    name = TextField()
    active = BooleanField(default=True)
    password = TextField()
    type = TextField(default="User")

    def is_active(self):
        return self.active

    def is_anonymous(self):
        return False

    def is_authenticated(self):
        return self.is_authenticated

couch = couchdb.Server()

try:
    db = couch.delete("mydb")
    db = couch.create("mydb")
except:
    db = couch.create("mydb")

u=User(name = u"Notch", password = u"ü")
u.id = u"Notch"
u.store(db)
u=User(name = u"Steve", password = u"b")
u.id = u"Steve"
u.store(db)
u=User(name = u"Creeper", active = False, password = u"c")
u.id = u"Creeper"
u.store(db)

user = User.load(db, "Notch")
print user.is_authenticated()

If I add "from couchdb import Document" it does not work


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
burli  
View profile  
 More options Dec 5 2011, 8:44 am
From: burli <m...@embedit.de>
Date: Mon, 5 Dec 2011 05:44:22 -0800 (PST)
Local: Mon, Dec 5 2011 8:44 am
Subject: Re: Methods and Document Class

Looks like there is a different between

*from couchdb.mapping import Document*

and
*from couchdb import Document*

Only the Document Class from mapping supports store and load methods


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alexander Shorin  
View profile  
 More options Dec 5 2011, 2:58 pm
From: Alexander Shorin <kxe...@gmail.com>
Date: Mon, 5 Dec 2011 22:58:39 +0300
Local: Mon, Dec 5 2011 2:58 pm
Subject: Re: Methods and Document Class

Take a look at User.is_authenticated method - it just returns itself(;
Other methods works as expected.

--
,,,^..^,,,


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
burli  
View profile  
 More options Dec 6 2011, 2:57 am
From: burli <m...@embedit.de>
Date: Mon, 5 Dec 2011 23:57:13 -0800 (PST)
Local: Tues, Dec 6 2011 2:57 am
Subject: Re: Methods and Document Class

> Take a look at User.is_authenticated method - it just returns itself(;
> Other methods works as expected.

Sorry, copy & paste failure. Should just return True.

I fixed the problem now. There where some other bugs. But I found that
couchdb.mapping Document is not the same as couchdb Document.

Thanks
Markus


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alexander Shorin  
View profile  
 More options Dec 6 2011, 5:36 am
From: Alexander Shorin <kxe...@gmail.com>
Date: Tue, 6 Dec 2011 13:36:30 +0300
Local: Tues, Dec 6 2011 5:36 am
Subject: Re: Methods and Document Class

On Tue, Dec 6, 2011 at 11:57 AM, burli <m...@embedit.de> wrote:

>> Take a look at User.is_authenticated method - it just returns itself(;
>> Other methods works as expected.

> Sorry, copy & paste failure. Should just return True.

> I fixed the problem now. There where some other bugs. But I found that
> couchdb.mapping Document is not the same as couchdb Document.

> Thanks
> Markus

Yes, couchdb.Document and couchdb.mapping.Document are different.
First one if dict based class that represents raw CouchDB document as
it is, while second one tries to objectify it and give the warranty
that document would always have some fields with certain type.

--
,,,^..^,,,


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »