Exemplo n.º 1
0
    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 sql alchemy format (example: Task.status == 'done')
        @param order: ordering in sqlalchemy format (example: desc(Task.urgency))
        @param limit: limit number tasks (int) or None for no limit
        @param groupKeyword: keyword used for grouping (as unicode string) or None
        """
        def applyFilters(lst):
            for filter in filters:
                lst = filter.apply(lst)
            return lst

        if groupKeyword:
            if groupKeyword.startswith("@"):
                groupKeyword = groupKeyword[1:]
            keywords = self.session.query(Keyword).filter(Keyword.name.like(groupKeyword))

            for keyword in sorted(keywords, key=lambda x: x.name.lower()):
                if str(keyword.name).startswith("_") and not groupKeyword.startswith("_"):
                    # BUG: cannot filter on db side because sqlobject does not
                    # understand ESCAPE needed with _. Need to test it with
                    # sqlalchemy
                    continue
                taskList = self.session.query(Task).filter(TaskKeyword.keywordId == keyword.id)
                taskList = taskList.outerjoin(TaskKeyword, Task.taskKeywords)
                taskList = applyFilters(taskList)
                taskList = taskList.order_by(*order).limit(limit).distinct()
                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(str(keyword), taskList)
            renderer.end()
        else:
            hiddenProjectNames = []
            for project in sorted(projectList, key=lambda x: x.name.lower()):
                if not project.active:
                    hiddenProjectNames.append(project.name)
                    continue
                taskList = self.session.query(Task).filter(Task.project == project)
                taskList = taskList.outerjoin(TaskKeyword, Task.taskKeywords)
                taskList = applyFilters(taskList)
                taskList = taskList.order_by(*order).limit(limit).distinct()
                taskList = list(taskList)
                if len(taskList) > 0:
                    self.lastTaskIds.extend([t.id for t in taskList])  # Keep selected id for further use
                    renderer.addTaskList(str(project), taskList)
            renderer.end()

            if len(hiddenProjectNames) > 0:
                tui.info("hidden projects: %s" % ", ".join(hiddenProjectNames))
Exemplo n.º 2
0
    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))
Exemplo n.º 3
0
 def do_c_set(self, line):
     """Set a configuration key to value : c_set <key> <value>"""
     line = line.split()
     if len(line) < 2:
         raise BadUsageException("You should provide two arguments : the parameter key and the value")
     name = line[0]
     value = " ".join(line[1:])
     p = Config.select(AND(Config.q.name == name, Config.q.system == False))
     if p.count() == 0:
         tui.error("Sorry, no parameter match")
     else:
         if self.checkParameterValue(name, value):
             p[0].value = value
             tui.info("Parameter updated")
         else:
             tui.error("Parameter value is incorrect")
Exemplo n.º 4
0
 def do_c_set(self, line):
     """Set a configuration key to value : c_set <key> <value>"""
     line = line.split()
     if len(line) < 2:
         raise BadUsageException("You should provide two arguments : the parameter key and the value")
     name = line[0]
     value = " ".join(line[1:])
     session = db.getSession()
     p = session.query(Config).filter_by(name=name, system=False)
     if p.count() == 0:
         raise YokadiException("Sorry, no parameter match")
     else:
         if self.checkParameterValue(name, value):
             p[0].value = value
             tui.info("Parameter updated")
         else:
             raise YokadiException("Parameter value is incorrect")
Exemplo n.º 5
0
 def do_c_set(self, line):
     """Set a configuration key to value : c_set <key> <value>"""
     line = line.split()
     if len(line) < 2:
         raise BadUsageException("You should provide two arguments : the parameter key and the value")
     name = line[0]
     value = " ".join(line[1:])
     session = db.getSession()
     p = session.query(Config).filter_by(name=name, system=False)
     if p.count() == 0:
         raise YokadiException("Sorry, no parameter match")
     else:
         if self.checkParameterValue(name, value):
             p[0].value = value
             tui.info("Parameter updated")
         else:
             raise YokadiException("Parameter value is incorrect")
Exemplo n.º 6
0
 def do_c_set(self, line):
     """Set a configuration key to value : c_set <key> <value>"""
     line = line.split()
     if len(line) < 2:
         raise BadUsageException(
             "You should provide two arguments : the parameter key and the value"
         )
     name = line[0]
     value = " ".join(line[1:])
     p = Config.select(AND(Config.q.name == name, Config.q.system == False))
     if p.count() == 0:
         tui.error("Sorry, no parameter match")
     else:
         if self.checkParameterValue(name, value):
             p[0].value = value
             tui.info("Parameter updated")
         else:
             tui.error("Parameter value is incorrect")
Exemplo n.º 7
0
    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))
Exemplo n.º 8
0
    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 sql alchemy format (example: Task.status == 'done')
        @param order: ordering in sqlalchemy format (example: desc(Task.urgency))
        @param limit: limit number tasks (int) or None for no limit
        @param groupKeyword: keyword used for grouping (as unicode string) or None
        """
        def applyFilters(lst):
            for filter in filters:
                lst = filter.apply(lst)
            return lst

        if groupKeyword:
            if groupKeyword.startswith("@"):
                groupKeyword = groupKeyword[1:]
            keywords = self.session.query(Keyword).filter(
                Keyword.name.like(groupKeyword))

            for keyword in sorted(keywords, key=lambda x: x.name.lower()):
                if str(keyword.name).startswith(
                        "_") and not groupKeyword.startswith("_"):
                    # BUG: cannot filter on db side because sqlobject does not understand ESCAPE needed with _. Need to test it with sqlalchemy
                    continue
                taskList = self.session.query(Task).filter(
                    TaskKeyword.keywordId == keyword.id)
                taskList = taskList.outerjoin(TaskKeyword, Task.taskKeywords)
                taskList = applyFilters(taskList)
                taskList = taskList.order_by(*order).limit(limit).distinct()
                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(str(keyword), taskList)
            renderer.end()
        else:
            hiddenProjectNames = []
            for project in sorted(projectList, key=lambda x: x.name.lower()):
                if not project.active:
                    hiddenProjectNames.append(project.name)
                    continue
                taskList = self.session.query(Task).filter(
                    Task.project == project)
                taskList = taskList.outerjoin(TaskKeyword, Task.taskKeywords)
                taskList = applyFilters(taskList)
                taskList = taskList.order_by(*order).limit(limit).distinct()
                taskList = list(taskList)
                if len(taskList) > 0:
                    self.lastTaskIds.extend([
                        t.id for t in taskList
                    ])  # Keep selected id for further use
                    renderer.addTaskList(str(project), taskList)
            renderer.end()

            if len(hiddenProjectNames) > 0:
                tui.info("hidden projects: %s" % ", ".join(hiddenProjectNames))