-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev-server' into production
- Loading branch information
Showing
33 changed files
with
1,121 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,6 @@ media/ | |
env/ | ||
venv/ | ||
.vscode | ||
.idea | ||
.idea | ||
|
||
dump.rdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import json | ||
|
||
from django.db.models.signals import post_save, post_delete | ||
from django.dispatch import receiver | ||
from django.db.models import Count | ||
from django.db.models.functions import Coalesce | ||
|
||
from db.learning_circle import LearningCircle | ||
from db.learning_circle import UserCircleLink | ||
from db.organization import Organization | ||
from db.task import InterestGroup | ||
from db.user import User, UserRoleLink | ||
|
||
from utils.types import IntegrationType, OrganizationType | ||
from utils.baseconsumer import BaseConsumer | ||
|
||
|
||
class GlobalCount(BaseConsumer): | ||
|
||
def receive(self, text_data): | ||
if json.loads(text_data)['type'] == 'global_count': | ||
org_type_counts = Organization.objects.filter( | ||
org_type__in=[OrganizationType.COLLEGE.value, OrganizationType.COMPANY.value, | ||
OrganizationType.COMMUNITY.value] | ||
).values('org_type').annotate(org_count=Coalesce(Count('org_type'), 0)) | ||
org_type_counts = list(org_type_counts) | ||
|
||
enablers_mentors_count = UserRoleLink.objects.filter( | ||
role__title__in=["Mentor", "Enabler"]).values( | ||
'role__title').annotate(role_count=Coalesce(Count('role__title'), 0)) | ||
enablers_mentors_count = list(enablers_mentors_count) | ||
|
||
interest_groups_count = InterestGroup.objects.all().count() | ||
learning_circles_count = LearningCircle.objects.all().count() | ||
members_count = User.objects.all().count() | ||
|
||
data = { | ||
'members': members_count, | ||
'org_type_counts': org_type_counts, | ||
'enablers_mentors_count': enablers_mentors_count, | ||
'ig_count': interest_groups_count, | ||
'learning_circle_count': learning_circles_count | ||
} | ||
|
||
self.send(text_data=json.dumps(data)) | ||
|
||
@receiver(post_save, sender=User) | ||
@receiver(post_save, sender=LearningCircle) | ||
@receiver(post_save, sender=InterestGroup) | ||
@receiver(post_save, sender=UserRoleLink) | ||
@receiver(post_save, sender=Organization) | ||
def user_post_save(sender, instance, created, **kwargs): | ||
data = {} | ||
|
||
if created: | ||
if sender == User: | ||
count = User.objects.all().count() | ||
data['members'] = count | ||
|
||
elif sender == LearningCircle: | ||
count = LearningCircle.objects.all().count() | ||
data['learning_circle_count'] = count | ||
|
||
elif sender == InterestGroup: | ||
count = InterestGroup.objects.all().count() | ||
data['ig_count'] = count | ||
|
||
elif sender == UserRoleLink: | ||
count = UserRoleLink.objects.filter( | ||
role__title__in=["Mentor", "Enabler"]).values( | ||
'role__title').annotate(role_count=Coalesce(Count('role__title'), 0)) | ||
data['enablers_mentors_count'] = list(count) | ||
|
||
elif sender == Organization: | ||
count = Organization.objects.filter( | ||
org_type__in=[OrganizationType.COLLEGE.value, OrganizationType.COMPANY.value, | ||
OrganizationType.COMMUNITY.value] | ||
).values('org_type').annotate(org_count=Coalesce(Count('org_type'), 0)) | ||
data['org_type_counts'] = list(count) | ||
|
||
self.send(text_data=json.dumps(data)) | ||
|
||
@receiver(post_delete, sender=User) | ||
@receiver(post_delete, sender=LearningCircle) | ||
@receiver(post_delete, sender=InterestGroup) | ||
def user_post_delete(sender, instance, created, **kwargs): | ||
data = {} | ||
|
||
if sender == User: | ||
count = User.objects.all().count() | ||
data['members'] = count | ||
|
||
elif sender == LearningCircle: | ||
count = LearningCircle.objects.all().count() | ||
data['learning_circle_count'] = count | ||
|
||
elif sender == InterestGroup: | ||
count = InterestGroup.objects.all().count() | ||
data['ig_count'] = count | ||
|
||
elif sender == UserRoleLink: | ||
count = UserRoleLink.objects.filter( | ||
role__title__in=["Mentor", "Enabler"]).values( | ||
'role__title').annotate(role_count=Coalesce(Count('role__title'), 0)) | ||
data['enablers_mentors_count'] = list(count) | ||
|
||
elif sender == Organization: | ||
count = Organization.objects.filter( | ||
org_type__in=[OrganizationType.COLLEGE.value, OrganizationType.COMPANY.value, | ||
OrganizationType.COMMUNITY.value] | ||
).values('org_type').annotate(org_count=Coalesce(Count('org_type'), 0)) | ||
data['org_type_counts'] = list(count) | ||
|
||
self.send(text_data=json.dumps(data)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.urls import path | ||
from . import common_consumer | ||
|
||
urlpatterns = [ | ||
path("landing-stats/", common_consumer.GlobalCount.as_asgi()) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.