diff options
| author | 2022-08-16 21:19:53 +0400 | |
|---|---|---|
| committer | 2022-08-16 21:19:53 +0400 | |
| commit | f2374900c4c83097c105b56de02ea82d66bd9466 (patch) | |
| tree | e886551b2dc3e92397160d5dd8886fb3a42d1909 | |
| parent | Move GitHub strptime Format To Settings (diff) | |
Unify Tag Migrations & Add Commit Model
Signed-off-by: Hassan Abouelela <[email protected]>
| -rw-r--r-- | pydis_site/apps/content/migrations/0001_add_tags.py | 34 | ||||
| -rw-r--r-- | pydis_site/apps/content/migrations/0001_initial.py | 23 | ||||
| -rw-r--r-- | pydis_site/apps/content/migrations/0002_remove_tag_url_tag_group.py | 22 | ||||
| -rw-r--r-- | pydis_site/apps/content/models/__init__.py | 4 | ||||
| -rw-r--r-- | pydis_site/apps/content/models/tag.py | 36 | 
5 files changed, 72 insertions, 47 deletions
| diff --git a/pydis_site/apps/content/migrations/0001_add_tags.py b/pydis_site/apps/content/migrations/0001_add_tags.py new file mode 100644 index 00000000..2e9d8c45 --- /dev/null +++ b/pydis_site/apps/content/migrations/0001_add_tags.py @@ -0,0 +1,34 @@ +# Generated by Django 4.0.6 on 2022-08-16 16:17 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + +    initial = True + +    dependencies = [ +    ] + +    operations = [ +        migrations.CreateModel( +            name='Commit', +            fields=[ +                ('sha', models.CharField(help_text='The SHA hash of this commit.', max_length=40, primary_key=True, serialize=False)), +                ('message', models.TextField(help_text='The commit message.')), +                ('date', models.DateTimeField(help_text='The date and time the commit was created.')), +                ('author', models.TextField(help_text='The person(s) who created the commit.')), +            ], +        ), +        migrations.CreateModel( +            name='Tag', +            fields=[ +                ('last_updated', models.DateTimeField(auto_now=True, help_text='The date and time this data was last fetched.')), +                ('name', models.CharField(help_text="The tag's name.", max_length=50, primary_key=True, serialize=False)), +                ('group', models.CharField(help_text='The group the tag belongs to.', max_length=50, null=True)), +                ('body', models.TextField(help_text='The content of the tag.')), +                ('last_commit', models.OneToOneField(help_text='The commit this file was last touched in.', null=True, on_delete=django.db.models.deletion.CASCADE, to='content.commit')), +            ], +        ), +    ] diff --git a/pydis_site/apps/content/migrations/0001_initial.py b/pydis_site/apps/content/migrations/0001_initial.py deleted file mode 100644 index 15e3fc95..00000000 --- a/pydis_site/apps/content/migrations/0001_initial.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 4.0.6 on 2022-08-13 00:53 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - -    initial = True - -    dependencies = [ -    ] - -    operations = [ -        migrations.CreateModel( -            name='Tag', -            fields=[ -                ('last_updated', models.DateTimeField(auto_now=True, help_text='The date and time this data was last fetched.')), -                ('name', models.CharField(help_text="The tag's name.", max_length=50, primary_key=True, serialize=False)), -                ('body', models.TextField(help_text='The content of the tag.')), -                ('url', models.URLField(help_text='The URL to this tag on GitHub.')), -            ], -        ), -    ] diff --git a/pydis_site/apps/content/migrations/0002_remove_tag_url_tag_group.py b/pydis_site/apps/content/migrations/0002_remove_tag_url_tag_group.py deleted file mode 100644 index e59077f0..00000000 --- a/pydis_site/apps/content/migrations/0002_remove_tag_url_tag_group.py +++ /dev/null @@ -1,22 +0,0 @@ -# Generated by Django 4.0.6 on 2022-08-13 23:48 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - -    dependencies = [ -        ('content', '0001_initial'), -    ] - -    operations = [ -        migrations.RemoveField( -            model_name='tag', -            name='url', -        ), -        migrations.AddField( -            model_name='tag', -            name='group', -            field=models.CharField(help_text='The group the tag belongs to.', max_length=50, null=True), -        ), -    ] diff --git a/pydis_site/apps/content/models/__init__.py b/pydis_site/apps/content/models/__init__.py index 2718ce94..60007e27 100644 --- a/pydis_site/apps/content/models/__init__.py +++ b/pydis_site/apps/content/models/__init__.py @@ -1,3 +1,3 @@ -from .tag import Tag +from .tag import Commit, Tag -__all__ = ["Tag"] +__all__ = ["Commit", "Tag"] diff --git a/pydis_site/apps/content/models/tag.py b/pydis_site/apps/content/models/tag.py index 01264ff1..1c89fe1e 100644 --- a/pydis_site/apps/content/models/tag.py +++ b/pydis_site/apps/content/models/tag.py @@ -1,6 +1,36 @@ +import json +  from django.db import models +class Commit(models.Model): +    """A git commit.""" + +    URL_BASE = "https://github.com/python-discord/bot/commit/" + +    sha = models.CharField( +        help_text="The SHA hash of this commit.", +        primary_key=True, +        max_length=40, +    ) +    message = models.TextField(help_text="The commit message.") +    date = models.DateTimeField(help_text="The date and time the commit was created.") +    author = models.TextField(help_text="The person(s) who created the commit.") + +    @property +    def url(self) -> str: +        """The URL to the commit on GitHub.""" +        return self.URL_BASE + self.sha + +    @property +    def format_users(self) -> str: +        """Return a nice representation of the user(s)' name and email.""" +        authors = [] +        for author in json.loads(self.author): +            authors.append(f"{author['name']} <{author['email']}>") +        return ", ".join(authors) + +  class Tag(models.Model):      """A tag from the python-discord server.""" @@ -10,6 +40,12 @@ class Tag(models.Model):          help_text="The date and time this data was last fetched.",          auto_now=True,      ) +    last_commit = models.OneToOneField( +        Commit, +        help_text="The commit this file was last touched in.", +        null=True, +        on_delete=models.CASCADE, +    )      name = models.CharField(          help_text="The tag's name.",          primary_key=True, | 
