Skip to content

Commit

Permalink
Merge pull request #705 from openedx/saleem-latif/ENT-7544
Browse files Browse the repository at this point in the history
ENT-7544: Added new app academy with related models
  • Loading branch information
saleem-latif authored Nov 2, 2023
2 parents d421657 + 5d54573 commit 43a4d17
Show file tree
Hide file tree
Showing 10 changed files with 255 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .annotation_safe_list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ waffle.Sample:
".. no_pii:": "This model has no PII"
waffle.Switch:
".. no_pii:": "This model has no PII"
academy.HistoricalAcademy:
".. no_pii:": "This model has no PII"
3 changes: 3 additions & 0 deletions enterprise_catalog/apps/academy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Academy app to handle implementation for academies.
"""
25 changes: 25 additions & 0 deletions enterprise_catalog/apps/academy/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
Admin for academy models.
"""
from django.contrib import admin
from simple_history.admin import SimpleHistoryAdmin

from enterprise_catalog.apps.academy.models import Academy, Tag


@admin.register(Tag)
class TagAdmin(admin.ModelAdmin):
"""
Django admin for Tag.
"""
list_display = ('id', 'title', )
search_fields = ('title', )


@admin.register(Academy)
class AcademyAdmin(SimpleHistoryAdmin):
"""
Django admin for Academy.
"""
list_display = ('uuid', 'title', 'created', 'modified', )
search_fields = ('title', 'short_description', 'long_description', )
9 changes: 9 additions & 0 deletions enterprise_catalog/apps/academy/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""
Academy app to handle implementation for academies.
"""
from django.apps import AppConfig


class AcademyConfig(AppConfig):
name = 'academy'
default = False
76 changes: 76 additions & 0 deletions enterprise_catalog/apps/academy/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Generated by Django 4.2.5 on 2023-11-02 07:29

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import model_utils.fields
import simple_history.models
import uuid


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('catalog', '0037_alter_historicalcontentmetadata_options_and_more'),
]

operations = [
migrations.CreateModel(
name='Tag',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(help_text='Tag title', max_length=255)),
('description', models.TextField(help_text='Tag description.')),
],
options={
'verbose_name': 'Tag',
'verbose_name_plural': 'Tags',
},
),
migrations.CreateModel(
name='HistoricalAcademy',
fields=[
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')),
('uuid', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False)),
('title', models.CharField(help_text='Academy title', max_length=255)),
('short_description', models.TextField(help_text='Short description of the academy.')),
('long_description', models.TextField(help_text='Long description of the academy.')),
('image', models.URLField(help_text='URL of the image shown on academy card on the frontend.')),
('history_id', models.AutoField(primary_key=True, serialize=False)),
('history_date', models.DateTimeField(db_index=True)),
('history_change_reason', models.CharField(max_length=100, null=True)),
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'historical Academy',
'verbose_name_plural': 'historical Academies',
'ordering': ('-history_date', '-history_id'),
'get_latest_by': ('history_date', 'history_id'),
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
migrations.CreateModel(
name='Academy',
fields=[
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')),
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('title', models.CharField(help_text='Academy title', max_length=255)),
('short_description', models.TextField(help_text='Short description of the academy.')),
('long_description', models.TextField(help_text='Long description of the academy.')),
('image', models.URLField(help_text='URL of the image shown on academy card on the frontend.')),
('enterprise_catalogs', models.ManyToManyField(related_name='academies', to='catalog.enterprisecatalog')),
('tags', models.ManyToManyField(related_name='academies', to='academy.tag')),
],
options={
'verbose_name': 'Academy',
'verbose_name_plural': 'Academies',
},
),
]
Empty file.
63 changes: 63 additions & 0 deletions enterprise_catalog/apps/academy/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""
Models for academy app.
"""
from uuid import uuid4

from django.db import models
from django.utils.translation import gettext as _
from model_utils.models import TimeStampedModel
from simple_history.models import HistoricalRecords

from enterprise_catalog.apps.catalog.models import EnterpriseCatalog


class Tag(models.Model):
"""
Model that can be used to tag records on any model.
.. no_pii:
"""
title = models.CharField(max_length=255, help_text=_('Tag title'))
description = models.TextField(help_text=_('Tag description.'))

