I'm pretty lost in everything you've described. I've been working with web2py for 2+ days and am slowly getting the hang of it. If you could dumb it down a bit, that would be helpful.

FYI - I can print the username using auth.user_id.username anyplace else in a web page. I just need to submit that variable to the database when my form is properly filled out. Nothing more, nothing less. I know this can be done using hidden form objects in regular HTML, but I don't see how to do that with CRUD.

On 2/23/2012 3:02 PM, Richard Vézina wrote:
I am pretty not sure about the hack, but you can try... It is pretty dirty... And you will not be able to use represent except if you transform back you id from string to int.

Why you don't just write a simple function that you other ressource will call to get the ids under string format like this :

def id_to_string(id):
    return str(id)


Richard

On Thu, Feb 23, 2012 at 2:58 PM, Richard Vézina <ml.richard.vez...@gmail.com <mailto:ml.richard.vez...@gmail.com>> wrote:

    In that case I think you will have to build something on your
    side... Maybe implement your own IS_IN_DB could be a solution... A
    hack could be this :

    db.ips.reportedby.requires=str(IS_IN_DB())

    But I don't think you will be able to define a foreign key... You
    will have to enforce your integrity check by yourself at the form
    level with validator...

    So, change your field definition for string only,
    no  "db.auth_user" and by the way that was wrong model definition
    I didn't catch at first read...

    Richard


    On Thu, Feb 23, 2012 at 2:53 PM, Larry G. Wapnitsky
    <la...@kvetsch.com <mailto:la...@kvetsch.com>> wrote:

        it's only one user that I need to enter into the database at a
        time, and only the username.   reportedby needs to be text due
        to another application that uses the same database.


        On 2/23/2012 2:51 PM, Richard Vézina wrote:
        Ok,

        So you need to create a foreign key relation... So you need
        "requires="...

        db.ips.reportedby.requires=IS_IN_DB(db, 'ips.id
        <http://ips.id>', '%(first_name)s %(last_name)s %(username)s
        %(whateverfieldname)s')

        If you have only one referenced user you will have to change
        the type of reportedby to integer since the id of ips is a
        int. If you want to reference many users you will have to add
        something to you IS_IN_DB requires :

        db.ips.reportedby.requires=IS_IN_DB(db, 'ips.id
        <http://ips.id>', '%(first_name)s %(last_name)s %(username)s
        %(whateverfieldname)s', multiple=True)

        And you will have to change also the type of the field for :
        list:reference type

        See book chapter 6 whit keyword list:reference

        Richard


        On Thu, Feb 23, 2012 at 2:43 PM, Larry G. Wapnitsky
        <la...@kvetsch.com <mailto:la...@kvetsch.com>> wrote:

            I need to have the username added to another SQL table on
            submission of a form.

            This is some of the code:

            db.define_table('ips',
                Field('id', 'id'),
                Field('ipaddress','string', length=15, unique=True),
                Field('dateadded', 'datetime', default=request.now),
Field('reportedby', 'string', db.auth_user, writable=False, readable=False),
                Field('updated', 'datetime', default=request.now),
                Field('attacknotes', 'text'),
                Field('b_or_w', 'string', length=1),
                migrate=False)


            db.ips.ipaddress.requires = [IS_NOT_IN_DB(db,
            'ips.ipaddress')]
            db.ips.ipaddress.requires.append(IS_IPV4())


            the field 'reportedby' needs to be filled in with the
            username taken from AD for the logged in user.


            On 2/23/2012 2:37 PM, Richard Vézina wrote:
            Ok, but what's is the problem... I don't understand sorry.

            Richard

            On Thu, Feb 23, 2012 at 2:33 PM, Larry G. Wapnitsky
            <la...@kvetsch.com <mailto:la...@kvetsch.com>> wrote:

                The issue is not putting the username into the
                web2py database, but another database that's storing
                information.

                On 2/23/2012 2:32 PM, Richard Vézina wrote:
                I am not sure how you connect to LDAP, but there is
                utilities to connect LDAP with web2py. You should
                read about those in the book searching with LDAP as
                keyword. If you only want to import LDAP user into
                web2py database table, I suggest you to use the
                user table of the RBAC.

                So then you can access those entries with CRUD, but
                also manage who is allow to access those sensitive
                informations.

                Richard

                On Thu, Feb 23, 2012 at 2:13 PM, Larry Wapnitsky
                <la...@kvetsch.com <mailto:la...@kvetsch.com>> wrote:

                    (newbie disclaimer :))

                    I'm logging in to my application via AD/LDAP.
                     I can get the variable of the username with no
                    issue.  What i need to do next is take this
                    variable and insert it into a field in a CRUD
                    form and have it show in my database.

                    Thanks,
                    Larry







Reply via email to