def list(self, **kwargs):
        """
        List all keys of a index


        list all entries matching kwargs. If none are specified, lists all

        e.g.
        email="*****@*****.**", name="reem"

        """
        if kwargs:
            clauses = []
            for key, val in kwargs.items():
                if not hasattr(self.index, key):
                    raise RuntimeError('%s model has no field "%s"' %
                                       (self.index._meta.name, key))
                field = getattr(self.index, key)
                clauses.append(field.contains(val))

            res = [
                item.key for item in self.index.select().where(
                    peewee.reduce(operator.and_, clauses)).order_by(
                        self.index.modTime.desc())
            ]
        else:
            res = [
                item.key for item in self.index.select().order_by(
                    self.index.modTime.desc())
            ]

        return res
Example #2
0
def getcalls(chatid, symbol=None):
    clauses = [(Calls.chatid == chatid), (Calls.type != 'WATCH')]
    if symbol:
        clauses.append((Calls.sym == symbol))

    callstxt = ''

    for call in Calls.select().where(reduce(operator.and_, clauses)):
        print("Time: " + call.time.strftime('%b %d %H:%M'))
        callstxt +=  call.type + " " + call.sym + "@" + call.callrange \
                    +" on <i>" + call.time.strftime('%b %d %H:%M') + "</i>\n"
    return callstxt
Example #3
0
def getcalls(chatid, symbol=None):
    clauses = [(Calls.chatid == chatid),
               (Calls.type.not_in([WATCH_TYPE, PORTFOLIO_TYPE]))]
    if symbol:
        clauses.append((Calls.sym == symbol))

    callstxt = ''
    for call in Calls.select().where(reduce(operator.and_, clauses)):
        callstxt += call.user + " : " + call.type + " " + call.sym + "@" + call.callrange + \
                    " " +(call.desc if call.desc else " ")+ \
                    " on <i>" + call.time.strftime('%b %d %H:%M') + "</i>\n"
    return callstxt
Example #4
0
    def list(self, **kwargs):
        """
        List all keys of a index


        list all entries matching kwargs. If none are specified, lists all

        e.g.
        email="*****@*****.**", name="reem"

        """
        if kwargs:
            clauses = []
            for key, val in kwargs.items():
                if not hasattr(self.index, key):
                    raise RuntimeError('%s model has no field "%s"' %
                                       (self.index._meta.name, key))
                field = (getattr(self.index, key))
                if isinstance(val, list):  # get range in list
                    clauses.append(field.between(val[0], val[1]))
                elif isinstance(field, peewee.BooleanField) or isinstance(
                        val, bool):
                    if j.data.types.bool.fromString(val):
                        clauses.append(field)
                    else:
                        clauses.append(~field)
                else:
                    clauses.append(field.contains(val))

            res = [
                item.key for item in self.index.select().where(
                    peewee.reduce(operator.and_, clauses)).order_by(
                        self.index.modTime.desc())
            ]
        else:
            res = [
                item.key for item in self.index.select().order_by(
                    self.index.modTime.desc())
            ]

        return res
Example #5
0
 def get_and_expression(cls, kwargs):
     return reduce(operator.and_, (cls.get_expression(field, value) for field, value in kwargs.items()))