comparison libervia/backend/memory/sqla_mapping.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents 5f2d496c633f
children
comparison
equal deleted inserted replaced
4269:64a85ce8be70 4270:0d7bb4df2343
87 87
88 88
89 profiles = Profiles() 89 profiles = Profiles()
90 90
91 91
92 def get_profile_by_id( profile_id): 92 def get_profile_by_id(profile_id):
93 return profiles.id_to_profile.get(profile_id) 93 return profiles.id_to_profile.get(profile_id)
94 94
95 95
96 class SyncState(enum.Enum): 96 class SyncState(enum.Enum):
97 #: synchronisation is currently in progress 97 #: synchronisation is currently in progress
261 ) 261 )
262 extra = Column(JSON) 262 extra = Column(JSON)
263 263
264 profile = relationship("Profile") 264 profile = relationship("Profile")
265 messages = relationship( 265 messages = relationship(
266 "Message", 266 "Message", backref="history", cascade="all, delete-orphan", passive_deletes=True
267 backref="history",
268 cascade="all, delete-orphan",
269 passive_deletes=True
270 ) 267 )
271 subjects = relationship( 268 subjects = relationship(
272 "Subject", 269 "Subject", backref="history", cascade="all, delete-orphan", passive_deletes=True
273 backref="history",
274 cascade="all, delete-orphan",
275 passive_deletes=True
276 ) 270 )
277 thread = relationship( 271 thread = relationship(
278 "Thread", 272 "Thread",
279 uselist=False, 273 uselist=False,
280 back_populates="history", 274 back_populates="history",
281 cascade="all, delete-orphan", 275 cascade="all, delete-orphan",
282 passive_deletes=True 276 passive_deletes=True,
283 ) 277 )
284 __mapper_args__ = {"version_id_col": version_id} 278 __mapper_args__ = {"version_id_col": version_id}
285 279
286 def __init__(self, *args, **kwargs): 280 def __init__(self, *args, **kwargs):
287 source_jid = kwargs.pop("source_jid", None) 281 source_jid = kwargs.pop("source_jid", None)
330 extra["thread"] = self.thread.thread_id 324 extra["thread"] = self.thread.thread_id
331 if self.thread.parent_id is not None: 325 if self.thread.parent_id is not None:
332 extra["thread_parent"] = self.thread.parent_id 326 extra["thread_parent"] = self.thread.parent_id
333 327
334 return { 328 return {
335 "from": f"{self.source}/{self.source_res}" 329 "from": (
336 if self.source_res 330 f"{self.source}/{self.source_res}" if self.source_res else self.source
337 else self.source, 331 ),
338 "to": f"{self.dest}/{self.dest_res}" if self.dest_res else self.dest, 332 "to": f"{self.dest}/{self.dest_res}" if self.dest_res else self.dest,
339 "uid": self.uid, 333 "uid": self.uid,
340 "message": {m.language or "": m.message for m in self.messages}, 334 "message": {m.language or "": m.message for m in self.messages},
341 "subject": {m.language or "": m.subject for m in self.subjects}, 335 "subject": {m.language or "": m.subject for m in self.subjects},
342 "type": self.type, 336 "type": self.type,
454 448
455 id = Column(Integer, primary_key=True, autoincrement=True) 449 id = Column(Integer, primary_key=True, autoincrement=True)
456 timestamp = Column(Float, nullable=False, default=time.time) 450 timestamp = Column(Float, nullable=False, default=time.time)
457 expire_at = Column(Float, nullable=True) 451 expire_at = Column(Float, nullable=True)
458 452
459 profile_id = Column(ForeignKey("profiles.id", ondelete="CASCADE"), index=True, nullable=True) 453 profile_id = Column(
454 ForeignKey("profiles.id", ondelete="CASCADE"), index=True, nullable=True
455 )
460 profile = relationship("Profile") 456 profile = relationship("Profile")
461 457
462 type = Column(Enum(NotificationType), nullable=False) 458 type = Column(Enum(NotificationType), nullable=False)
463 459
464 title = Column(Text, nullable=True) 460 title = Column(Text, nullable=True)