diff --git a/.gitignore b/.gitignore index a70c028..018df26 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,10 @@ cloud/migrations/* !cloud/migrations/__init__.py cloud/__pycache__/* +chat/migrations/* +!chat/migrations/__init__.py +chat/__pycache__/* + notificsys/migrations/* !notificsys/migrations/__init__.py notificsys/__pycache__/* diff --git a/api/views.py b/api/views.py index 1b9af62..2b8176e 100644 --- a/api/views.py +++ b/api/views.py @@ -7,6 +7,8 @@ from rest_framework import serializers from .serializers import StandardsSerializer from rest_framework.decorators import api_view, permission_classes from rest_framework import status +from rest_framework.authentication import SessionAuthentication, BasicAuthentication, TokenAuthentication +from rest_framework.decorators import authentication_classes class HelloView(APIView): permission_classes = (IsAuthenticated,) # <-- And here diff --git a/chat/__init__.py b/chat/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/chat/admin.py b/chat/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/chat/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/chat/apps.py b/chat/apps.py new file mode 100644 index 0000000..8ebb9f0 --- /dev/null +++ b/chat/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class ChatConfig(AppConfig): + name = 'chat' diff --git a/chat/migrations/__init__.py b/chat/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/chat/models.py b/chat/models.py new file mode 100644 index 0000000..dd56b89 --- /dev/null +++ b/chat/models.py @@ -0,0 +1,56 @@ +from django.db import models +from django.contrib.auth.models import User +from users.models import Agency +from django.urls import reverse +from django.utils import timezone + + +''' + +MODEL ChatMessage + + +''' +class ChatMessage(models.Model): + author = models.ForeignKey(User, on_delete=models.CASCADE) + content = models.CharField(max_length=5000, blank=False, default="") + sendtime = models.DateTimeField(default=timezone.now, blank=True) + room = models.ForeignKey("ChatRoom", on_delete=models.CASCADE) +''' + +Model ChatRoom + +''' + +class ChatRoom(models.Model): + + creator = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True) + ''' + chatroomtype + + 0 - User-User-Chat + 1 - Group-Chat + + ''' + chatroomtype = models.IntegerField(default=0) + roomname = models.CharField(max_length=200, blank=False, default="") + # This field is for random-String Django Channels + roomname_channel = models.CharField(max_length=200, blank=False) + chatmembers = models.ManyToManyField(User, blank=True, related_name='users_in_chatroom') + chatroom_createddate = models.DateTimeField(blank=True) + chatmember_single = models.ForeignKey(User, related_name='singleuserchat', on_delete=models.CASCADE, null=True, blank=True) + ''' + VIEWSTATUS + + 0 - Hide and Close + 1 - Hide, but visible in base.html + 2 - Full visible + + ''' + viewstatus = models.IntegerField(default=True) + messages = models.ManyToManyField("ChatMessage", blank=True, related_name='all_chatmessages') + + def __str__(self): + return f'{self.roomname}' + + diff --git a/chat/templates/chat/chat_allusers.html b/chat/templates/chat/chat_allusers.html new file mode 100644 index 0000000..3b4b3db --- /dev/null +++ b/chat/templates/chat/chat_allusers.html @@ -0,0 +1,47 @@ + +