diff --git a/django_polly/admin.py b/django_polly/admin.py index 68f0a4e..0ff27f8 100644 --- a/django_polly/admin.py +++ b/django_polly/admin.py @@ -1,9 +1,11 @@ from django.contrib import admin -from .models import Parrot, Trick, Message, SmartConversation +from .models import Parrot, Trick, Message, SmartConversation, APIKey from django.utils.html import format_html from django.urls import reverse from django import forms +from django.contrib.auth import get_user_model +User = get_user_model() # Define a custom form for Parrot model class ParrotAdminForm(forms.ModelForm): @@ -26,6 +28,13 @@ class MessageInline(admin.TabularInline): ordering = ("created_at",) +class APIKeyInline(admin.TabularInline): + model = APIKey + extra = 0 + readonly_fields = ("key", "created_at") + can_delete = False + + @admin.register(Parrot) class ParrotAdmin(admin.ModelAdmin): list_display = ('name', 'color', 'age', 'external_id', 'created_at', 'updated_at') @@ -79,3 +88,16 @@ class MessageAdmin(admin.ModelAdmin): search_fields = ("content",) date_hierarchy = "created_at" raw_id_fields = ("conversation",) + + +@admin.register(APIKey) +class APIKeyAdmin(admin.ModelAdmin): + list_display = ("key", "user", "created_at") + list_filter = ("user", "created_at") + search_fields = ("key", "user__username") + readonly_fields = ("key", "created_at") + + +@admin.register(User) +class CustomUserAdmin(admin.ModelAdmin): + inlines = [APIKeyInline] diff --git a/django_polly/models.py b/django_polly/models.py index ddd87c5..23b6fbb 100644 --- a/django_polly/models.py +++ b/django_polly/models.py @@ -45,6 +45,15 @@ class ConversationParty(models.TextChoices): ASSISTANT = 'ASSISTANT', 'Assistant' +class APIKey(CommonFieldsModel): + key = models.CharField(max_length=255, unique=True) + user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="api_keys") + created_at = models.DateTimeField(auto_now_add=True) + + def __str__(self): + return self.key + + class SmartConversation(CommonFieldsModel): user = models.ForeignKey( User, on_delete=models.CASCADE, related_name="conversations" diff --git a/django_polly/static/css/custom.css b/django_polly/static/css/custom.css index 4b8d4dc..73c8155 100644 --- a/django_polly/static/css/custom.css +++ b/django_polly/static/css/custom.css @@ -1 +1,50 @@ /* custom css goes here */ + +.fab { + position: fixed; + bottom: 20px; + right: 20px; + background-color: #4f46e5; + color: white; + border: none; + border-radius: 50%; + width: 56px; + height: 56px; + display: flex; + align-items: center; + justify-content: center; + box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2); + cursor: pointer; + transition: background-color 0.3s ease; +} + +.fab:hover { + background-color: #4338ca; +} + +.chat-container { + display: none; + position: fixed; + bottom: 80px; + right: 20px; + width: 300px; + height: 400px; + background-color: white; + border-radius: 8px; + box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2); + overflow: hidden; + z-index: 1000; +} + +.chat-header { + background-color: #4f46e5; + color: white; + padding: 10px; + text-align: center; +} + +.chat-body { + padding: 10px; + height: calc(100% - 40px); + overflow-y: auto; +} diff --git a/django_polly/templates/conversation/iframe_chat.html b/django_polly/templates/conversation/iframe_chat.html new file mode 100644 index 0000000..4c88004 --- /dev/null +++ b/django_polly/templates/conversation/iframe_chat.html @@ -0,0 +1,176 @@ + + +
+ + +