def _coerce(value): if value: if isinstance(value, int): return LID(value) elif isinstance(value, str): return LID.from_str(value) return value
def test_compare_lid(): with freeze_time("2020-08-31 12:00:01"): lid1 = LID() with freeze_time("2020-08-31 12:00:02"): lid2 = LID() assert lid1 < lid2 assert lid2 > lid1
def process_bind_param(self, value, dialect): if isinstance(value, LID): return value.lid elif isinstance(value, str): return LID.from_str(value).lid else: return value
def test_create_lid(): with freeze_time("2020-08-31 12:00:01"): lid = LID() ts_str, rand_str = lid.repr.split("-") assert len(ts_str) == 9 assert len(rand_str) == 5 assert lid.datetime assert lid.milliseconds
def proposition_note(request, proposition_id=LID(), user_id=0): note = request.q(PropositionNote).get({ "proposition_id": proposition_id, "user_id": user_id }) if note is None: return PropositionNote(user_id, proposition_id) return note
def proposition_path(request, proposition_id=LID(), slug=""): proposition = request.q(Proposition).get(proposition_id) if proposition is None: return None canonical_slug = proposition_slug(proposition) if canonical_slug == slug: return proposition canonical = f"/p/{proposition_id}/{canonical_slug}" Message.log(msg="redirect to canonical URL", original=slug, canonical=canonical_slug) return redirect(canonical)
def argument_relations(request, proposition_id=LID(), relation_type=None): return ArgumentRelations(proposition_id, relation_type)
def argument_relation(request, proposition_id=LID(), argument_id=0): argument_relation = request.q(ArgumentRelation).filter_by( proposition_id=proposition_id, argument_id=argument_id).scalar() return argument_relation
def _convert_lid_or_legacy_id(value): if "-" not in value: return LID(int(value)) else: return LID.from_str(value)
def process_result_value(self, value, dialect): if value is None: return value return LID(value)
def __init__(self, proposition_id=LID()): self.id = proposition_id
def test_from_lid_from_int(): lid_int = 6705847306369952472 lid = LID(lid_int) assert lid.milliseconds == 1598798586456 assert lid.repr == "1EGZX4RJR-31TPR" assert lid.datetime == datetime(2020, 8, 30, 14, 43, 6, 456000)
def test_lid_from_str(): lid_str = "1EGZX4RJR-31TPR" lid = LID.from_str(lid_str) assert lid.repr == lid_str assert lid == lid_str
def test_lid_equality(): lid = LID() assert lid == LID(lid.lid) assert lid == lid.lid
def convert_lid(): return morepath.Converter(lambda s: LID.from_str(s), lambda l: str(l))