Skip to content

Commit

Permalink
Add tags for people (SEA-1445 und SEA-1437). Show avatars.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrillkuettel committed Aug 18, 2024
1 parent 4763ebe commit 2bc6d1b
Show file tree
Hide file tree
Showing 22 changed files with 585 additions and 49 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,6 @@ messages.xlsx
# Translation binaries
*.mo
*.pot

src/privatim/locale/de/LC_MESSAGES/privatim.mo
src/privatim/locale/fr/LC_MESSAGES/privatim.mo
Binary file added here.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 23 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ email-validator==2.2.0
# via
# privatim (setup.cfg)
# privatim
et-xmlfile==1.1.0
# via openpyxl
fanstatic==1.4
# via
# privatim (setup.cfg)
Expand Down Expand Up @@ -81,6 +83,8 @@ idna==3.7
# via
# email-validator
# requests
lxml==5.3.0
# via python-docx
mako==1.3.5
# via
# alembic
Expand All @@ -100,6 +104,10 @@ nh3==0.2.18
# via
# privatim (setup.cfg)
# privatim
openpyxl==3.1.5
# via
# privatim (setup.cfg)
# privatim
packaging==24.1
# via zope-sqlalchemy
pastedeploy==3.1.0
Expand All @@ -112,10 +120,11 @@ phonenumberslite==8.13.42
# via
# privatim (setup.cfg)
# privatim
pillow==10.4.0
pillow==10.3.0
# via
# privatim (setup.cfg)
# privatim
# pyavatar
# weasyprint
plaster==1.1.2
# via
Expand All @@ -126,10 +135,18 @@ plaster-pastedeploy==1.0.1
# privatim (setup.cfg)
# privatim
# pyramid
polib==1.2.0
# via
# privatim (setup.cfg)
# privatim
psycopg2==2.9.9
# via
# privatim (setup.cfg)
# privatim
pyavatar==0.1.6
# via
# privatim (setup.cfg)
# privatim
pycparser==2.22
# via cffi
pydyf==0.10.0
Expand Down Expand Up @@ -177,6 +194,10 @@ pyramid-tm==2.5
# privatim
python-dateutil==2.9.0.post0
# via arrow
python-docx==1.1.2
# via
# privatim (setup.cfg)
# privatim
python-magic==0.4.27
# via
# privatim (setup.cfg)
Expand Down Expand Up @@ -235,6 +256,7 @@ typing-extensions==4.12.2
# privatim (setup.cfg)
# alembic
# privatim
# python-docx
# sqlalchemy
urllib3==2.2.2
# via
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ fanstatic.libraries =
privatim:css = privatim.static:css_library

console_scripts =
fix_img = privatim.cli.migrate_profile_pic:main
add_user = privatim.cli.user:add_user
# delete_user = privatim.cli.user:delete_user
initialize_db = privatim.cli.initialize_db:main
Expand Down
50 changes: 31 additions & 19 deletions src/privatim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def includeme(config: Configurator) -> None:
))
smsdir = settings.get('sms.queue_path', '')
config.registry.registerUtility(ASPSMSGateway(smsdir))

config.include('pyramid_beaker')
config.include('pyramid_chameleon')
config.include('pyramid_layout')
Expand Down Expand Up @@ -300,13 +301,16 @@ def upgrade(context: 'UpgradeContext'): # type: ignore[no-untyped-def]

)

# this needs to be added in the second run
context.operations.create_index(
'idx_searchable_files_searchable_text_de_CH',
'searchable_files',
['searchable_text_de_CH'],
postgresql_using='gin',
)
if not context.index_exists(
'searchable_files', 'idx_searchable_files_searchable_text_de_CH'
):
# this needs to be added in the second run
context.operations.create_index(
'idx_searchable_files_searchable_text_de_CH',
'searchable_files',
['searchable_text_de_CH'],
postgresql_using='gin',
)

# Drop all existing comments and related tables
context.drop_table('comments_for_consultations_comments')
Expand Down Expand Up @@ -380,18 +384,26 @@ def upgrade(context: 'UpgradeContext'): # type: ignore[no-untyped-def]
),
)

context.operations.create_index(
context.operations.f('ix_consultations_deleted'),
'consultations',
['deleted'],
unique=False,
)
if not context.index_exists(
'consultations', 'ix_consultations_deleted'
):
context.operations.create_index(
context.operations.f('ix_consultations_deleted'),
'consultations',
['deleted'],
unique=False,
)

