enable user tokens
Run Tests / Run Tests (push) Failing after 39s Details

This commit is contained in:
James Ravenscroft 2024-12-18 21:35:31 +00:00
parent 9496c637ce
commit dee74d7ea4
5 changed files with 67 additions and 4 deletions

View File

@ -45,6 +45,9 @@ INSTALLED_APPS = [
"webui", "webui",
"markdown_deux", "markdown_deux",
"markdownify.apps.MarkdownifyConfig", "markdownify.apps.MarkdownifyConfig",
"rest_framework",
"rest_framework.authtoken",
"django_filters",
] ]
MIDDLEWARE = [ MIDDLEWARE = [
@ -57,6 +60,14 @@ MIDDLEWARE = [
"django.middleware.clickjacking.XFrameOptionsMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware",
] ]
REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
]
}
ROOT_URLCONF = "penparse.urls" ROOT_URLCONF = "penparse.urls"
TEMPLATES = [ TEMPLATES = [
@ -150,6 +161,6 @@ CELERY_BROKER_URL = "amqp://guest:guest@localhost/"
OPENAI_API_BASE = os.getenv("OPENAI_API_BASE") OPENAI_API_BASE = os.getenv("OPENAI_API_BASE")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
#OPENAI_API_KEY = "test" # OPENAI_API_KEY = "test"
OPENAI_MODEL = os.getenv("OPENAI_MODEL", "openai/gpt-4o") OPENAI_MODEL = os.getenv("OPENAI_MODEL", "openai/gpt-4o")
#OPENAI_MODEL="ollama/llama3.2-vision" # OPENAI_MODEL="ollama/llama3.2-vision"

View File

@ -3,7 +3,10 @@ from django.contrib.auth.base_user import BaseUserManager
from django.db import models from django.db import models
from uuid import uuid4 from uuid import uuid4
from email.header import Charset from django.conf import settings
from django.db.models.signals import post_save
from django.dispatch import receiver
from rest_framework.authtoken.models import Token
class UserManager(BaseUserManager): class UserManager(BaseUserManager):
@ -57,7 +60,8 @@ class ImageMemo(models.Model):
image = models.ImageField(upload_to="uploads/%Y/%m/%d") image = models.ImageField(upload_to="uploads/%Y/%m/%d")
content = models.TextField() content = models.TextField()
author = models.ForeignKey("User", on_delete=models.CASCADE, related_name="memos") author = models.ForeignKey(
"User", on_delete=models.CASCADE, related_name="memos")
model_name = models.CharField(max_length=255, null=True) model_name = models.CharField(max_length=255, null=True)
@ -89,3 +93,10 @@ class User(AbstractUser):
def __str__(self): def __str__(self):
"""Return string representation of our user""" """Return string representation of our user"""
return self.email return self.email
@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def create_auth_token(sender, instance=None, created=False, **kwargs):
"""Create and save a token when a user is created."""
if created:
Token.objects.create(user=instance)

11
penparse/webui/signals.py Normal file
View File

@ -0,0 +1,11 @@
from django.conf import settings
from django.db.models.signals import post_save
from django.dispatch import receiver
from rest_framework.authtoken.models import Token
@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def create_auth_token(sender, instance=None, created=False, **kwargs):
if created:
Token.objects.create(user=instance)

View File

@ -6,9 +6,11 @@ readme = "README.md"
requires-python = ">=3.9" requires-python = ">=3.9"
dependencies = [ dependencies = [
"celery>=5.4.0", "celery>=5.4.0",
"django-filter>=24.3",
"django-markdown-deux>=1.0.6", "django-markdown-deux>=1.0.6",
"django-markdownify>=0.9.5", "django-markdownify>=0.9.5",
"django>=4.2.16", "django>=4.2.16",
"djangorestframework>=3.15.2",
"litellm>=1.54.1", "litellm>=1.54.1",
"loguru>=0.7.3", "loguru>=0.7.3",
"markdown>=3.7", "markdown>=3.7",

28
uv.lock
View File

@ -406,6 +406,18 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/94/2c/6b6c7e493d5ea789416918658ebfa16be7a64c77610307497ed09a93c8c4/Django-4.2.16-py3-none-any.whl", hash = "sha256:1ddc333a16fc139fd253035a1606bb24261951bbc3a6ca256717fa06cc41a898", size = 7992936 }, { url = "https://files.pythonhosted.org/packages/94/2c/6b6c7e493d5ea789416918658ebfa16be7a64c77610307497ed09a93c8c4/Django-4.2.16-py3-none-any.whl", hash = "sha256:1ddc333a16fc139fd253035a1606bb24261951bbc3a6ca256717fa06cc41a898", size = 7992936 },
] ]
[[package]]
name = "django-filter"
version = "24.3"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "django" },
]
sdist = { url = "https://files.pythonhosted.org/packages/50/bc/dc19ae39c235332926dd0efe0951f663fa1a9fc6be8430737ff7fd566b20/django_filter-24.3.tar.gz", hash = "sha256:d8ccaf6732afd21ca0542f6733b11591030fa98669f8d15599b358e24a2cd9c3", size = 144444 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/09/b1/92f1c30b47c1ebf510c35a2ccad9448f73437e5891bbd2b4febe357cc3de/django_filter-24.3-py3-none-any.whl", hash = "sha256:c4852822928ce17fb699bcfccd644b3574f1a2d80aeb2b4ff4f16b02dd49dc64", size = 95011 },
]
[[package]] [[package]]
name = "django-markdown-deux" name = "django-markdown-deux"
version = "1.0.6" version = "1.0.6"
@ -429,6 +441,18 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/1b/35/c7a4bd957b279a8e7c808116bed399b73874ed3da78689993ee76f30d9f6/django_markdownify-0.9.5-py3-none-any.whl", hash = "sha256:2c4ae44e386c209453caf5e9ea1b74f64535985d338ad2d5ad5e7089cc94be86", size = 10342 }, { url = "https://files.pythonhosted.org/packages/1b/35/c7a4bd957b279a8e7c808116bed399b73874ed3da78689993ee76f30d9f6/django_markdownify-0.9.5-py3-none-any.whl", hash = "sha256:2c4ae44e386c209453caf5e9ea1b74f64535985d338ad2d5ad5e7089cc94be86", size = 10342 },
] ]
[[package]]
name = "djangorestframework"
version = "3.15.2"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "django" },
]
sdist = { url = "https://files.pythonhosted.org/packages/2c/ce/31482eb688bdb4e271027076199e1aa8d02507e530b6d272ab8b4481557c/djangorestframework-3.15.2.tar.gz", hash = "sha256:36fe88cd2d6c6bec23dca9804bab2ba5517a8bb9d8f47ebc68981b56840107ad", size = 1067420 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/7c/b6/fa99d8f05eff3a9310286ae84c4059b08c301ae4ab33ae32e46e8ef76491/djangorestframework-3.15.2-py3-none-any.whl", hash = "sha256:2b8871b062ba1aefc2de01f773875441a961fefbf79f5eed1e32b2f096944b20", size = 1071235 },
]
[[package]] [[package]]
name = "exceptiongroup" name = "exceptiongroup"
version = "1.2.2" version = "1.2.2"
@ -998,8 +1022,10 @@ source = { virtual = "." }
dependencies = [ dependencies = [
{ name = "celery" }, { name = "celery" },
{ name = "django" }, { name = "django" },
{ name = "django-filter" },
{ name = "django-markdown-deux" }, { name = "django-markdown-deux" },
{ name = "django-markdownify" }, { name = "django-markdownify" },
{ name = "djangorestframework" },
{ name = "litellm" }, { name = "litellm" },
{ name = "loguru" }, { name = "loguru" },
{ name = "markdown" }, { name = "markdown" },
@ -1015,8 +1041,10 @@ dependencies = [
requires-dist = [ requires-dist = [
{ name = "celery", specifier = ">=5.4.0" }, { name = "celery", specifier = ">=5.4.0" },
{ name = "django", specifier = ">=4.2.16" }, { name = "django", specifier = ">=4.2.16" },
{ name = "django-filter", specifier = ">=24.3" },
{ name = "django-markdown-deux", specifier = ">=1.0.6" }, { name = "django-markdown-deux", specifier = ">=1.0.6" },
{ name = "django-markdownify", specifier = ">=0.9.5" }, { name = "django-markdownify", specifier = ">=0.9.5" },
{ name = "djangorestframework", specifier = ">=3.15.2" },
{ name = "litellm", specifier = ">=1.54.1" }, { name = "litellm", specifier = ">=1.54.1" },
{ name = "loguru", specifier = ">=0.7.3" }, { name = "loguru", specifier = ">=0.7.3" },
{ name = "markdown", specifier = ">=3.7" }, { name = "markdown", specifier = ">=3.7" },