Esempio n. 1
0
    def touch(data, by_user=None):
        if '_db_created_time' not in data:
            data.update({'_db_created_time': now()})
        elif data['_db_created_time'] is None:
            data['_db_created_time'] = now()

        if '_db_created_by' not in data:
            data.update({'_db_created_by': by_user.username if by_user else None})
        elif data['_db_created_by'] is None:
            data['_db_created_by'] = by_user.username if by_user else None

        if '_db_updated_time' not in data:
            data.update({'_db_updated_time': now()})
        else:
            data['_db_updated_time'] = now()

        if '_db_updated_by' not in data:
            data.update({'_db_updated_by': by_user.username if by_user else None})
        else:
            data['_db_updated_by'] = by_user.username if by_user else None

        if '_db_deleted' not in data:
            data.update({'_db_deleted': False})

        if '_db_owner' not in data:
            data.update({'_db_owner': by_user.username if by_user else None})

        if '_db_created_time' not in data:
            data.update({'_db_created_time': now()})
    def load_session(self):
        doc = self.get_doc(self.id)

        if doc is None:
            raise InvalidCookieException()

        # Expire time on session
        if (dateutils.now() - dateutils.fromtuple(doc["date"])).total_seconds() > self.expires:
            raise InvalidCookieException()
        
        doc["date"] = dateutils.totuple(self.date)
        self.doc = doc
Esempio n. 3
0
    def load_session(self):
        doc = self.get_doc(self.id)

        if doc is None:
            raise InvalidCookieException()

        # Expire time on session
        if (dateutils.now() - dateutils.fromtuple(
                doc["date"])).total_seconds() > self.expires:
            raise InvalidCookieException()

        doc["date"] = dateutils.totuple(self.date)
        self.doc = doc
Esempio n. 4
0
    def init(self):
        if self.is_init:
            return
        self.is_init = True

        self.date = dateutils.now()
        if self.id != None:
            try:
                self.load_session()
                return
            except InvalidCookieException:
                pass
        self.new_session()
    def init(self):
        if self.is_init:
            return
        self.is_init = True

        self.date = dateutils.now()
        if self.id != None:
            try:
                self.load_session()
                return
            except InvalidCookieException:
                pass
        self.new_session()
Esempio n. 6
0
    def save(self, comment=u"", filepath=None):
        self.date = dateutils.now()
        self.comment = comment
        self.version = 2

        filepath = filepath or self.filepath

        self.filepath = filepath

        if filepath is None:
            raise Exception("No path specified")

        try:
            current = Document.load(filepath)
        except IOError:
            pass
        else:
            dateformatted = current.date.astimezone(dateutils.utc).strftime("%Y.%m.%d.%H.%M.%S")
            shutil.move(filepath, filepath + "." + dateformatted)

        with open(filepath, "w") as f:
            json.dump(self.export(), f)
def add(uid, group, description, amount, creditor, debtors):
    date = dateutils.totuple(dateutils.now())
    
    members = set(x[0] for x in user.getmembers(uid))

    if not creditor in members:
        raise PermissionError()

    for debtor in debtors:
        if not debtor[0] in members:
            raise PermissionError()

    db().save_doc({
        "type": "entry",
        "amount": amount,
        "creditor": creditor,
        "date": date,
        "debtors": debtors,
        "description": description,
        "group": group,
        "uid": uid,
        "deletedby":None,
    })
Esempio n. 8
0
 def __init__(self, id_=None, description=u"", date=None, amount=0):
     self.id = id_ or unicode(uuid4().hex)
     self.description = description
     self.date = date or dateutils.now()
     self.amount = amount
Esempio n. 9
0
 def __init__(self, name=u"", price=0, quantity=0, date=None, id=None):
     self.name = name
     self.price = price
     self.quantity = quantity
     self.date = date or dateutils.now()
     self.id = id or unicode(uuid4().hex)