I tried doing this last year and I was close and couldn't figure it out.
I need to complete implementing it and wondered if you could help out.
Using the attatched model I want to do the following:
I need to have a list of all the users that have similar tags to the
user that is logged in. I need those tag names as well.
As an added sugar candy bonus I wonder if there is an easy way to could
them or should I just count them as I sort throw them in the view.
I think I am close with this, it modified from something done last year.
Am I doing this right?
Best Regards,
Jason Brower

My pertinent controller function:
---

@auth.requires_login()
def your_connections():
    related_tags = db((

db.auth_user.id==db.user_tags.user_id)&(db.user_tags.tag_id==db.tag.id)&(db.user_tags.tag_id.belongs(
            db(db.user_tags.user_id==auth.user.id)._select(
                db.user_tags.tag_id)))).select(
                    db.auth_user.ALL,db.tag.ALL,groupby=db.auth_user.id)
    return dict(related_tags = related_tags)
---
from datetime import datetime, date, time
now = datetime.utcnow()
today = date.today()


db = SQLDB('sqlite://interestID.db')

#######################################
# Authentication System
#######################################
from gluon.tools import Mail, Auth

mail = Mail()
mail.settings.server='smtp.gmail.com:587'
mail.settings.sender= '[email protected]'
mail.settings.login='[email protected]:----'

auth = Auth(globals(), db)

# after
# auth = Auth(globals(),db)
auth_table = db.define_table(auth.settings.table_user_name,
        Field('first_name',
            length=128,
            default=''),
        Field('last_name',
            length=128,
            default=''),
        Field('email',
            length=128,
            default='',
            unique=True),
        Field('password', 'password', 
            length=256,
            readable=False,
            label='Password'),
        Field('registration_key',
            length=128,
            default= '',
            writable=False,
            readable=False),
        Field('nickname', 'string',
            length=20,
            unique=True),
        Field('phone_number', 'string',
            length=15),
        Field('university_affiliation', 'string',
            length=100),
        Field('created', 'datetime',
            default=now,
            writable=False,
            readable=False),
        Field('avatar', 'upload'),
        Field('short_description','text'),
        Field('sex','text')
    )
auth_table.first_name.requires = \
    IS_NOT_EMPTY(error_message=auth.messages.is_empty)
auth_table.last_name.requires = \
    IS_NOT_EMPTY(error_message=auth.messages.is_empty)
auth_table.password.requires = [CRYPT()]
auth_table.email.requires = [
    IS_EMAIL(error_message=auth.messages.invalid_email),
    IS_NOT_IN_DB(db, auth_table.email)]
auth.settings.table_user = auth_table
auth_table.nickname.requires = IS_NOT_IN_DB(db,'auth_user.nickname')
auth_table.created.requires = IS_NOT_EMPTY()
auth_table.sex.requires = IS_IN_SET(["Male","Female","Unset"])
auth.settings.mailer = mail
auth.define_tables()

db.define_table('tag',
        Field('name', 'string'),
        Field('description', 'text'),
        Field('logo', 'upload'),
        Field('created', 'date', default=now, writable=False),
        Field('creator', 'string', writable=False))

db.define_table('user_tags',
        Field('tag_id',db.tag),
        Field('user_id', db.auth_user))
        
db.define_table('user_photos',
        Field('photo', 'upload'),
        Field('description', 'text'),
        Field('tag', db.tag),
        Field('date_added', 'datetime', default=request.now, readable=False, writable=False),
        Field('creator', 'integer'))

db.user_photos.tag.requires = IS_IN_DB(db, db.tag.id, '%(name)s')

db.user_tags.tag_id.requires = IS_IN_DB(db,'tag.id', '%(name)s')
db.user_tags.user_id.requires = IS_IN_DB(db, 'auth_user.id', '%(nickname)s')

db.tag.name.requires = [IS_NOT_EMPTY(), IS_NOT_IN_DB(db,'tag.name')]
db.tag.description.requires = IS_NOT_EMPTY()
db.tag.logo.requires = IS_NOT_EMPTY()
db.tag.created.requires = IS_NOT_EMPTY()

#Special condition to default to the current user.
if auth.user:
    user_id=auth.user.email
else: user_id=0
db.tag.creator.default=user_id
db.user_photos.creator.default=user_id

Reply via email to