class Meta:
verbose_name = _('Tag')
verbose_name_plural = _('Tags')
app_label = 'academy'

def __str__(self):
"""
Return human-readable string representation.
"""

return f'<Tag title="{self.title}">'


class Academy(TimeStampedModel):
"""
Model for storing academy related information.
.. no_pii:
"""
uuid = models.UUIDField(primary_key=True, default=uuid4, editable=False)
title = models.CharField(max_length=255, help_text=_('Academy title'))
enterprise_catalogs = models.ManyToManyField(EnterpriseCatalog, related_name='academies')
short_description = models.TextField(help_text=_('Short description of the academy.'))
long_description = models.TextField(help_text=_('Long description of the academy.'))
image = models.URLField(help_text=_('URL of the image shown on academy card on the frontend.'))

tags = models.ManyToManyField(Tag, related_name='academies')

history = HistoricalRecords()

class Meta:
verbose_name = _('Academy')
verbose_name_plural = _('Academies')
app_label = 'academy'

def __str__(self):
"""
Return human-readable string representation.
"""

return f'<Academy UUID="{self.uuid}">'
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by Django 4.2.5 on 2023-10-30 07:39

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('catalog', '0036_auto_20230306_1550'),
]

operations = [
migrations.AlterModelOptions(
name='historicalcontentmetadata',
options={'get_latest_by': ('history_date', 'history_id'), 'ordering': ('-history_date', '-history_id'), 'verbose_name': 'historical Content Metadata', 'verbose_name_plural': 'historical Content Metadata'},
),
migrations.AlterModelOptions(
name='historicalenterprisecatalog',
options={'get_latest_by': ('history_date', 'history_id'), 'ordering': ('-history_date', '-history_id'), 'verbose_name': 'historical Enterprise Catalog', 'verbose_name_plural': 'historical Enterprise Catalogs'},
),
migrations.AlterField(
model_name='contentmetadata',
name='associated_content_metadata',
field=models.ManyToManyField(blank=True, to='catalog.contentmetadata'),
),
migrations.AlterField(
model_name='historicalcontentmetadata',
name='history_date',
field=models.DateTimeField(db_index=True),
),
migrations.AlterField(
model_name='historicalenterprisecatalog',
name='history_date',
field=models.DateTimeField(db_index=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Generated by Django 4.2.5 on 2023-10-30 07:39

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('curation', '0002_add_can_only_view_highlight_sets'),
]

operations = [
migrations.AlterModelOptions(
name='historicalenterprisecurationconfig',
options={'get_latest_by': ('history_date', 'history_id'), 'ordering': ('-history_date', '-history_id'), 'verbose_name': 'historical Enterprise curation', 'verbose_name_plural': 'historical Enterprise curations'},
),
migrations.AlterModelOptions(
name='historicalhighlightedcontent',
options={'get_latest_by': ('history_date', 'history_id'), 'ordering': ('-history_date', '-history_id'), 'verbose_name': 'historical highlighted content', 'verbose_name_plural': 'historical highlighted contents'},
),
migrations.AlterModelOptions(
name='historicalhighlightset',
options={'get_latest_by': ('history_date', 'history_id'), 'ordering': ('-history_date', '-history_id'), 'verbose_name': 'historical highlight set', 'verbose_name_plural': 'historical highlight sets'},
),
migrations.AlterField(
model_name='historicalenterprisecurationconfig',
name='history_date',
field=models.DateTimeField(db_index=True),
),
migrations.AlterField(
model_name='historicalhighlightedcontent',
name='history_date',
field=models.DateTimeField(db_index=True),
),
migrations.AlterField(
model_name='historicalhighlightset',
name='history_date',
field=models.DateTimeField(db_index=True),
),
]
1 change: 1 addition & 0 deletions enterprise_catalog/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
'enterprise_catalog.apps.catalog',
'enterprise_catalog.apps.curation',
'enterprise_catalog.apps.api',
'enterprise_catalog.apps.academy',
)

INSTALLED_APPS += THIRD_PARTY_APPS
Expand Down

0 comments on commit 43a4d17

Please sign in to comment.