Skip to content

Commit

Permalink
Tracker meta: rename user_type by user_kind
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Nov 20, 2023
1 parent d304da8 commit b9cbbbd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lemarche/stats/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class TrackerQuerySet(models.QuerySet):
def env_prod(self):
return self.filter(env="prod", isadmin=False)

def by_user_type(self, user_type):
return self.filter(data__meta__user_type=user_type)
def by_user_kind(self, user_kind):
return self.filter(user_kind=user_kind)

def siae_views_last_3_months(self, siae_slug):
return self.env_prod().filter(
Expand All @@ -22,10 +22,10 @@ def siae_views_last_3_months(self, siae_slug):
)

def siae_buyer_views_last_3_months(self, siae_slug):
return self.env_prod().siae_views_last_3_months(siae_slug).by_user_type(constants.USER_KIND_BUYER)
return self.env_prod().siae_views_last_3_months(siae_slug).by_user_kind(constants.USER_KIND_BUYER)

def siae_partner_views_last_3_months(self, siae_slug):
return self.env_prod().siae_views_last_3_months(siae_slug).by_user_type(constants.USER_KIND_PARTNER)
return self.env_prod().siae_views_last_3_months(siae_slug).by_user_kind(constants.USER_KIND_PARTNER)


class Tracker(models.Model):
Expand Down
2 changes: 1 addition & 1 deletion lemarche/templates/includes/_tracker_itou.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
const meta = Object.assign(metaIn, getUrlMeta());
// user info
meta['is_admin'] = {% if user.is_authenticated %}{% if user.kind == 'ADMIN' %}true{% else %}false{% endif %}{% else %}false{% endif %};
meta['user_type'] = {% if user.is_authenticated %}'{{ user.kind }}'{% else %}null{% endif %};
meta['user_kind'] = {% if user.is_authenticated %}'{{ user.kind }}'{% else %}null{% endif %};
meta['user_id'] = {% if user.is_authenticated %}{{ user.id }}{% else %}null{% endif %};
meta['siae_id'] = {% if siae %}{{ siae.id }}{% else %}null{% endif %};
// default data
Expand Down
6 changes: 3 additions & 3 deletions lemarche/utils/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
# @task()
def track(page: str = "", action: str = "load", meta: dict = {}): # noqa B006
# Don't log in dev
if settings.BITOUBI_ENV not in ("dev", "test"):
if settings.BITOUBI_ENV not in ("test"):
date_created = timezone.now()
user_id = int(meta.get("user_id")) if meta.get("user_id", None) else None
user_kind = meta.get("user_type") if meta.get("user_type", "") else ""
user_kind = meta.get("user_kind") if meta.get("user_kind", "") else ""
siae_id = meta.get("siae_id", None)
if siae_id:
siae_id = int(siae_id[0]) if (type(siae_id) is list) else int(siae_id)
Expand Down Expand Up @@ -154,7 +154,7 @@ def extract_user_info(self, request: HttpRequest, context_data: dict):
siae = context_data.get("siae")
return {
"user_id": user.id if user.is_authenticated else None,
"user_type": user.kind if user.is_authenticated else "",
"user_kind": user.kind if user.is_authenticated else "",
"is_admin": user.is_authenticated and user.kind == User.KIND_ADMIN,
"siae_id": siae.id if siae else None,
"siae_kind": siae.kind if siae else "",
Expand Down

0 comments on commit b9cbbbd

Please sign in to comment.