Пример #1
0
    def updateAttrInMongoDBColl(self,attrName,collName=AUTHORCLAIM_USERS_MONGODB_COLL):

        # Debug
        #conn=getMongoDBConn()
        # Must be set explicitly to JSON in order to avoid the seg fault?
        # Debug 

        # bson.errors.InvalidDocument: Cannot encode object: Liu, Xiaoming
        # print getattr(self,attrName).toJSON()
        # This works
        # getMongoDBColl('debugDictList',getMongoDBConn()).update({'a':True},{'$set':{'e':[{'a':'b'},{'c':'d'}]}},True,safe=True)
        

        #getMongoDBColl(collName,conn).update({'acisID':self.value},{'$set':{attrName:getattr(self,attrName).toJSON()}},True,safe=True)
        #conn.disconnect()

        conn=getMongoDBConn()
        try:
            getMongoDBColl(collName,conn).update({'acisID':self.value},{'$set':{attrName:getattr(self,attrName).toJSON()}},True,safe=True)
        except:
            print 'Could not update'
            raise
        conn.disconnect()
        print 'Updated'
        exit()
Пример #2
0
def getACUserRecordForACISID(acisID):

    conn=getMongoDBConn()
    record=getMongoDBColl(AUTHORCLAIM_USERS_MONGODB_COLL,conn).find_one({'acisID':acisID})
    
    conn.disconnect()
    return record
Пример #3
0
    def retrieveAttrFromDBColl(self,attrName,collName=AUTHORS_MONGODB_COLL):

        conn=getMongoDBConn()
        try:
            record=getMongoDBColl(collName,conn).find_one({'name':self.value},{attrName:True})
        except:
            print 'Could not retrieve'
            raise
        if attrName in record:return record[attrName]
        conn.disconnect()
Пример #4
0
    def retrieveAttrFromDBColl(self,attrName,collName=AUTHORCLAIM_USERS_MONGODB_COLL):

        conn=getMongoDBConn()
        try:
            record=getMongoDBColl(collName,conn).find_one({'acisID':self.value},{attrName:True})
        except:
            print 'Could not retrieve the attribute',attrName,'for',self.value
            exit(1)
            #raise
        if record and (attrName in record):return record[attrName]
        conn.disconnect()
Пример #5
0
def checkIfACUserHasClaimedText(authorNameStr,amfText):

    # I do not know what the ACIS string-normalization process resembles.
    #authorNameStr=sub('['+escape(punctuation)+']','',authorNameStr.lower())
    authorNameStr=normalizeAunex(authorNameStr)

    conn=getMongoDBConn()
    record=getACUserRecordForNameVar(authorNameStr,conn)
    conn.disconnect()
    
    if not record:return record
    return amfText.get('ref') in record['isauthorofTexts']
Пример #6
0
    def updateMongoDBColl(self,collName=AUTHORS_MONGODB_COLL):

        # print unicode(self.toJSON()).encode('ascii','backslashreplace')
        #print self.toJSON()

        conn=getMongoDBConn()
        try:
            return getMongoDBColl(collName,conn).update({'name':self.value},{'$set':{'name':self.value}},True,safe=True)
        except:
            print 'Could not update'
            exit()
            raise
        conn.disconnect()
        print 'Updated'
        exit()