def existsSame(self, **o): l = MyLog().l() l = MyLog().empty() userId = getSimpleVal(o, 'userId') positionId = getSimpleVal(o, 'name') response = False doc = None l(userId, 'userId') l(positionId, 'positionId') if userId != None and positionId != None: searchDoc = { TimecardUsersPositions.user_id_: userId, TimecardUsersPositions.position_id_: positionId } # l(searchDoc, 'existsSame() searchDoc32879t234g89') with MyDB: cursor = TimecardUsersPositions.find(searchDoc) # if isinstance(cursor, collections.Iterable): for d in cursor: doc = d break if doc != None: response = True # l(doc, 'isExists doc6545641615') return response
def existsSame(self, **o): l = MyLog().l() l = MyLog().empty() name = o['name'] response = False doc = None searchDoc = {TimecardSkillTags.name_: name} # l(searchDoc, 'existsSame() searchDoc32879t234g89') with MyDB: cursor = TimecardSkillTags.find(searchDoc) # if isinstance(cursor, collections.Iterable): for d in cursor: doc = d break if doc != None: response = True # l(doc, 'isExists doc6545641615') return response
def getSkillTagIdByName(self, **o): l = MyLog().l() l = MyLog().empty() name = getSimpleVal(o, 'name') skillTagId = None doc = None cursor = None l(name, 'getSkillTagIdByName() name') if name != None: searchDoc = {TimecardSkillTags.name_: name} with MyDB: cursor = TimecardSkillTags.find(searchDoc) if iterable(cursor): for skill in cursor: doc = skill l(doc, 'finded skilltagID doc') break skillTagId = self.get_id(doc) l(skillTagId, 'skillTagId') return skillTagId
def my_save(self): l = MyLog().l() p = MyLog().p() l('OLOLO TROLOLO Method my_save() do nothing') l('ATTENTION: Method my_save() do nothing') p('OLOLO TROLOLO Method my_save() do nothing') p('ATTENTION: Method my_save() do nothing') result = None # with MyDB: # # objA = [] # list # # objB = () # tuple # objC = {} # dict # # setDoc = {} # if self.__values[TimecardUser.name_] != None: # setDoc[TimecardUser.name_] = self.__values[TimecardUser.name_] # # result = TimecardUser.update( # { # TimecardUser.id_: self[TimecardUser.id_], # }, # {'$set': setDoc # }, # upsert = False, # multi = False # ) return result
def getFilesIdsAppendedOnEmptyProject(self, appenderId): l = MyLog().l() p = MyLog().p() mass = self.getFilesAppendedOnEmptyProject(appenderId) _ = [] for x in mass: _.append(str(x['_id'])) return _
def blockLanguageEditByUserId(self, employeeId): l = MyLog().l() p = MyLog().p() response = False criteriaDoc = {TimecardUser.id_: int(employeeId)} updateDoc = {"$set": {TimecardUser.can_edit_language_skill_: 0}} l(criteriaDoc, 'criteriaDoc') l(updateDoc, 'updateDoc') with MyDB: response = TimecardUser.update(criteriaDoc, updateDoc) return response
def getFilesIdsAppendedOnRealProject(self, projectId): l = MyLog().l() p = MyLog().p() l('call func getFilesIdsAppendedOnRealProject() ') mass = self.getFilesAppendedOnRealProject(projectId) l(mass, 'mass') _ = [] for x in mass: _.append(str(x['_id'])) return _
def addSkillTagIdsToUser(self, userId, skillId, skillTagIds): addedUserSkillTagId = [] l = MyLog().l() if is_int(userId) and isValidObjectId(skillId): removeResult = self.removeUsersSkillTagsIds(userId=userId, skillId=skillId) if iterable(skillTagIds): for skillTagId_objectId in skillTagIds: b = not self.existsSame(skillTagId=skillTagId_objectId, userId=userId, skillId=skillId) l([b, skillTagId_objectId], 'NOT THE SAME: NEED INSERT ?') if b: # ObjectId userSkillTagId = self.addUserSkillTagId( skillTagId=skillTagId_objectId, userId=userId, skillId=skillId) if isValidObjectId(userSkillTagId): addedUserSkillTagId.append(userSkillTagId) return addedUserSkillTagId
def addNewTags(self, **opts): skillTagIds = [] l = MyLog().l() description = getSimpleVal(opts, 'description') words = my_explode(description) # wordsForInsert = list(set(words)) # l(wordsForInsert, 'wordsForInsert') # for word in wordsForInsert: for word in words: if not self.existsSame(name=word): skillTagId = self.addTag(name=word) skillTagIds.append(skillTagId) else: skillTagId = self.getSkillTagIdByName(name=word) l([skillTagId, word], 'skillTagId, word') if isValidObjectId(skillTagId): skillTagIds.append(skillTagId) else: l('SOMETHING HAPPENING') # l(skillTagIds, 'skillTagIds') return skillTagIds # list of ObjectId
def setCurrentLocationOrder(self, **options): l = MyLog().l() p = MyLog().p() me = options['me'] groupedUsers = options['groupedUsers'] groups = [] if 'office' in me and me['office'] in groupedUsers: # l(groupedUsers[me['office']], '39024uht930h0949groupedUsers[me[office]]') # projectList__ groups.append(groupedUsers[me['office']]) del groupedUsers[me['office']] for groupName, group in groupedUsers.iteritems(): groups.append(group) return groups
def remove_position_from_user(self, **o): l = MyLog().l() response = False ok = False removeResult = None userId = getSimpleVal(o, 'userId') positionId = getSimpleVal(o, 'positionId') l(positionId, 'positionId') l(userId, 'userId') if isValidObjectId(positionId): removeDoc = { TimecardUsersPositions.user_id_: userId, TimecardUsersPositions.position_id_: ObjectId(positionId), } l(removeDoc, 'removeDoc') with MyDB: removeResult = TimecardUsersPositions.remove(removeDoc) l(removeResult, 'removeResult') ok = getSimpleVal(removeResult, 'ok') if ok == 1: response = True l(ok, 'ok') return response
def addPositionToUser(self, **o): l = MyLog().l() userId = getSimpleVal(o, 'userId') positionId = getSimpleVal(o, 'positionId') addResult = False # l(userId, 'userId') # l(is_int(userId), 'is_int(userId)') # l(positionId, 'positionId') l(isValidObjectId(positionId), 'isValidObjectId(positionId)') if is_int(userId) and isValidObjectId(positionId): doc = { TimecardUsersPositions.user_id_: userId, TimecardUsersPositions.position_id_: ObjectId(positionId), } l(doc, 'doc') if not self.existsSame(userId=userId, positionId=positionId): with MyDB: addResult = TimecardUsersPositions.insert(doc) l(addResult, 'addResult') return addResult
def unblockSkillEditByUserId(self, employeeId): l = MyLog().l() p = MyLog().p() response = False result = None criteriaDoc = {TimecardUser.id_: int(employeeId)} updateDoc = {"$set": {TimecardUser.can_edit_skill_: 1}} with MyDB: result = TimecardUser.update(criteriaDoc, updateDoc) if isinstance(result, collections.Iterable): if 'updatedExisting' in result: if result['updatedExisting'] == True: response = result['updatedExisting'] return response
def getAllUsers(self, **options): l = MyLog().l() p = MyLog().p() users = [] order_by = getSimpleVal(options, 'order_by') i = 0 with MyDB: if order_by != None: cursor = TimecardUser.find().sort(order_by, humbledb.ASC) else: cursor = TimecardUser.find() if iterable(cursor): for x in cursor: x['order'] = i i += 1 users.append(x) return users
def getFilesAppendedOnEmptyProject(self, appenderId): l = MyLog().l() p = MyLog().p() _ = [] with MyDB: cursor = ProjectAppendedFilesDoc.find({ ProjectAppendedFilesDoc.appenderId: appenderId, ProjectAppendedFilesDoc.projectId: { '$exists': False } }) # _ =[x for x in cursor] for el in cursor: el['fileId'] = str(el['_id']) _.append(el) l(el, 'el') return _
def getFilesAppendedOnRealProject(self, project_id): l = MyLog().l() p = MyLog().p() _ = [] # project_id searchDoc = {ProjectAppendedFilesDoc.projectId: ObjectId(project_id)} l(searchDoc, 'searchDoc') with MyDB: cursor = ProjectAppendedFilesDoc.find(searchDoc) # l(cursor, 'cursor') for el in cursor: el['fileId'] = str(el['_id']) _.append(el) # l(el, 'el') return _
def groupBy(self, **options): l = MyLog().l() group_by = options['group_by'] users = options['users'] groups = {} for user in users: if group_by in user: if not user[group_by] in groups: groups[user[group_by]] = [] groups[user[group_by]].append(user) return groups
def addTag(self, **o): l = MyLog().l() resultInsert = False name = getSimpleVal(o, 'name') if is_str(name): insertDoc = {TimecardSkillTags.name_: name} with MyDB: skillTagId = TimecardSkillTags.insert(insertDoc) return skillTagId
def clearListFromAppliedPositions(self, **o): l = MyLog().l() notApplied = [] usersPositions = getSimpleVal(o, 'usersPositions') allPositions = getSimpleVal(o, 'allPositions') if iterable(allPositions): for position in allPositions: # l(position, 'position') if iterable(position): if '_id' in position: # '_id' hasUser = False # l(hasUser, 'hasUser') if iterable(usersPositions): for userPosition in usersPositions: l(userPosition, 'userPosition') if iterable(userPosition): if TimecardUsersPositions.position_id_ in userPosition: # l(userPosition[TimecardUsersPositions.position_id_], 'userPosition[TimecardUsersPositions.position_id_]') # l(position['_id'], 'position[_id]') strPositionId = str(position['_id']) strUserPosition = str( userPosition[TimecardUsersPositions .position_id_]) # l(strPositionId, 'strPositionId') # l(strUserPosition, 'strUserPosition') b = strUserPosition == strPositionId # l(b, 'beeeee') if b: hasUser = True break if hasUser == False: notApplied.append(position) return notApplied
def existsSame(self, **o): l = MyLog().l() userId = getSimpleVal(o, 'userId') skillTagId = getSimpleVal(o, 'skillTagId') skillId = getSimpleVal(o, 'skillId') response = False doc = None # l(is_int(userId), 'is_int(userId)') # l(isValidObjectId(skillTagId), 'isValidObjectId(skillTagId)') # l(skillId, 'skillId') # # l(isValidObjectId(skillId), 'isValidObjectId(skillId)') if is_int(userId) and isValidObjectId(skillTagId) and isValidObjectId( skillId): searchDoc = { TimecardUserSkillTagId.user_id_: userId, TimecardUserSkillTagId.skill_id_: ObjectId(skillId), TimecardUserSkillTagId.skill_tag_id_: ObjectId(skillTagId), } with MyDB: cursor = TimecardUserSkillTagId.find(searchDoc) # l(cursor, 'cursor987tsdfasdf') # l(iterable(cursor), 'iterable(cursor)') if iterable(cursor): for d in cursor: # l(d, 'd') doc = d break # l(doc, 'DOCCcc') if doc != None: response = True # l(doc, 'isExists doc') return response
def removeUsersSkillTagsIds(self, **o): l = MyLog().l() removeResult = None userId = o['userId'] skillId = o['skillId'] criteriaDoc = { TimecardUserSkillTagId.user_id_: userId, TimecardUserSkillTagId.skill_id_: skillId } with MyDB: removeResult = TimecardUserSkillTagId.remove(criteriaDoc) l(removeResult, 'removeResult') return removeResult
def validateDate(self, dd_mm_yyyyy, splitter='/'): l = MyLog().l() day = None month = None year = None # l(dd_mm_yyyyy, '-->>>dd_mm_yyyyy') if type(splitter) == str: lst = dd_mm_yyyyy.split('/') # l(lst, '!!lst') if len(lst) == 3: year = lst.pop() month = lst.pop() day = lst.pop() # l(day, '!!day') # l(month, '!!month') # l(year, '!!year') return day, month, year
def isValidDate(self, dd_mm_yyyyy): l = MyLog().l() response = False d_, m_, y_ = self.validateDate(dd_mm_yyyyy) l(d_, 'd_') # l([d_, m_, y_], '[d_, m_, y_]') if d_ != None and m_ != None and y_ != None: if isinstance(d_, unicode) and isinstance( m_, unicode) and isinstance(y_, unicode): d_ = int(d_) m_ = int(m_) y_ = int(y_) if d_ > 0 and d_ < 32 and m_ > 0 and m_ < 13 and y_ > 0 and y_ < 9999: response = True return response
def compare(self, aDateStr, bDateStr, splitter='/'): l = MyLog().l() result = False # l(aDateStr, '-->> aDateStr') # l(bDateStr, '-->> bDateStr') aDay, aMonth, aYear = self.validateDate(aDateStr, splitter) bDay, bMonth, bYear = self.validateDate(bDateStr, splitter) if aDay != None and aMonth != None and aYear != None and bDay != None and bMonth != None and bYear != None: # l(aYear, 'aYear') # l(aMonth, 'aMonth') # l(aDay, 'aDay') # # l(bYear, 'bYear') # l(bMonth, 'bMonth') # l(bDay, 'bDay') # aDate = datetime.strptime(str(aYear) + str(aMonth) + str(aDay), "%Y%m%d") # bDate = datetime.strptime(str(bYear) + str(bMonth) + str(bDay), "%Y%m%d") aDate = None bDate = None _aStr = str(aYear) + str(aMonth) + str(aDay) _bStr = str(bYear) + str(bMonth) + str(bDay) # l(_aStr, '_aStr') # l(_bStr, '_bStr') aDate = datetime.datetime.strptime(_aStr, "%Y%m%d") bDate = datetime.datetime.strptime(_bStr, "%Y%m%d") # l(aDate, 'aDate') # l(bDate, 'bDate') if aDate.date() < bDate.date(): result = 1 else: if aDate.date() == bDate.date(): result = 0 else: result = -1 return result
def activateShowOnMainPage(self, **o): response = False l = MyLog().l() positionId = getSimpleVal(o, 'positionId') l(positionId, 'positionId') userId = getSimpleVal(o, 'userId') positionId = toObjectId(positionId) l(positionId, 'positionId') l(is_int(userId), 'is_int(userId)') l(type(positionId) == ObjectId, 'type(positionId) == ObjectId') if is_int(userId) and type(positionId) == ObjectId: updateResult = None searchDoc = { TimecardUsersPositions.position_id_: positionId, TimecardUsersPositions.user_id_: userId } # l(searchDoc, 'searchDoc') updateDoc = { '$set': { TimecardUsersPositions.show_on_main_page_: True } } # l(updateDoc, 'updateDoc') with MyDB: updateResult = TimecardUsersPositions.update( searchDoc, updateDoc) l(updateResult, 'updateResult') if isinstance(updateResult, collections.Iterable): if 'updatedExisting' in updateResult: if updateResult['updatedExisting'] == True: response = True return response
def updateFileDescriptionRealProject(self, appenderId, projectId, fileId, fileDescription): l = MyLog().l() result = None updateDoc = { "_id": ObjectId(fileId), ProjectAppendedFilesDoc.appenderId: appenderId, ProjectAppendedFilesDoc.projectId: ObjectId(projectId) } setDoc = {ProjectAppendedFilesDoc.fileDescription: fileDescription} with MyDB: result = ProjectAppendedFilesDoc.update(updateDoc, {'$set': setDoc}, upsert=False, multi=False) return result
def addUserSkillTagId(self, **o): l = MyLog().l() skillTagId = getSimpleVal(o, 'skillTagId') userId = getSimpleVal(o, 'userId') skillId = getSimpleVal(o, 'skillId') insertDoc = None userSkillTagId = None if is_int(userId) and isValidObjectId(skillTagId) and isValidObjectId( skillId): insertDoc = { TimecardUserSkillTagId.skill_id_: ObjectId(skillId), TimecardUserSkillTagId.skill_tag_id_: ObjectId(skillTagId), TimecardUserSkillTagId.user_id_: userId, } with MyDB: userSkillTagId = TimecardUserSkillTagId.insert(insertDoc) l(userSkillTagId, 'NEW USER SKILL TAG') return userSkillTagId # ObjectId