コード例 #1
0
ファイル: search.py プロジェクト: mrmaple/open_qon
    def _generate_document_for_user(self, user, existing):
        fields = []    

        # fields are in the form of [name, value, isStored, isIndexed, isTokenized]
        fields.append(['karma', str(user.get_karma_score()).zfill(6), False, True, False])
        fields.append(['u_name', user.display_name(), False, True, True])
        fields.append(['date', str(get_unix_timestamp(user.get_user_data().member_since())), False, True, False])    # index it so that we can sort by it            
        fields.append(['oid', self._encode_oid(user._p_oid), True, True, False])
        fields.append(['type', 'User', True, True, True])                   

        # create the main text to index (bio + email addresses + name)
        tidb = get_tagged_item_database()
        tags = " ".join(tidb.get_tags(user._p_oid))
        text = "%s %s %s %s %s" % (user.bio, user.location, " ".join(user.email_list()), user.display_name(), tags)
        fields.append(['text', text, False, True, True])    

        # create the preview text    
        preview = self._generate_preview_text(user.bio)
        fields.append(['preview', preview, True, False, False])

        # send the document for indexing        
        self._queue_document(fields, existing)
コード例 #2
0
ファイル: qxmlrpc.py プロジェクト: mrmaple/open_qon
    def user_data(self, login_bundle, atom_tag, fields):
        """Return struct containing requested fields for user atom_tag.

        Parameters:
            atom_tag: the atom tag of the user for which requesting data
            fields: array of zero or more of the following:
                'name':         currently-specified name to be displayed
                'fscore':       feedback score
                'fbank':        feedback bank
                'fpos':         positive feedback received
                'fneg':         negative feedback received
                'fposgiv':      positive feedback given
                'fneggiv':      negative feedback given
                'fcom':         net comment feedback received
                'fcompos':      positive comment feedback received
                'fcomneg':      negative comment feedback received
                'membsince':    member since date
                'lastlogin':    last login (may return 'never' or 'inactive')
                'idletime':     idle time or 'none' if not logged in
                'posffrom':     positive feedback from (array of user_ids)
                'posffromnum':  number of positive feedback givers
                'negffrom':     negative feedback from (if visible)
                'neggfromnum':  number of negative feedback givers
                'emaildomain:   domain portion of email
                'groupown':     groups owned by user
                'groupmemb':    groups user is a member of
                'all':          all of the above

        Returns struct containing one entry per requested field.
        """
        user_db = get_user_database()
        group_db = get_group_database()

        cur_user = self._check_login(login_bundle)
        user = lookup_atom_id(atom_tag)
        if not user or not isinstance(user, qon.user.User):
            raise xmlrpclib.Fault(FAULT_INVALID_ITEM, 'Invalid user id')

        all = 'all' in fields
        result = {}

        if all or 'name' in fields:
            result['name'] = user.display_name()
        if all or 'fscore' in fields:
            result['fscore'] = user.get_karma_score()
        if all or 'fbank' in fields:
            result['fbank'] = user.get_karma_bank_balance()
        if all or 'fpos' in fields:
            result['fpos'] = user.karma_plus_received()
        if all or 'fneg' in fields:
            result['fneg'] = user.karma_minus_received()
        if all or 'fposgiv' in fields:
            result['fposgiv'] = user.karma_plus_given()
        if all or 'fneggiv' in fields:
            result['fneggiv'] = user.karma_minus_given()

        if all or ('fcom' in fields) or ('fcompos' in fields) or ('fcomneg' in fields):
            fcompos, fcomneg = get_list_database().karma_user_content_totals(user)
        if all or 'fcom' in fields:
            result['fcom'] = fcompos + fcomneg
        if all or 'fcompos' in fields:
            result['fcompos'] = fcompos
        if all or 'fcomneg' in fields:
            result['fcomneg'] = fcomneg

        if all or 'membsince' in fields:
            dt = user.get_user_data().member_since()
            result['membsince'] = _format_dt(dt)
        if all or 'lastlogin' in fields:
            result['lastlogin'] = _format_dt(getattr(user, 'last_login', None))
        if all or 'idletime' in fields:
            if user.is_disabled():
                sec = 'inactive'
            else:
                idle = user.idle_time()
                if idle:
                    sec = idle.seconds
                else:
                    sec = 'none'
            result['idletime'] = sec

        if all or 'posffrom' in fields:
            result['posffrom'] = [atom_id(user_db.get_user(uid)) \
                    for karma, uid in user.positive_karma_givers()]

        if all or 'posffromnum' in fields:
            result['posffromnum'] = len(user.positive_karma_givers())

        if all or 'negffrom' in fields:
            result['negffrom'] = [atom_id(user_db.get_user(uid)) \
                    for karma, uid in user.negative_karma_givers()]

        if all or 'negffromnum' in fields:
            result['negffromnum'] = len(user.negative_karma_givers())

        if all or 'emaildomain' in fields:
            e = user.get_primary_email()
            result['emaildomain'] = e[e.find('@')+1:]
        if all or 'groupown' in fields:
            result['groupown'] = [atom_id(g) \
                    for g in group_db.owned_groups(user)]
        if all or 'groupmemb' in fields:
            result['groupmemb'] = [atom_id(g) \
                    for g in group_db.member_groups(user)]

        return result
コード例 #3
0
ファイル: qxmlrpc.py プロジェクト: mrmaple/open_qon
def _format_user(user):
    return dict(
            atom_tag = atom_id(user),
            display_name = xml_escape(user.display_name()),
            feedback_score = user.get_karma_score(),
            )