Browse Source

Experiment with file uploads, related to https://gitlab.com/glitchtip/glitchtip/-/issues/13

David Burke 3 years ago
parent
commit
315af98567

+ 2 - 0
.gitignore

@@ -118,3 +118,5 @@ dmypy.json
 .pyre/
 
 docker-compose.override.yml
+dump.sql
+uploads

+ 23 - 0
alerts/migrations/0004_auto_20210411_1913.py

@@ -0,0 +1,23 @@
+# Generated by Django 3.2 on 2021-04-11 19:13
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('alerts', '0003_auto_20210327_1648'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='notification',
+            name='created',
+            field=models.DateTimeField(auto_now_add=True, db_index=True),
+        ),
+        migrations.AlterField(
+            model_name='projectalert',
+            name='created',
+            field=models.DateTimeField(auto_now_add=True, db_index=True),
+        ),
+    ]

+ 3 - 4
alerts/models.py

@@ -1,10 +1,11 @@
 from django.db import models
 from django.utils.translation import gettext_lazy as _
+from glitchtip.base_models import CreatedModel
 from .email import send_email_notification
 from .webhooks import send_webhook_notification
 
 
-class ProjectAlert(models.Model):
+class ProjectAlert(CreatedModel):
     """
     Example: Send notification when project has 15 events in 5 minutes.
     """
@@ -12,7 +13,6 @@ class ProjectAlert(models.Model):
     project = models.ForeignKey("projects.Project", on_delete=models.CASCADE)
     timespan_minutes = models.PositiveSmallIntegerField(blank=True, null=True)
     quantity = models.PositiveSmallIntegerField(blank=True, null=True)
-    created = models.DateTimeField(auto_now_add=True)
 
 
 class AlertRecipient(models.Model):
@@ -36,8 +36,7 @@ class AlertRecipient(models.Model):
             send_webhook_notification(notification, self.url)
 
 
-class Notification(models.Model):
-    created = models.DateField(auto_now_add=True)
+class Notification(CreatedModel):
     project_alert = models.ForeignKey(ProjectAlert, on_delete=models.CASCADE)
     is_sent = models.BooleanField(default=False)
     issues = models.ManyToManyField("issues.Issue")

+ 18 - 0
api_tokens/migrations/0003_alter_apitoken_created.py

@@ -0,0 +1,18 @@
+# Generated by Django 3.2 on 2021-04-11 19:13
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('api_tokens', '0002_auto_20200821_1446'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='apitoken',
+            name='created',
+            field=models.DateTimeField(auto_now_add=True, db_index=True),
+        ),
+    ]

+ 3 - 2
api_tokens/models.py

@@ -7,12 +7,14 @@ from django.db import models
 
 from bitfield import BitField
 
+from glitchtip.base_models import CreatedModel
+
 
 def generate_token():
     return binascii.hexlify(os.urandom(20)).decode()
 
 
-class APIToken(models.Model):
+class APIToken(CreatedModel):
     """
     Ideas borrowed from rest_framework.authtoken and sentry.apitoken
     """
@@ -42,7 +44,6 @@ class APIToken(models.Model):
             "member:admin",
         )
     )
-    created = models.DateTimeField(auto_now_add=True)
 
     def __str__(self):
         return self.token

+ 3 - 4
environments/models.py

@@ -1,25 +1,24 @@
 from django.db import models
+from glitchtip.base_models import CreatedModel
 
 
-class EnvironmentProject(models.Model):
+class EnvironmentProject(CreatedModel):
     project = models.ForeignKey("projects.Project", on_delete=models.CASCADE)
     environment = models.ForeignKey(
         "environments.Environment", on_delete=models.CASCADE
     )
     is_hidden = models.BooleanField(default=False)
-    created = models.DateTimeField(auto_now_add=True, db_index=True)
 
     class Meta:
         unique_together = ("project", "environment")
 
 
-class Environment(models.Model):
+class Environment(CreatedModel):
     name = models.CharField(max_length=256)
     organization = models.ForeignKey(
         "organizations_ext.Organization", on_delete=models.CASCADE
     )
     projects = models.ManyToManyField("projects.Project", through=EnvironmentProject)
-    created = models.DateTimeField(auto_now_add=True, db_index=True)
 
     class Meta:
         unique_together = ("organization", "name")

+ 2 - 2
events/models.py

@@ -2,12 +2,12 @@ import uuid
 from django.db import models
 from django.contrib.postgres.fields import HStoreField
 from user_reports.models import UserReport
+from glitchtip.base_models import CreatedModel
 from glitchtip.model_utils import FromStringIntegerChoices
 
 
-class AbstractEvent(models.Model):
+class AbstractEvent(CreatedModel):
     event_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
-    created = models.DateTimeField(auto_now_add=True, db_index=True)
     data = models.JSONField(help_text="General event data that is searchable")
     timestamp = models.DateTimeField(
         blank=True,

+ 0 - 0
files/__init__.py


+ 9 - 0
files/admin.py

@@ -0,0 +1,9 @@
+from django.contrib import admin
+from .models import FileBlob
+
+
+class FileBlobAdmin(admin.ModelAdmin):
+    pass
+
+
+admin.site.register(FileBlob, FileBlobAdmin)

+ 6 - 0
files/apps.py

@@ -0,0 +1,6 @@
+from django.apps import AppConfig
+
+
+class FilesConfig(AppConfig):
+    default_auto_field = 'django.db.models.BigAutoField'
+    name = 'files'

Some files were not shown because too many files changed in this diff