Пример #1
0
    def set_iso_datetime(self, attr, value):
        try:
            date, time = value.split(" ")
            yy, mm, dd = date.split("-")
            try:
                hh, min, sec = time.split(":")
            except:
                hh = min = sec = 0
            value = datetime.datetime(str_to_int(yy), str_to_int(mm), str_to_int(dd), str_to_int(hh), str_to_int(min), str_to_int(sec))
        except Exception:
            value = None

        setattr(self, attr, value)
Пример #2
0
    def set_datetime(self, attr, value):
        try:
            date, time = value.split(" ")
            dd, mm, yy = date.split(".")
            try:
                hh, min = time.split(":")
            except:
                hh = min = 0
            value = datetime.datetime(str_to_int(yy), str_to_int(mm), str_to_int(dd), str_to_int(hh), str_to_int(min), 0)
        except Exception:
            value = None

        setattr(self, attr, value)
Пример #3
0
 def set_ordering(self, order_changed, order_items_ids):
     if order_changed == "1":
         ids = [str_to_int(n) for n in order_items_ids.split(",") if n]
         for n, id in enumerate(ids):
             if id == 0:
                 id = self.id
             self.__class__.objects.filter(id=id).update(order=n)
Пример #4
0
    def set_datetime(self, attr, value):
        import datetime
        from project.main.util import str_to_int
        try:
            date, time = value.split(" ")
            dd, mm, yy = date.split(".")
            try:
                hh, min = time.split(":")
            except:
                hh = min = 0
            value = datetime.datetime(str_to_int(yy), str_to_int(mm),
                                      str_to_int(dd), str_to_int(hh),
                                      str_to_int(min), 0)
        except:
            value = None

        setattr(self, attr, value)
Пример #5
0
    def set_many_to_many(self, attr, obj_class, ids):
        if isinstance(ids, str):
            ids = [str_to_int(n) for n in ids.split(",") if n]

        # add new objects
        for id in ids:
            try:
                item = obj_class.objects.get(id=id)
                if not attr.filter(id=id).exists():
                    attr.add(item)
            except obj_class.DoesNotExist:
                pass
        # remove nonexisting objects
        for item in attr.all():
            if item.id not in ids:
                attr.remove(item)
Пример #6
0
    def __create_entry(self, client_app, data, counter, bulk_uuid=None):
        if 'level' not in data:
            raise APIException("Invalid parameter")
        if 'format' not in data:
            raise APIException("Invalid parameter")

        direction = str_to_int(
            data['direction'], default=const.DirectionNone
        ) if 'direction' in data else const.DirectionNone
        if not direction in const.ValidDirections:
            direction = const.DirectionNone

        try:
            level = int(data['level'])
            format = int(data['format'])
        except ValueError:
            raise APIException("Invalid parameter")

        if format == const.FormatJson:
            d = json.dumps(data['data'])
        else:
            d = data['data']

        timestamp = None
        if 'timestamp' in data:
            try:
                timestamp = datetime.datetime.strptime(data['timestamp'],
                                                       "%Y-%m-%d %H:%M:%S.%f")
            except:
                pass

        counter.add(level=level, cnt=1)

        return LogEntry(
            client_app=client_app,
            direction=direction,
            level=level,
            format=format,
            category=data['category'] if 'category' in data else None,
            group=data['group'] if 'group' in data else None,
            bulk_uuid=bulk_uuid,
            data=d,
            vars=data['variables'] if 'variables' in data else None,
            timestamp=timestamp
            if timestamp is not None else datetime.datetime.now(),
        )
Пример #7
0
    def set_many_to_many(self, attr, obj_class, ids):
        if isinstance(ids, basestring):
            from project.main.util import str_to_int
            ids = [str_to_int(n) for n in ids.split(",") if n]

        # add new objects
        for id in ids:
            try:
                item = obj_class.objects.get(id=id)
                if attr.filter(id=id).count() == 0:
                    attr.add(item)
            except obj_class.DoesNotExist:
                pass
        # remove nonexisting objects
        for item in attr.all():
            if not item.id in ids:
                attr.remove(item)