-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
task/DES-2672: CMS plugins for app listings, related apps, and app va…
…riants (#1197) * Add CMS plugin for listing apps by category * whitespace fixes * remove extraneous loggging * Add description field for app variants * add plugin for related apps * Add app variant selector * filter apps/variants based on enabled status * replace trick link * format hrefs for app variants * fix app href query string * fix comments
- Loading branch information
Showing
14 changed files
with
359 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ def get_fieldsets(self, request, obj=None): | |
{ | ||
"fields": ( | ||
"label", | ||
"description", | ||
"enabled", | ||
) | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
"""CMS plugins for Tools & Applications pages.""" | ||
|
||
import logging | ||
from cms.plugin_base import CMSPluginBase | ||
from cms.plugin_pool import plugin_pool | ||
from designsafe.apps.workspace.models.app_entries import ( | ||
AppListingEntry, | ||
) | ||
from designsafe.apps.workspace.models.app_cms_plugins import ( | ||
AppCategoryListingPlugin, | ||
RelatedAppsPlugin, | ||
AppVariantsPlugin, | ||
) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class AppCategoryListing(CMSPluginBase): | ||
"""CMS plugin to render the list of apps for a given category.""" | ||
|
||
model = AppCategoryListingPlugin | ||
name = "App Category Listing" | ||
module = "Tools & Applications" | ||
render_template = "designsafe/apps/workspace/app_listing_plugin.html" | ||
cache = False | ||
|
||
def render(self, context, instance, placeholder): | ||
context = super().render(context, instance, placeholder) | ||
listing_entries = AppListingEntry.objects.filter( | ||
category=instance.app_category, enabled=True | ||
) | ||
serialized_listing = [ | ||
{ | ||
"label": entry.label, | ||
"icon": entry.icon, | ||
"description": entry.description, | ||
"tags": [tag.name for tag in entry.tags.all()], | ||
"is_popular": entry.is_popular, | ||
"is_simcenter": entry.is_simcenter, | ||
"license_type": ( | ||
"Open Source" if entry.license_type == "OS" else "Licensed" | ||
), | ||
"href": entry.href, | ||
} | ||
for entry in listing_entries | ||
] | ||
context["listing"] = serialized_listing | ||
return context | ||
|
||
|
||
plugin_pool.register_plugin(AppCategoryListing) | ||
|
||
|
||
class RelatedApps(CMSPluginBase): | ||
"""CMS plugin to render related apps.""" | ||
|
||
model = RelatedAppsPlugin | ||
name = "Related Apps" | ||
module = "Tools & Applications" | ||
render_template = "designsafe/apps/workspace/related_apps_plugin.html" | ||
cache = False | ||
|
||
def render(self, context, instance: AppListingEntry, placeholder): | ||
context = super().render(context, instance, placeholder) | ||
listing_entries = instance.app.related_apps.filter(enabled=True) | ||
serialized_listing = [ | ||
{ | ||
"label": entry.label, | ||
"icon": entry.icon, | ||
"description": entry.description, | ||
"tags": [tag.name for tag in entry.tags.all()], | ||
"is_popular": entry.is_popular, | ||
"is_simcenter": entry.is_simcenter, | ||
"license_type": ( | ||
"Open Source" if entry.license_type == "OS" else "Licensed" | ||
), | ||
"href": entry.href, | ||
} | ||
for entry in listing_entries | ||
] | ||
context["listing"] = serialized_listing | ||
return context | ||
|
||
|
||
plugin_pool.register_plugin(RelatedApps) | ||
|
||
|
||
class AppVariants(CMSPluginBase): | ||
"""CMS plugin to render an apps versions/variants.""" | ||
|
||
model = AppVariantsPlugin | ||
name = "App Version Selection" | ||
module = "Tools & Applications" | ||
render_template = "designsafe/apps/workspace/app_variant_plugin.html" | ||
cache = False | ||
|
||
def render(self, context, instance: AppListingEntry, placeholder): | ||
context = super().render(context, instance, placeholder) | ||
app_variants = instance.app.appvariant_set.filter(enabled=True) | ||
context["listing"] = app_variants | ||
|
||
return context | ||
|
||
|
||
plugin_pool.register_plugin(AppVariants) |
42 changes: 42 additions & 0 deletions
42
designsafe/apps/workspace/migrations/0005_appcategorylistingplugin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Generated by Django 4.2.6 on 2024-04-02 17:54 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("cms", "0022_auto_20180620_1551"), | ||
("workspace", "0004_initial_app_categories_and_tags"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="AppCategoryListingPlugin", | ||
fields=[ | ||
( | ||
"cmsplugin_ptr", | ||
models.OneToOneField( | ||
auto_created=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
parent_link=True, | ||
primary_key=True, | ||
related_name="%(app_label)s_%(class)s", | ||
serialize=False, | ||
to="cms.cmsplugin", | ||
), | ||
), | ||
( | ||
"app_category", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="workspace.apptraycategory", | ||
), | ||
), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
bases=("cms.cmsplugin",), | ||
), | ||
] |
21 changes: 21 additions & 0 deletions
21
designsafe/apps/workspace/migrations/0006_appvariant_description.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Generated by Django 4.2.6 on 2024-04-02 22:16 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("workspace", "0005_appcategorylistingplugin"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="appvariant", | ||
name="description", | ||
field=models.TextField( | ||
blank=True, | ||
help_text="App variant description text for version overview.", | ||
null=True, | ||
), | ||
), | ||
] |
42 changes: 42 additions & 0 deletions
42
designsafe/apps/workspace/migrations/0007_relatedappsplugin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Generated by Django 4.2.6 on 2024-04-03 15:14 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("cms", "0022_auto_20180620_1551"), | ||
("workspace", "0006_appvariant_description"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="RelatedAppsPlugin", | ||
fields=[ | ||
( | ||
"cmsplugin_ptr", | ||
models.OneToOneField( | ||
auto_created=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
parent_link=True, | ||
primary_key=True, | ||
related_name="%(app_label)s_%(class)s", | ||
serialize=False, | ||
to="cms.cmsplugin", | ||
), | ||
), | ||
( | ||
"app", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="workspace.applistingentry", | ||
), | ||
), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
bases=("cms.cmsplugin",), | ||
), | ||
] |
42 changes: 42 additions & 0 deletions
42
designsafe/apps/workspace/migrations/0008_appvariantsplugin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Generated by Django 4.2.6 on 2024-04-03 18:02 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("cms", "0022_auto_20180620_1551"), | ||
("workspace", "0007_relatedappsplugin"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="AppVariantsPlugin", | ||
fields=[ | ||
( | ||
"cmsplugin_ptr", | ||
models.OneToOneField( | ||
auto_created=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
parent_link=True, | ||
primary_key=True, | ||
related_name="%(app_label)s_%(class)s", | ||
serialize=False, | ||
to="cms.cmsplugin", | ||
), | ||
), | ||
( | ||
"app", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="workspace.applistingentry", | ||
), | ||
), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
bases=("cms.cmsplugin",), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"""Models associated with CMS plugins for Tools & Applications""" | ||
|
||
from cms.models.pluginmodel import CMSPlugin | ||
from django.db import models | ||
from designsafe.apps.workspace.models.app_entries import ( | ||
AppTrayCategory, | ||
AppListingEntry, | ||
) | ||
|
||
|
||
class AppCategoryListingPlugin(CMSPlugin): | ||
"""Model for listing apps by category.""" | ||
|
||
app_category = models.ForeignKey( | ||
to=AppTrayCategory, on_delete=models.deletion.CASCADE | ||
) | ||
|
||
def __str__(self): | ||
return self.app_category.category | ||
|
||
|
||
class RelatedAppsPlugin(CMSPlugin): | ||
"""Model for listing related apps.""" | ||
|
||
app = models.ForeignKey(to=AppListingEntry, on_delete=models.deletion.CASCADE) | ||
|
||
def __str__(self): | ||
return self.app.label | ||
|
||
|
||
class AppVariantsPlugin(CMSPlugin): | ||
"""Model for listing related apps.""" | ||
|
||
app = models.ForeignKey(to=AppListingEntry, on_delete=models.deletion.CASCADE) | ||
|
||
def __str__(self): | ||
return self.app.label |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
designsafe/apps/workspace/templates/designsafe/apps/workspace/app_card.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<a class="c-app-card" href="{{app.href}}" style="width: 230px"> | ||
<h3 class="c-app-card__title"><i class="icon icon-hazmapper"></i> {{app.label}}</h3> | ||
|
||
<p class="c-app-card__desc">{{app.description}}</p> | ||
|
||
<ul class="c-app-card__types"> | ||
{% for tag in app.tags %} | ||
<li>{{tag}}</li> | ||
{% endfor %} | ||
</ul> | ||
|
||
<ul class="c-app-card__flags"> | ||
{% if app.is_popular %} | ||
<li><strong>Popular</strong></li> | ||
{% endif %} | ||
|
||
{% if not app.is_popular and app.is_simcenter %} | ||
<li>SimCenter</li> | ||
{% endif %} | ||
|
||
|
||
<li class="c-app-card__repo">{{app.license_type}}</li> | ||
</ul> | ||
</a> |
6 changes: 6 additions & 0 deletions
6
designsafe/apps/workspace/templates/designsafe/apps/workspace/app_listing_plugin.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h2>{{instance.app_category}}</h2> | ||
<section style="display:flex; gap:30px; flex-wrap: wrap"> | ||
{% for app in listing %} | ||
{% include "designsafe/apps/workspace/app_card.html" with app=app %} | ||
{% endfor %} | ||
</section> |
15 changes: 15 additions & 0 deletions
15
designsafe/apps/workspace/templates/designsafe/apps/workspace/app_variant_plugin.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<section style="background-color: #f4f4f4; padding: 25px;"> | ||
<h3>Select a Version</h3> | ||
{% for variant in listing %} | ||
<article> | ||
<div style="display:flex; align-items: center; justify-content: space-between;"> | ||
<h4>{{variant.label}}</h4> | ||
<a href="{{variant.href}}"><button class="btn btn-success">Get Started</button></a> | ||
</div> | ||
<p>{{variant.description}}</p> | ||
{% if listing.count > forloop.counter %} | ||
<hr /> | ||
{% endif %} | ||
</article> | ||
{% endfor %} | ||
</section> |
6 changes: 6 additions & 0 deletions
6
designsafe/apps/workspace/templates/designsafe/apps/workspace/related_apps_plugin.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h2>Related Applications</h2> | ||
<section style="display:flex; gap:30px; flex-wrap: wrap"> | ||
{% for app in listing %} | ||
{% include "designsafe/apps/workspace/app_card.html" with app=app %} | ||
{% endfor %} | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.