feat: add notification services and observation views implementation
This commit is contained in:
parent
e27a979a53
commit
775151c72d
2 changed files with 9 additions and 15 deletions
|
|
@ -666,9 +666,7 @@ def get_or_create_observation_discussion(observation):
|
||||||
"""
|
"""
|
||||||
Trouve ou crée la discussion associée à une observation.
|
Trouve ou crée la discussion associée à une observation.
|
||||||
|
|
||||||
Les participants sont : le créateur de l'observation + les membres des
|
Les participants sont : le créateur de l'observation.
|
||||||
équipes gestionnaires d'assets (is_assets_manager=True) pour la catégorie
|
|
||||||
concernée.
|
|
||||||
Retourne (discussion, created).
|
Retourne (discussion, created).
|
||||||
"""
|
"""
|
||||||
from .models import Discussion
|
from .models import Discussion
|
||||||
|
|
@ -703,18 +701,6 @@ def get_or_create_observation_discussion(observation):
|
||||||
if observation.created_by_id:
|
if observation.created_by_id:
|
||||||
participants.add(observation.created_by)
|
participants.add(observation.created_by)
|
||||||
|
|
||||||
if observation.category_id:
|
|
||||||
try:
|
|
||||||
from contracts.models import CompanyMember
|
|
||||||
from django.contrib.auth.models import User as AuthUser
|
|
||||||
manager_users = AuthUser.objects.filter(
|
|
||||||
companymember__teams__is_assets_manager=True,
|
|
||||||
companymember__teams__asset_categories=observation.category,
|
|
||||||
).distinct()
|
|
||||||
participants.update(manager_users)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
discussion.participants.set(participants)
|
discussion.participants.set(participants)
|
||||||
return discussion, True
|
return discussion, True
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1000,6 +1000,8 @@ def observation_change_status(request, observation_id):
|
||||||
if new_status == 'needs_info':
|
if new_status == 'needs_info':
|
||||||
from notifications.services import get_or_create_observation_discussion, post_message
|
from notifications.services import get_or_create_observation_discussion, post_message
|
||||||
discussion, _created = get_or_create_observation_discussion(observation)
|
discussion, _created = get_or_create_observation_discussion(observation)
|
||||||
|
if request.user.is_authenticated:
|
||||||
|
discussion.participants.add(request.user)
|
||||||
post_message(
|
post_message(
|
||||||
discussion=discussion,
|
discussion=discussion,
|
||||||
author=request.user,
|
author=request.user,
|
||||||
|
|
@ -1016,6 +1018,8 @@ def observation_change_status(request, observation_id):
|
||||||
)
|
)
|
||||||
from notifications.services import get_or_create_observation_discussion, post_message
|
from notifications.services import get_or_create_observation_discussion, post_message
|
||||||
discussion, _created = get_or_create_observation_discussion(observation)
|
discussion, _created = get_or_create_observation_discussion(observation)
|
||||||
|
if request.user.is_authenticated:
|
||||||
|
discussion.participants.add(request.user)
|
||||||
post_message(
|
post_message(
|
||||||
discussion=discussion,
|
discussion=discussion,
|
||||||
author=request.user,
|
author=request.user,
|
||||||
|
|
@ -1282,6 +1286,8 @@ def observation_add(request, observation_id=None):
|
||||||
)
|
)
|
||||||
from notifications.services import get_or_create_observation_discussion, post_message
|
from notifications.services import get_or_create_observation_discussion, post_message
|
||||||
discussion, _created = get_or_create_observation_discussion(observation)
|
discussion, _created = get_or_create_observation_discussion(observation)
|
||||||
|
if request.user.is_authenticated:
|
||||||
|
discussion.participants.add(request.user)
|
||||||
post_message(
|
post_message(
|
||||||
discussion=discussion,
|
discussion=discussion,
|
||||||
author=request.user,
|
author=request.user,
|
||||||
|
|
@ -2004,6 +2010,8 @@ def observation_add_message(request, observation_id):
|
||||||
)
|
)
|
||||||
|
|
||||||
discussion, _created = get_or_create_observation_discussion(observation)
|
discussion, _created = get_or_create_observation_discussion(observation)
|
||||||
|
if request.user.is_authenticated:
|
||||||
|
discussion.participants.add(request.user)
|
||||||
|
|
||||||
files = request.FILES.getlist('attachments') or None
|
files = request.FILES.getlist('attachments') or None
|
||||||
post_message(discussion=discussion, author=request.user, content=content, files=files)
|
post_message(discussion=discussion, author=request.user, content=content, files=files)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue