def filter(self): """Return a filter in SQlObject format""" taskValueFilter = (1 == 1) projectValueFilter = (1 == 1) if self.name: if self.value: if self.valueOperator == "=": taskValueFilter = (TaskKeyword.q.value == self.value) projectValueFilter = (ProjectKeyword.q.value == self.value) elif self.valueOperator == "!=": taskValueFilter = (TaskKeyword.q.value != self.value) projectValueFilter = (ProjectKeyword.q.value != self.value) # TODO: handle also <, >, =< and >= taskKeywordTaskIDs = Select( Task.q.id, where=(AND(LIKE(Keyword.q.name, self.name), TaskKeyword.q.keywordID == Keyword.q.id, TaskKeyword.q.taskID == Task.q.id, taskValueFilter))) projectKeywordTaskIDs = Select( Task.q.id, where=(AND(LIKE(Keyword.q.name, self.name), ProjectKeyword.q.keywordID == Keyword.q.id, ProjectKeyword.q.projectID == Project.q.id, Project.q.id == Task.q.project, projectValueFilter))) if self.negative: return AND(NOTIN(Task.q.id, taskKeywordTaskIDs), NOTIN(Task.q.id, projectKeywordTaskIDs)) else: return OR(IN(Task.q.id, taskKeywordTaskIDs), IN(Task.q.id, projectKeywordTaskIDs))
def _parseListLine(self, parser, line): """ Parse line with parser, returns a tuple of the form (options, projectList, filters) """ args = parser.parse_args(line) if len(args.filter) > 0: projectName, keywordFilters = parseutils.extractKeywords(u" ".join( args.filter)) else: projectName = "" keywordFilters = [] if self.kFilters: # Add keyword filter keywordFilters.extend(self.kFilters) if not projectName: if self.pFilter: # If a project filter is defined, use it as none was provided projectName = self.pFilter else: # Take all project if none provided projectName = "%" if projectName.startswith("!"): projectName = self._realProjectName(projectName[1:]) projectList = Project.select(NOT(LIKE(Project.q.name, projectName))) else: projectName = self._realProjectName(projectName) projectList = Project.select(LIKE(Project.q.name, projectName)) if projectList.count() == 0: raise YokadiException("Found no project matching '%s'" % projectName) # Check keywords exist parseutils.warnIfKeywordDoesNotExist(keywordFilters) # Filtering and sorting according to parameters filters = [] # Filter on keywords for keywordFilter in keywordFilters: filters.append(keywordFilter.filter()) # Search if args.search: for word in args.search: if word.startswith("@"): tui.warning( "Maybe you want keyword search (without -s option) " "instead of plain text search?") filters.append( OR(LIKE(Task.q.title, "%" + word + "%"), LIKE(Task.q.description, "%" + word + "%"))) return args, projectList, filters
def test_select_LIKE(): setupClass(IterTest) IterTest(name='sqlobject') IterTest(name='sqlbuilder') assert IterTest.select(LIKE(IterTest.q.name, "sql%")).count() == 2 assert IterTest.select(LIKE(IterTest.q.name, "sqlb%")).count() == 1 assert IterTest.select(LIKE(IterTest.q.name, "sqlb%")).count() == 1 assert IterTest.select(LIKE(IterTest.q.name, "sqlx%")).count() == 0
def getItemPropertiesStartingWith(item, field, text): """Return a list of item.field starting with text @param item: the object item, example : Task, Project, Keyword... @param field: the item's field lookup : Project.q.name, Task.q.title, Keyword.q.name. Don't forget the magic q @param text: The begining of the text as a str @return: list of matching strings""" return [x.name for x in item.select(LIKE(field, text + "%"))]
def __init__(self, name, filter_string): self.name = name project_name, keyword_filters = parseutils.extractKeywords( filter_string) q_filters = [x.filter() for x in keyword_filters] project_list = Project.select(LIKE(Project.q.name, project_name)) q_filters.append(IN(Task.q.project, project_list)) # Skip notes q_filters.append( parseutils.KeywordFilter("!@" + NOTE_KEYWORD).filter()) # Only list done tasks if they were done after min_date min_date = compute_min_date() q_filters.append( OR(Task.q.status != 'done', Task.q.doneDate >= min_date)) self.tasks = Task.select(AND(*q_filters), orderBy=Task.q.id, distinct=True, join=LEFTJOINOn( Task, TaskKeyword, Task.q.id == TaskKeyword.q.taskID))
def _get_expression(self): # pylint: disable=no-member # SQLObject methods not detected by pylint if self._bBraces: return super()._get_expression() return LIKE(func.LOWER(self._oMapTable.q.search_text), '%' + self._sPattern + '%')
def search_users(username, search_user): try: result = [] select = User.select(LIKE(User.q.username, "%{}%".format(search_user))) # print(123) select_for_con = UserContacts.select( UserContacts.q.user == User.select( User.q.username == username).getOne()) # print (dir(select_for_con)) # for i in select_for_con: # print(i) # print(type(i)) # print(i.user) for i in select: flag = False for j in select_for_con: print(j.con_user.username) if j.con_user.username == i.username: flag = True break if flag: continue result.append(i.username) return result except Exception as e: print(e) return "failed"
def _addProjectFilter(self): if self.projectName is None: return self._filters.append( IN( Task.q.project, Select(Project.q.id, LIKE(Project.q.name, "%" + self.projectName + "%")) ))
def warnIfKeywordDoesNotExist(keywordFilters): """Warn user is keyword does not exist @return: True if at least one keyword does not exist, else False""" doesNotExist = False for keyword in [k.name for k in keywordFilters]: if Keyword.select(LIKE(Keyword.q.name, keyword)).count() == 0: tui.error("Keyword %s is unknown." % keyword) doesNotExist = True return doesNotExist
def do_c_get(self, line): parser = self.parser_c_get() args = parser.parse_args(line) key = args.key if not key: key = "%" k = Config.select( AND(LIKE(Config.q.name, key), Config.q.system == args.system)) fields = [(x.name, "%s (%s)" % (x.value, x.desc)) for x in k] if fields: tui.renderFields(fields) else: raise YokadiException("Configuration key %s does not exist" % line)
def _renderList(self, renderer, projectList, filters, order, limit=None, groupKeyword=None): """ Render a list using renderer, according to the restrictions set by the other parameters @param renderer: renderer class (for example: TextListRenderer) @param projectList: list of project name (as unicode string) @param filters: filters in sqlobject format (example: Task.q.status == 'done') @param order: ordering in sqlobject format (example: -Task.q.urgency) @param limit: limit number tasks (int) or None for no limit @param groupKeyword: keyword used for grouping (as unicode string) or None """ if groupKeyword: if groupKeyword.startswith("@"): groupKeyword = groupKeyword[1:] for keyword in Keyword.select(LIKE(Keyword.q.name, groupKeyword)): if unicode(keyword.name).startswith( "_") and not groupKeyword.startswith("_"): # BUG: cannot filter on db side because sqlobject does not understand ESCAPE needed whith _ continue taskList = Task.select( AND(TaskKeyword.q.keywordID == keyword.id, *filters), orderBy=order, limit=limit, distinct=True, join=LEFTJOINOn(Task, TaskKeyword, Task.q.id == TaskKeyword.q.taskID)) taskList = list(taskList) if projectList: taskList = [ x for x in taskList if x.project in projectList ] if len(taskList) > 0: self.lastTaskIds.extend([ t.id for t in taskList ]) # Keep selected id for further use renderer.addTaskList(unicode(keyword), taskList) renderer.end() else: hiddenProjectNames = [] for project in projectList: if not project.active: hiddenProjectNames.append(project.name) continue taskList = Task.select(AND(Task.q.projectID == project.id, *filters), orderBy=order, limit=limit, distinct=True, join=LEFTJOINOn( Task, TaskKeyword, Task.q.id == TaskKeyword.q.taskID)) taskList = list(taskList) if len(taskList) > 0: self.lastTaskIds.extend([ t.id for t in taskList ]) # Keep selected id for further use renderer.addTaskList(unicode(project), taskList) renderer.end() if len(hiddenProjectNames) > 0: tui.info("hidden projects: %s" % ", ".join(hiddenProjectNames))
def _get_expression(self): # pylint: disable=no-member # SQLObject methods not detected by pylint return LIKE(AbstractCard.q.canonicalName, '%' + self.__sPattern + '%')
def _get_expression(self): # pylint: disable=no-member # SQLObject methods not detected by pylint return LIKE(func.LOWER(AbstractCard.q.text), '%' + self._sPattern + '%')
def _get_expression(self): return LIKE(func.LOWER(self.oTable.annotations), '%' + self.__sPattern + '%')
def _get_expression(self): return LIKE(func.LOWER(self.oTable.comment), '%' + self.__sPattern + '%')