diff options
author | Andrew Godwin | 2022-11-05 14:17:27 -0600 |
---|---|---|
committer | Andrew Godwin | 2022-11-05 14:17:27 -0600 |
commit | d77dcf62b4005a0f36ef2fa7ba6d3651d2ef38d7 (patch) | |
tree | dd356a933b8179a22e5da6e938acd96a175ac0d6 /statuses | |
download | takahe-d77dcf62b4005a0f36ef2fa7ba6d3651d2ef38d7.tar.gz takahe-d77dcf62b4005a0f36ef2fa7ba6d3651d2ef38d7.tar.bz2 takahe-d77dcf62b4005a0f36ef2fa7ba6d3651d2ef38d7.zip |
Initial commit (users and statuses)
Diffstat (limited to 'statuses')
-rw-r--r-- | statuses/__init__.py | 0 | ||||
-rw-r--r-- | statuses/admin.py | 8 | ||||
-rw-r--r-- | statuses/apps.py | 6 | ||||
-rw-r--r-- | statuses/migrations/0001_initial.py | 56 | ||||
-rw-r--r-- | statuses/migrations/__init__.py | 0 | ||||
-rw-r--r-- | statuses/models/__init__.py | 1 | ||||
-rw-r--r-- | statuses/models/status.py | 35 | ||||
-rw-r--r-- | statuses/views/__init__.py | 0 | ||||
-rw-r--r-- | statuses/views/home.py | 35 |
9 files changed, 141 insertions, 0 deletions
diff --git a/statuses/__init__.py b/statuses/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/statuses/__init__.py diff --git a/statuses/admin.py b/statuses/admin.py new file mode 100644 index 0000000..040a0eb --- /dev/null +++ b/statuses/admin.py @@ -0,0 +1,8 @@ +from django.contrib import admin + +from statuses.models import Status + + +@admin.register(Status) +class StatusAdmin(admin.ModelAdmin): + pass diff --git a/statuses/apps.py b/statuses/apps.py new file mode 100644 index 0000000..b0a694e --- /dev/null +++ b/statuses/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class StatusesConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "statuses" diff --git a/statuses/migrations/0001_initial.py b/statuses/migrations/0001_initial.py new file mode 100644 index 0000000..7b8eced --- /dev/null +++ b/statuses/migrations/0001_initial.py @@ -0,0 +1,56 @@ +# Generated by Django 4.1.3 on 2022-11-05 19:43 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ("users", "0001_initial"), + ] + + operations = [ + migrations.CreateModel( + name="Status", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("local", models.BooleanField()), + ("uri", models.CharField(blank=True, max_length=500, null=True)), + ( + "visibility", + models.IntegerField( + choices=[ + (0, "Public"), + (1, "Unlisted"), + (2, "Followers"), + (3, "Mentioned"), + ], + default=0, + ), + ), + ("text", models.TextField()), + ("created", models.DateTimeField(auto_now_add=True)), + ("updated", models.DateTimeField(auto_now=True)), + ("deleted", models.DateTimeField(blank=True, null=True)), + ( + "identity", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="statuses", + to="users.identity", + ), + ), + ], + ), + ] diff --git a/statuses/migrations/__init__.py b/statuses/migrations/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/statuses/migrations/__init__.py diff --git a/statuses/models/__init__.py b/statuses/models/__init__.py new file mode 100644 index 0000000..84098eb --- /dev/null +++ b/statuses/models/__init__.py @@ -0,0 +1 @@ +from .status import Status # noqa diff --git a/statuses/models/status.py b/statuses/models/status.py new file mode 100644 index 0000000..2e17a19 --- /dev/null +++ b/statuses/models/status.py @@ -0,0 +1,35 @@ +from django.db import models + + +class Status(models.Model): + class StatusVisibility(models.IntegerChoices): + public = 0 + unlisted = 1 + followers = 2 + mentioned = 3 + + identity = models.ForeignKey( + "users.Identity", + on_delete=models.PROTECT, + related_name="statuses", + ) + + local = models.BooleanField() + uri = models.CharField(max_length=500, blank=True, null=True) + visibility = models.IntegerField( + choices=StatusVisibility.choices, + default=StatusVisibility.public, + ) + text = models.TextField() + + created = models.DateTimeField(auto_now_add=True) + updated = models.DateTimeField(auto_now=True) + deleted = models.DateTimeField(null=True, blank=True) + + @classmethod + def create_local(cls, identity, text: str): + return cls.objects.create( + identity=identity, + text=text, + local=True, + ) diff --git a/statuses/views/__init__.py b/statuses/views/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/statuses/views/__init__.py diff --git a/statuses/views/home.py b/statuses/views/home.py new file mode 100644 index 0000000..b9b98d2 --- /dev/null +++ b/statuses/views/home.py @@ -0,0 +1,35 @@ +from django import forms +from django.shortcuts import redirect +from django.utils.decorators import method_decorator +from django.views.generic import FormView + +from core.forms import FormHelper +from statuses.models import Status +from users.decorators import identity_required + + +@method_decorator(identity_required, name="dispatch") +class Home(FormView): + + template_name = "statuses/home.html" + + class form_class(forms.Form): + text = forms.CharField() + + helper = FormHelper(submit_text="Post") + + def get_context_data(self): + context = super().get_context_data() + context.update( + { + "statuses": self.request.identity.statuses.all()[:100], + } + ) + return context + + def form_valid(self, form): + Status.create_local( + identity=self.request.identity, + text=form.cleaned_data["text"], + ) + return redirect(".") |