From 32ea7a408fdd9492f3502f67f0b4529853880aa1 Mon Sep 17 00:00:00 2001 From: emile Date: Sun, 21 Jul 2024 21:43:54 +0300 Subject: [PATCH] new --- osinaweb/db.sqlite3 | Bin 1675264 -> 1683456 bytes .../osichat/__pycache__/admin.cpython-310.pyc | Bin 511 -> 534 bytes .../__pycache__/consumers.cpython-310.pyc | Bin 3278 -> 4482 bytes .../__pycache__/models.cpython-310.pyc | Bin 2758 -> 2811 bytes .../__pycache__/routing.cpython-310.pyc | Bin 359 -> 411 bytes osinaweb/osichat/admin.py | 2 +- osinaweb/osichat/consumers.py | 44 +++++++++++++++++- .../migrations/0011_visitor_country.py | 18 +++++++ .../0012_alter_visitor_reference.py | 18 +++++++ .../0011_visitor_country.cpython-310.pyc | Bin 0 -> 666 bytes ...12_alter_visitor_reference.cpython-310.pyc | Bin 0 -> 646 bytes osinaweb/osichat/models.py | 3 +- osinaweb/osichat/routing.py | 1 + osinaweb/static/js/osichat/conversation.js | 1 - osinaweb/static/js/osichat/visitors.js | 31 ++++++++++++ 15 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 osinaweb/osichat/migrations/0011_visitor_country.py create mode 100644 osinaweb/osichat/migrations/0012_alter_visitor_reference.py create mode 100644 osinaweb/osichat/migrations/__pycache__/0011_visitor_country.cpython-310.pyc create mode 100644 osinaweb/osichat/migrations/__pycache__/0012_alter_visitor_reference.cpython-310.pyc create mode 100644 osinaweb/static/js/osichat/visitors.js diff --git a/osinaweb/db.sqlite3 b/osinaweb/db.sqlite3 index 20b52e67cf96f7c41fa99c4cf2d6dbd56644102e..e8acf2db07c849d814c792e440158bb636fa93c9 100644 GIT binary patch delta 2275 zcmb_dYitx%6rR^UW?$2#Y-b7xTNI>jJDof48AD{jCL$D!prpRmT9&Y|+1+lZCD@d9 zWwqAE(9+nE5)zy6$3Lc~38OI~QU8b`NV}ux@Mnm*$TefVi(KJl*on+3v z_k8z$=iGDq-#O4fb6|LNxCO)T(|}VL7z`sXj5J8#S6D##!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we=%L!fR1P<(`t!zK+=!T z7nw)sV+`u!Dak%+y`2 z^TZmas>G!Zwu)py5ukKY3(q?V()~(*0ey{6Dx;*c6Bw@9ZFaq`-F5NUU8mc+X8#8l CU@qSP delta 1246 zcma)5zi-n(6!yi5eR1qIN|TVb34)fiaw#E{1tdW92MDARhGxnVIq^{(5?h>8gczEE zxzo)^@D~6Q8#9Oj!EOnOmANAWymzT8R2+n*`}}AM z{?Lw3JEAxkKx~Uz-*2F$3n@yWUNq?{3 zZ`hXjK<sz;?BoBfCH!;F2K+75g9k0*Y{@$R&I7iCZ zd@68&*@Y;IDmlo;Bw3a4ig-;cVkvcZglSFEJ_l!f9^ouNqz#y)LzR31L6#*W%hC%x ze?nCj!4;z%j;oR-S*!}~b`|lCmV~C=xpWRbp@p$MI0I+0A~KIL^_&=KtBY|>SO#y* zmoFhKi!a)N!e1Q3?r4wDwOfhsyNU~*QN5bR30*a7+d`n zaK~hhtDh%RsC-2h|CheujYS)iv%nDJ;_CwzhR!bI=V2={oZ-;vJ{(M?d1@W0SN67f&69C7Pe>VP@n`5N$J*c9E_pn7_47x)v@MERd!R0cnqd~xyX9=$> z;tef}_vtN}N5lRf>{ zv8AvDGib8E1ZmJ@yv0(GSd#IQ5yD~AsuC$L*3U1_OwLFw(J#v^&Me6=I+%pCs#I>{*m diff --git a/osinaweb/osichat/admin.py b/osinaweb/osichat/admin.py index 44f8b1bf..50a8a297 100644 --- a/osinaweb/osichat/admin.py +++ b/osinaweb/osichat/admin.py @@ -1,7 +1,7 @@ from django.contrib import admin from .models import * # Register your models here. - +admin.site.register(Visitor) admin.site.register(ChatRoom) admin.site.register(ChatRoomGuest) admin.site.register(ChatMember) diff --git a/osinaweb/osichat/consumers.py b/osinaweb/osichat/consumers.py index f0c070e8..07b7edf2 100644 --- a/osinaweb/osichat/consumers.py +++ b/osinaweb/osichat/consumers.py @@ -6,6 +6,49 @@ from asgiref.sync import async_to_sync from django.shortcuts import get_object_or_404 +class OsitcomVisitor(WebsocketConsumer): + def connect(self): + self.accept() + async_to_sync(self.channel_layer.group_add)( + 'ositcom_visitors', self.channel_name + ) + self.visitor = None + + def disconnect(self, close_code): + if self.visitor: + self.visitor.left_date = datetime.now() + self.visitor.save() + async_to_sync(self.channel_layer.group_discard)( + 'ositcom_visitors', self.channel_name + ) + def receive(self, text_data): + text_data_json = json.loads(text_data) + event_type = text_data_json.get('event_type') + if event_type == 'new_visitor': + event = { + 'type': 'new_visitor_handler', + 'session_id': text_data_json.get('session_id'), + 'ip_address': text_data_json.get('ip_address'), + 'country': text_data_json.get('country'), + 'url': text_data_json.get('url'), + } + async_to_sync(self.channel_layer.group_send)( + 'ositcom_visitors', event + ) + + def new_visitor_handler(self, event): + visitor = Visitor.objects.create( + session_id = event['session_id'], + ip_address = event['ip_address'], + country = event['country'], + url = event['url'], + visit_date = datetime.now(), + ) + self.visitor = visitor + + + + class OsitcomChatRoom(WebsocketConsumer): def connect(self): @@ -105,7 +148,6 @@ class OsitcomChatRoom(WebsocketConsumer): context = { 'chat_message': chat_message, } - print('lokf') html = render_to_string("partials/message.html", context=context) self.send(text_data=json.dumps({ 'event_type': 'send_message', diff --git a/osinaweb/osichat/migrations/0011_visitor_country.py b/osinaweb/osichat/migrations/0011_visitor_country.py new file mode 100644 index 00000000..6fde18b2 --- /dev/null +++ b/osinaweb/osichat/migrations/0011_visitor_country.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.5 on 2024-07-21 17:09 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('osichat', '0010_visitor_left_date_visitor_visit_date'), + ] + + operations = [ + migrations.AddField( + model_name='visitor', + name='country', + field=models.CharField(max_length=15, null=True), + ), + ] diff --git a/osinaweb/osichat/migrations/0012_alter_visitor_reference.py b/osinaweb/osichat/migrations/0012_alter_visitor_reference.py new file mode 100644 index 00000000..1935ef65 --- /dev/null +++ b/osinaweb/osichat/migrations/0012_alter_visitor_reference.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.5 on 2024-07-21 17:25 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('osichat', '0011_visitor_country'), + ] + + operations = [ + migrations.AlterField( + model_name='visitor', + name='reference', + field=models.URLField(blank=True, null=True), + ), + ] diff --git a/osinaweb/osichat/migrations/__pycache__/0011_visitor_country.cpython-310.pyc b/osinaweb/osichat/migrations/__pycache__/0011_visitor_country.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0c6636752f7164206e50f8875e79f81a86777308 GIT binary patch literal 666 zcmYjPJ#W-N5Zw>^>^mg_QG}KX$<6uFBXkG^O$bGxakJWZ=I(r~Kk)iUu7);0A)=!E5J>qd18Xl&_A4^Kj1PG+a%kQE$Q zA%HJ=Au(FVo&ZPd1R{uGbR{6Ul2l6}C8Dt#zyHrbbV+Nga-|2C&1T0l^|i9q(DusU zVo;z5yvu}2NV#O+<&v`9G(*3=c|>!348!Y7`nFjPD;G5zV=_q#`6X1NYowg_@uETl zr!-2cLS891QHuID1}Q#J>dQtO-|G=zhYes;R%m-cOfG!|@YdhaOAp7dSGo__P1+9k z>iuN>5mkfxbD4j#*xMZI${-q3Z83j?_Vdto`I$CV{p>_{9(>fnAjO|ErwjJH8WZugkRC_Wm)9$m|nxDHAffjbgzCKj6{d^fuH_v&fBi i98)+CJBH0d@qUY4^px&#>5H9OFX{a;>p32aBl!<$YrEC} literal 0 HcmV?d00001 diff --git a/osinaweb/osichat/migrations/__pycache__/0012_alter_visitor_reference.cpython-310.pyc b/osinaweb/osichat/migrations/__pycache__/0012_alter_visitor_reference.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cf3064491af12fa6d3d2ff2fb0e63635f00e748c GIT binary patch literal 646 zcmYjP&2H2%5cW^9$wsY&5cJFmDVI&l8KELoa4AKi^pcC^jb|5cojBN8s=Xo6Q>9+G z^8mb(ubg-VBvi)P(sm+`=9`(!H#4@~-7N^p_oE++D@w?(2p&p;;1G|0j!F?l4QXjj zTUIkl-V((Wza)wSUGZZOx|ww(`?)+#W*iJ^y*Avnb2XQ+VG zRFRq~x}-ISWR*q&n5;6D;Fn%AHM!;(%TTY&wzB9^}6{ahwx;7|KLD;(OwVM ziN>zG!EHiz>j+Z^3vkdi@Dcw?=SFttA?en}lpK4GeTq)DfWD~Hg$AQe%4x{O=ocas zLSWw70NOi3d|pcvb0bpFL#MF12JaXS6^hqp0QV+VaXdQmvk%8342A9Cc0)gjdy2tP z{rOs*d2qghRvQ3g^aiRU@aKc=t5a!o`|Mcu5xmD48{1YmdMB$6E=EJGWVf_i=LO88 z5f@Y4-$#WjdLd+N>~2waYnk;M7cYK-$3I4u6ULL9BxRJ*9h&^jZ^rmZnS|+={&KsvSNPV5j~tKK9{&eI0ki!8 literal 0 HcmV?d00001 diff --git a/osinaweb/osichat/models.py b/osinaweb/osichat/models.py index 16b4eaf4..b06dc644 100644 --- a/osinaweb/osichat/models.py +++ b/osinaweb/osichat/models.py @@ -5,8 +5,9 @@ from osinacore.models import * class Visitor(models.Model): session_id = models.CharField(max_length=300) ip_address = models.CharField(max_length=300) + country = models.CharField(max_length=15, null=True) url = models.URLField() - reference = models.URLField() + reference = models.URLField(null=True, blank=True) visit_date = models.DateTimeField(null=True) left_date = models.DateTimeField(null=True) diff --git a/osinaweb/osichat/routing.py b/osinaweb/osichat/routing.py index 1d4d14d1..5439cef6 100644 --- a/osinaweb/osichat/routing.py +++ b/osinaweb/osichat/routing.py @@ -2,6 +2,7 @@ from django.urls import path from .consumers import * websocket_urlpatterns = [ + path("ws/osichat/visitors/", OsitcomVisitor.as_asgi()), path("ws/osichat//", OsitcomChatRoom.as_asgi()), ] \ No newline at end of file diff --git a/osinaweb/static/js/osichat/conversation.js b/osinaweb/static/js/osichat/conversation.js index a09e4ad3..b7062555 100644 --- a/osinaweb/static/js/osichat/conversation.js +++ b/osinaweb/static/js/osichat/conversation.js @@ -2,7 +2,6 @@ const chat_ws_scheme = window.location.protocol === "https:" ? "wss" : "ws"; const domain = "192.168.1.111:8000"; const sessionId = document.getElementById('session_id').textContent.trim(); -console.log(sessionId); const osichatSocketUrl = `${chat_ws_scheme}://${domain}/ws/osichat/${sessionId}/`; const osichatSocket = new WebSocket(osichatSocketUrl); diff --git a/osinaweb/static/js/osichat/visitors.js b/osinaweb/static/js/osichat/visitors.js new file mode 100644 index 00000000..eb4dc199 --- /dev/null +++ b/osinaweb/static/js/osichat/visitors.js @@ -0,0 +1,31 @@ + +const visitors_ws_scheme = window.location.protocol === "https:" ? "wss" : "ws"; +const my_domain = "192.168.1.111:8000"; +const session_id = document.getElementById('session_id').textContent.trim(); +const client_ip = document.getElementById('client_ip').textContent.trim(); +const client_country = document.getElementById('client_country').textContent.trim(); +const current_url = document.getElementById('current_url').textContent.trim(); +const visitorsSocketUrl = `${chat_ws_scheme}://${domain}/ws/osichat/visitors/`; +const visitorsSocket = new WebSocket(visitorsSocketUrl); + + +visitorsSocket.onopen = () => { + console.log('WebSocket connection to visitors established'); + const event_message = { + 'event_type': 'new_visitor', + 'session_id': session_id, + 'ip_address': client_ip, + 'country': client_country, + 'url': current_url + }; + visitorsSocket.send(JSON.stringify(event_message)); +}; + + +visitorsSocket.onclose = () => { + console.log('WebSocket connection to visitors closed'); +}; + +visitorsSocket.onerror = (error) => { + console.log('WebSocket error:', error); +};