diff --git a/past3d/settings.py b/past3d/settings.py index 5bdddee..826cfef 100644 --- a/past3d/settings.py +++ b/past3d/settings.py @@ -75,12 +75,12 @@ STATIC_ROOT = os.path.join(BASE_DIR, "static") STATIC_URL = '/static/' # Additional locations of static files -STATICFILES_DIRS = ( +STATICFILES_DIRS = [ os.path.join(BASE_DIR, "static_common"), # Put strings here, like "/home/html/static" or "C:/www/django/static". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. -) +] # List of finder classes that know how to find static files in # various locations. @@ -93,34 +93,56 @@ STATICFILES_FINDERS = ( # Make this unique, and don't share it with anybody. SECRET_KEY = 'InsertSomethingSecretHereBeforeDoingProduktion' -# List of callables that know how to import templates from various sources. -TEMPLATE_LOADERS = ( - 'django.template.loaders.filesystem.Loader', - 'django.template.loaders.app_directories.Loader', - # 'django.template.loaders.eggs.Loader', -) +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [os.path.join(BASE_DIR, 'templates'),], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] -MIDDLEWARE_CLASSES = ( - 'django.middleware.common.CommonMiddleware', +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', - # Uncomment the next line for simple clickjacking protection: - # 'django.middleware.clickjacking.XFrameOptionsMiddleware', -) + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] ROOT_URLCONF = 'past3d.urls' # Python dotted path to the WSGI application used by Django's runserver. WSGI_APPLICATION = 'past3d.wsgi.application' -TEMPLATE_DIRS = ( - os.path.join(BASE_DIR, 'templates'), - # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". - # Always use forward slashes, even on Windows. - # Don't forget to use absolute paths, not relative paths. -) + +# Password validation +# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + INSTALLED_APPS = ( 'django_extensions', @@ -173,3 +195,5 @@ LOGGING = { }, } } + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' \ No newline at end of file diff --git a/past3d/urls.py b/past3d/urls.py index b57a8b9..e668604 100644 --- a/past3d/urls.py +++ b/past3d/urls.py @@ -17,3 +17,4 @@ urlpatterns = [ ] urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) +urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) diff --git a/pastebin/migrations/0001_initial.py b/pastebin/migrations/0001_initial.py new file mode 100644 index 0000000..893b21c --- /dev/null +++ b/pastebin/migrations/0001_initial.py @@ -0,0 +1,36 @@ +# Generated by Django 4.2.3 on 2023-07-12 18:10 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import pastebin.models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Geometry', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=128)), + ('description', models.TextField(blank=True)), + ('date', models.DateTimeField(auto_now_add=True)), + ('expiration', models.IntegerField(choices=[(0, 'one hour'), (1, 'one day'), (2, 'one week'), (3, 'one month'), (4, 'forever')], default=0)), + ('public', models.BooleanField(default=True)), + ('polycount', models.IntegerField(blank=True, default=0)), + ('width', models.FloatField(blank=True, default=0)), + ('depth', models.FloatField(blank=True, default=0)), + ('height', models.FloatField(blank=True, default=0)), + ('file', models.FileField(upload_to=pastebin.models.model_path)), + ('sourcefile', models.FileField(blank=True, upload_to=pastebin.models.source_path)), + ('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/pastebin/migrations/__init__.py b/pastebin/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pastebin/models.py b/pastebin/models.py index be7793f..74a0986 100644 --- a/pastebin/models.py +++ b/pastebin/models.py @@ -12,19 +12,26 @@ from django.db import models vertex_pattern = re.compile(r'vertex\s+([0-9.e+-]+)\s+([0-9.e+-]+)\s+([0-9.e+-]+)') -def safe_upload_path(base_dir): - def generate_path(instance, filename): - ext = os.path.splitext(filename)[1] +def model_path(instance, filename): + ext = os.path.splitext(filename)[1] + md5sum = md5() + md5sum.update(instance.name.encode('utf-8') + + str(datetime.now()).encode('utf-8') + + filename.encode('utf-8')) + randomname = md5sum.hexdigest() + return os.path.join('models', '%s%s' % (randomname, ext)) - md5sum = md5() - md5sum.update(instance.name + str(datetime.now()) + filename) - randomname = md5sum.hexdigest() +def source_path(instance, filename): + ext = os.path.splitext(filename)[1] + md5sum = md5() + md5sum.update(instance.name.encode('utf-8') + + str(datetime.now()).encode('utf-8') + + filename.encode('utf-8')) + randomname = md5sum.hexdigest() + return os.path.join('sources', '%s%s' % (randomname, ext)) - return os.path.join(base_dir, '%s%s' % (randomname, ext)) - - return generate_path class Geometry(models.Model): @@ -55,8 +62,8 @@ class Geometry(models.Model): width = models.FloatField(blank=True, default=0) depth = models.FloatField(blank=True, default=0) height = models.FloatField(blank=True, default=0) - file = models.FileField(upload_to=safe_upload_path('models')) - sourcefile = models.FileField(upload_to=safe_upload_path('sources'), blank=True) + file = models.FileField(upload_to=model_path) + sourcefile = models.FileField(upload_to=source_path, blank=True) def get_absolute_url(self): return reverse('geometry_details', kwargs={'id': self.pk}) diff --git a/pastebin/templates/pastebin/geometry.html b/pastebin/templates/pastebin/geometry.html index a74930c..35ce5ae 100644 --- a/pastebin/templates/pastebin/geometry.html +++ b/pastebin/templates/pastebin/geometry.html @@ -1,4 +1,5 @@ {% extends "base.html" %} +{% load static %} {% block title %} {{ geometry.name }} {% endblock %} @@ -12,9 +13,9 @@ } - - - + + +