feat: configurable branding, private preferences, city photo cards and database backups
This commit is contained in:
+14
-1
@@ -3,6 +3,8 @@ import datetime as dt
|
||||
import json
|
||||
import re
|
||||
import secrets
|
||||
import hashlib
|
||||
from appearance import png_bytes
|
||||
|
||||
|
||||
class Households:
|
||||
@@ -110,7 +112,8 @@ class Households:
|
||||
def label(uid):
|
||||
account = self.a.get_object('users', uid)
|
||||
return account.get('name', '') if account else ''
|
||||
return [dict({k: v for k, v in row.items() if k != 'leadershipHistory' or self.manager(user)}, ownerName=label(row.get('ownerId')), successorName=label(row.get('successorId')),
|
||||
return [dict({k: v for k, v in row.items() if k != 'coverData' and (k != 'leadershipHistory' or self.manager(user))}, ownerName=label(row.get('ownerId')), successorName=label(row.get('successorId')),
|
||||
coverUrl=('/api/households/cover?id='+row['id']+'&v='+row.get('coverRevision','0')) if row.get('coverData') else '',
|
||||
canAssignOwner=user['role'] == 'admin' or row.get('ownerId') == user['id'],
|
||||
members=sum(self.family_of(u) == row['id'] for u in self.a.objects('users')),
|
||||
sites=sum(self.family_of(s) == row['id'] for s in self.a.objects('sites'))) for row in rows]
|
||||
@@ -162,6 +165,16 @@ class Households:
|
||||
kind=kind,
|
||||
note=a.clean_text(data.get('note', ''), 300),
|
||||
createdAt=old['createdAt'] if old else dt.datetime.now(dt.timezone.utc).isoformat())
|
||||
for field in ('province','city','district'):
|
||||
item[field] = a.clean_text(data.get(field, (old or {}).get(field, '')), 60)
|
||||
if 'coverData' in data:
|
||||
cover = data['coverData']
|
||||
if not isinstance(cover, str): raise a.Problem('封面图片格式不正确')
|
||||
if cover:
|
||||
try: png_bytes(cover, 2*1024*1024)
|
||||
except ValueError as error: raise a.Problem(str(error).replace('Logo', '封面'))
|
||||
item['coverData'] = cover
|
||||
item['coverRevision'] = hashlib.sha256(cover.encode()).hexdigest()[:16]
|
||||
a.save_object('households', item)
|
||||
a.audit('保存家庭', item['name'])
|
||||
return item
|
||||
|
||||
Reference in New Issue
Block a user