context.operations.create_index(
context.operations.f('ix_searchable_files_deleted'),
'searchable_files',
['deleted'],
unique=False,
)
if not context.index_exists(
'searchable_files', 'ix_searchable_files_deleted'
):
context.operations.create_index(
context.operations.f('ix_searchable_files_deleted'),
'searchable_files',
['deleted'],
unique=False,
)

context.add_column('users', Column('tags', String(255), nullable=True))

context.commit()
43 changes: 43 additions & 0 deletions src/privatim/cli/migrate_profile_pic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import click
from pyramid.paster import bootstrap
from pyramid.paster import get_appsettings

from privatim.models import User
from privatim.models.profile_pic import get_or_create_default_profile_pic
from privatim.orm import get_engine, Base


@click.command()
@click.argument('config_uri')
def main(config_uri: str) -> None:

env = bootstrap(config_uri)
settings = get_appsettings(config_uri)
engine = get_engine(settings)
Base.metadata.create_all(engine)

with env['request'].tm:
dbsession = env['request'].dbsession

# Update existing users and generate profile pics
default_pic = get_or_create_default_profile_pic(dbsession)
users = dbsession.query(User).all()
for user in users:
# Generate tags if not present
if not user.tags:
user.tags = (
user.first_name[:1] + user.last_name[:1]
).upper() or user.email[:2].upper()

if (
user.profile_pic is None or
user.profile_pic.content == default_pic.content
or user.profile_pic_id is None
):
user.generate_profile_picture(dbsession)

dbsession.flush()


if __name__ == '__main__':
main()
7 changes: 6 additions & 1 deletion src/privatim/cli/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class UpgradeContext:

def __init__(self, db: 'Session'):
self.session = db
self.engine: 'Engine' = self.session.bind # type: ignore
self.engine: Engine = self.session.bind # type: ignore

self.operations_connection = db._connection_for_bind(
self.engine
Expand All @@ -52,6 +52,11 @@ def drop_table(self, table: str) -> bool:
return True
return False

def index_exists(self, table_name: str, index_name: str) -> bool:
inspector = inspect(self.operations_connection)
indexes = inspector.get_indexes(table_name)
return any(index['name'] == index_name for index in indexes)

def has_column(self, table: str, column: str) -> bool:
inspector = inspect(self.operations_connection)
return column in {c['name'] for c in inspector.get_columns(table)}
Expand Down
1 change: 1 addition & 0 deletions src/privatim/cli/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ def add_user(
return

user = User(email=email, first_name=first_name, last_name=last_name)
user.generate_profile_picture(dbsession)
user.set_password(password)
dbsession.add(user)
22 changes: 22 additions & 0 deletions src/privatim/forms/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,25 @@
('ZG', 'ZG'),
('ZH', 'ZH'),
]

# Color palette for avatar backgrounds
AVATAR_COLORS = [
'#1abc9c', # Turquoise
'#2ecc71', # Emerald
'#3498db', # Peter River
'#9b59b6', # Amethyst
'#34495e', # Wet Asphalt
'#16a085', # Green Sea
'#27ae60', # Nephritis
'#2980b9', # Belize Hole
'#8e44ad', # Wisteria
'#2c3e50', # Midnight Blue
'#f1c40f', # Sunflower
'#e67e22', # Carrot
'#e74c3c', # Alizarin
'#95a5a6', # Concrete
'#f39c12', # Orange
'#d35400', # Pumpkin
'#c0392b', # Pomegranate
'#7f8c8d', # Asbestos
]
5 changes: 5 additions & 0 deletions src/privatim/forms/user_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ def validate_email(self, field: EmailField) -> None:
validators=[Optional()],
)

tags = StringField(
_('Tags'),
validators=[Optional(), Length(min=1, max=3)],
)

def populate_obj(self, obj: object) -> None:
for name, field in self._fields.items():

Expand Down
Binary file modified src/privatim/locale/de/LC_MESSAGES/privatim.mo
Binary file not shown.
Binary file modified src/privatim/locale/fr/LC_MESSAGES/privatim.mo
Binary file not shown.
Loading

0 comments on commit 2bc6d1b

Please sign in to comment.