Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
37228ad
GH-93: Article List Plugin
wesleyboar Jun 23, 2021
b510c75
GH-93: Polish Existing Plugins
wesleyboar Jun 23, 2021
37c1ebd
GH-93: Static Article Preview Plugin
wesleyboar Jun 23, 2021
c266eec
GH-93: Rename Article List Plugin (add Static)
wesleyboar Jun 23, 2021
3bf3ff8
GH-93: StaticArticleList: + footer_link_url TODOs
wesleyboar Jun 23, 2021
29e929e
GH-93: Noop: Existing Plugins: Comments, New Lines
wesleyboar Jun 23, 2021
537c501
GH-93: Add Allocs. Drop List C. Type. Fix HTML.
wesleyboar Jun 25, 2021
bcc3ee1
WIP: GH-93: Deprecate Scopes. Add Components.
wesleyboar Jun 25, 2021
1b66d4c
GH-93: article list → news & allocs article lists
wesleyboar Jun 25, 2021
e9e66dd
FP-1099: Test: Disable reindex on publish
wesleyboar Jun 18, 2021
e6a63d7
FP-1099: Make Search a feature
wesleyboar Jun 21, 2021
b3d9714
FP-1099: Clarify Search feature value results
wesleyboar Jun 21, 2021
c090d83
GH-93: Noop: Update TODO comments cuz of progress
wesleyboar Jun 25, 2021
02d0ea8
GH-93: Fix Allocs Article Preview date logic
wesleyboar Jun 25, 2021
d0f4167
GH-93: Polish Allocs Article Preview date logic
wesleyboar Jun 25, 2021
439c7ca
Merge branch 'dev' into task/GH-93-article-list-styles
wesleyboar Jun 25, 2021
eddc6b0
Merge branch 'dev' into task/GH-93-article-list-styles
wesleyboar Jun 25, 2021
b862f8d
GH-93: Article List Plugin Revamp, Footer Link URL
wesleyboar Jun 28, 2021
bf3d306
GH-93: Article List Template Context Vars
wesleyboar Jun 28, 2021
a5d72a1
GH-93: Fix Article List Styling Bugs
wesleyboar Jun 28, 2021
0f8f320
GH-93: Quick: Use rem for outline-offset
wesleyboar Jun 28, 2021
1f20489
GH-93: Prevent Row/Col Layout/Style Mismatch
wesleyboar Jun 28, 2021
da50965
GH-93: Allow Gapless Rows
wesleyboar Jun 28, 2021
560a412
GH-93: Rename Row/Col Layout Options
wesleyboar Jun 28, 2021
08c7758
GH-93: Reorganize & Rename Row/Col Style Options
wesleyboar Jun 28, 2021
dfa551d
GH-93: Improve Layout texts. Translate help texts.
wesleyboar Jun 28, 2021
8128aa9
GH-93: Rebuild migrations
wesleyboar Jun 28, 2021
12d6066
Quick: Fix indentation in code of how to doc
wesleyboar Jun 29, 2021
0e3f4c5
Quick: Fix typo in comment
wesleyboar Jun 29, 2021
ac4eb3e
GH-93: Quick:Static Article List Cleanup
wesleyboar Jun 29, 2021
34193bd
GH-93: Quick: Static Article Preview Link Support
wesleyboar Jun 29, 2021
9f0a34e
GH-93: Quick: Docs: Update architecture decision
wesleyboar Jun 29, 2021
c10917d
Doc: How to Handle "Non-Nullable" "Default Value"
wesleyboar Jun 29, 2021
a323472
GH-93: DRY-er Support AbstractLink
wesleyboar Jun 29, 2021
c70df4d
GH-93: DRY-er Docs for Static Article Plugins
wesleyboar Jun 29, 2021
888af57
GH-93: Add" Docs" Article plugins ⚠️
wesleyboar Jun 29, 2021
985fc35
GH-93: Rename `--links` to `--docs`
wesleyboar Jun 29, 2021
5b6ab69
GH-93: Fix and comment out a `--docs` style
wesleyboar Jun 29, 2021
47b34e2
GH-93: Couple Style "Gapless" to Layout
wesleyboar Jun 29, 2021
128119a
GH-93: Fix News Article Missing Publish Date
wesleyboar Jun 29, 2021
4941a46
GH-93: Run clean_for_… before custom validation
wesleyboar Jun 30, 2021
f94c39f
GH-93: Fix bad internationalization format
wesleyboar Jun 30, 2021
55616fe
GH-93: Add" Events" Article plugins
wesleyboar Jun 30, 2021
90b759c
GH-93: Design Fix: Bigger space after See All icon
wesleyboar Jun 30, 2021
32a3c47
GH-93: Couple class names and choices
wesleyboar Jun 30, 2021
a2df8a9
Quick: Couple DIRECTION class names and choices
wesleyboar Jun 30, 2021
2095a51
Merge branch 'dev' into task/GH-93-article-list-styles
wesleyboar Jun 30, 2021
85493a4
GH-93: Add "Gapless" style to Columns Layouts
wesleyboar Jun 30, 2021
64c301e
GH-93: Noop: Consistent Comments & New Lines
wesleyboar Jul 1, 2021
8954f24
Merge branch 'dev' into task/GH-93-article-list-styles
wesleyboar Jul 1, 2021
ce5ee9e
Merge branch 'dev' into task/GH-93-article-list-styles
wesleyboar Jul 2, 2021
14d458b
GH-93: Up taccsite-custom, latest from its dev?
wesleyboar Jul 2, 2021
2be3f36
GH-93: hard squash migrations
wesleyboar Jul 2, 2021
51b0fca
GH-93: Comments & Noop tweaks
wesleyboar Jul 2, 2021
d0ace4b
GH-93: Update CSS docblocks and markup
wesleyboar Jul 2, 2021
10e549c
GH-93: Resolve GH-93 `!!!` comments
wesleyboar Jul 2, 2021
7f0a76c
GH-93: Do not use new `.x-…` mixins
wesleyboar Jul 2, 2021
7965b52
GH-93: Frontera: Use old s-article-preview
wesleyboar Jul 5, 2021
96761a8
GH-93: Frontera: Cleanup s-home as GH-93 completes
wesleyboar Jul 5, 2021
658ae01
GH-93: Demote Deprecated Core Styles to Frontera
wesleyboar Jul 5, 2021
50d6a9b
GH-93: Consistent Line-Height for Docs & Events
wesleyboar Jul 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# How to Conditionally Render Child Plugins

```handlebars
{% for plugin_instance in instance.child_plugin_instances %}
{% if plugin_instance.plugin_type == 'LinkPlugin' %}
<a href="{{ link }}" <!-- ... -->>
<!-- ... -->
</a>
{% endif %}
{% endfor %}
```
66 changes: 66 additions & 0 deletions taccsite_cms/contrib/_docs/how-to-extend-django-cms-plugin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# How To Extend a `djangocms-___` Plugin

These example codes extend the [`djangocms-link` plugin](https://github.com/django-cms/djangocms-link/tree/3.0.0/djangocms_link).

`.../models.py`:

```python
from djangocms_link.models import AbstractLink

class Taccsite______(AbstractLink):
"""
Components > "Article List" Model
https://confluence.tacc.utexas.edu/x/OIAjCQ
"""
# ___ = ___

class Meta:
abstract = False
```

`.../cms_plugins.py`:

```python
from djangocms_link.cms_plugins import LinkPlugin

from .models import ______Preview

class ______Plugin(LinkPlugin):
module = 'TACC Site'
model = Taccsite______
name = _('______')
render_template = 'static_article_preview.html'
def get_render_template(self, context, instance, placeholder):
return self.render_template

fieldsets = [
(_('Link'), {
'fields': (
('external_link', 'internal_link'),
('anchor', 'target'),
)
}),
]

# Render
def render(self, context, instance, placeholder):
context = super().render(context, instance, placeholder)
request = context['request']

context.update({
'link_url': instance.get_link(),
'link_text': instance.name,
'link_target': instance.target
})
return context
```

`.../templates/______.py`:

```handlebars

<a class="______" href="{{ link_url }}"
{% if link_target %}target="{{ link_target }}"{% endif %}>
<span>{{ link_text }}
</a>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# How to Handle "Non-Nullable" "Default Value"

## Sample Error

```text
You are trying to add a non-nullable field '...'
to choice without a default; we can't do that
(the database needs something to populate existing rows).
Please select a fix:
1) Provide a one-off default now (will be set on all existing rows)
2) Quit, and let me add a default in models.py
Select an option:
```

## Explanations

- (blog post) [What do you do when 'makemigrations' is telling you About your Lack of Default Value](https://chrisbartos.com/articles/what-do-you-do-when-makemigrations-is-telling-you-about-your-lack-of-default-value/)
- (video) [You are trying to add a non-nullable field ' ' to ' ' without a default; we can't do that](https://www.youtube.com/watch?v=NgaTUEijQSQ)

## Solutions

### For `cmsplugin_ptr`

1. ☑ Select option 1), then see:
- [Follow-Up Error](#follow-up-error)
- [Notes ▸ `cmsplugin_ptr`](#cmsplugin_ptr)

### For Other Fields

1. ⚠ Select option 1) and hope for the best.
2. ☑ Select option 2) and provide a sensible default (_not_ `None` a.k.a. null).
3. ⚠ (blog post) (hack) [Add A Migration For A Non-Null Foreignkey Field In Django](https://jaketrent.com/post/add-migration-nonnull-foreignkey-field-django)

## Follow-Up Error

If you allowed Null to be set as default, then you may have this new error:

```text
django.db.utils.IntegrityError: column "..." contains null values
```

Solutions:

1. [delete _relevant_ migration files and rebuild migrations](https://stackoverflow.com/a/37244199/11817077)
2. [delete _all_ migration files and rebuild migrations](https://stackoverflow.com/a/37242930/11817077)

## Notes

### `cmsplugin_ptr`

If the field is `cmsplugin_ptr` then know that

- [it is a database relationship field managed automatically by Django](https://github.com/nephila/djangocms-blog/issues/316#issuecomment-242292787),
- you may see it in workarounds for other plugins ([source a](https://github.com/django-cms/djangocms-link/blob/3.0.0/djangocms_link/models.py#L125), [source b](https://github.com/django-cms/djangocms-picture/blob/3.0.0/djangocms_picture/models.py#L208)),
- you should __not__ add or overwrite it unless you know what you are doing.

_W. Bomar learned everything in the intitial version of this document after trying to overwrite `cmsplugin_ptr` while extending its model from [source a](https://github.com/django-cms/djangocms-link/blob/3.0.0/djangocms_link/models.py#L125). His solution was [delete _all_ migration files and rebuild migrations](https://stackoverflow.com/a/37242930/11817077)._

## Appendix

- [Django CMS ▸ How to create Plugins ▸ Handling Relations](https://docs.django-cms.org/en/release-3.7.x/how_to/custom_plugins.html#handling-relations)
- [[BUG] Plugins with models that don't directly inherit from CMSPlugin or an abstract model cannot be copied](https://github.com/django-cms/django-cms/issues/6987)
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# How To Override `ValidationError()` from Parent Model

Intercept Error(s):

```python
from django.core.exceptions import ValidationError

from djangocms_Xxx.models import AbstractXxx

from taccsite_cms.contrib.helpers import (
get_indices_that_start_with
)

class OurModelThatUsesXxx(AbstractXxx):
# Validate
def clean(self):
# Bypass irrelevant parent validation
try:
super().clean()
except ValidationError as err:
# Intercept single-field errors
if hasattr(err, 'error_list'):
for i in range(len(err.error_list)):
# SEE: "Find Error(s)"
# ...
# Skip error
del err.error_list[i]
# Replace error
# SEE: https://docs.djangoproject.com/en/2.2/ref/forms/validation/#raising-validationerror

# Intercept multi-field errors
if hasattr(err, 'error_dict'):
for field, errors in err.message_dict.items():
# SEE: "Find Error(s)"
# ...
# Skip error
del err.error_dict[field]
# Replace error
# SEE: https://docs.djangoproject.com/en/2.2/ref/forms/validation/#raising-validationerror

# NOTE: The conditional `pass` is only to skip multi-field errors;
# single-field error skipping is unaffected by this logic;
# so it seems safe to always include this logic block
if len(err.messages) == 0:
pass
else:
raise err
```

Handle Error(s):

```python
# SEE: "Find Error(s)"
# ...

# Catch known static error
if 'Known static error string' in error:
# ...

# Catch known dynamic error
indices_to_catch = get_indices_that_start_with(
'Known dynamic error string that starts with same text',
errors
)
for i in indices_to_catch:
# ...
```
66 changes: 66 additions & 0 deletions taccsite_cms/contrib/_docs/taccsite_static_article.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Static Article Plugins

## Intention

Support static addition of news articles that originate from a Core news site.

A [dynamic solution that pulls form the Core news site](https://github.com/TACC/Core-CMS/issues/69) is preferable.

But this is not available due to constrainst of architecture, time, or ability.

## Architecture

### (Currently) Add Image via Child Plugin Instead of Via Fields

Instead, the image fields should be in the plugin, __not__ via a child plugin, but a solution has not yet been implemented.

#### Hope for the Future

The `AbstractLink` model was successfully extended.

See:
- [./how-to-extend-django-cms-plugin.md](./how-to-extend-django-cms-plugin.md)
- [../taccsite_static_article_preview](../taccsite_static_article_preview)
- [../taccsite_static_article_list](../taccsite_static_article_list)

#### Failed Attempt

1. Build model so it extends `AbstractPicture` from `djangocms-picture`.
2. Tweak model to sweep bugs under the rug.
3. Quit when he was unable to resolve the error,
`TaccsiteStaticNewsArticlePreview has no field named 'cmsplugin_ptr_id'`
upon saving a plugin instance.
4. Learn:
- [one should not try to reduce `AbstractPicture`](https://stackoverflow.com/a/3674714/11817077)
- [one should not subclass a subclass of `CMSPlugin`](https://github.com/django-cms/django-cms/blob/3.7.4/cms/models/pluginmodel.py#L104)

#### Abandoned Code

```python
from djangocms_picture.models import AbstractPicture

# To allow user to not set image
# FAQ: Emptying the clean() method avoids picture validation
# SEE: https://github.com/django-cms/djangocms-picture/blob/3.0.0/djangocms_picture/models.py#L278
def skip_image_validation():
pass

class TaccsiteStaticNewsArticlePreview(AbstractPicture):
#
# …
#

# Remove error-prone attribute from parent class
# FAQ: Avoid error when running `makemigrations`:
# "You are trying to add a non-nullable field 'cmsplugin_ptr' […]"
# SEE: https://github.com/django-cms/djangocms-picture/blob/3.0.0/djangocms_picture/models.py#L212
# SEE: https://github.com/django-cms/djangocms-picture/blob/3.0.0/djangocms_picture/models.py#L234
cmsplugin_ptr = None

class Meta:
abstract = False

# Validate
def clean(self):
skip_image_validation()
```
4 changes: 2 additions & 2 deletions taccsite_cms/contrib/bootstrap4_djangocms_link/cms_plugins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Reregister unregistered LinkPlugin without uninstalling Bootstrap4's
# Re-register unregistered LinkPlugin without uninstalling Bootstrap4's
# FAQ: A Bootstrap link is undesirable but may be used by migrated legacy sites
# TODO: Drop try/except & load non-standard plugin set for migrated legacy sites
# FAQ: If we can import both plugins, then re-register LinkPlugin
Expand All @@ -18,7 +18,7 @@

# SEE: https://github.com/django-cms/djangocms-link/issues/163
plugin_pool.register_plugin(LinkPlugin)
# CAVEAT: If import statement fails for reason other than Bootstrap presence,
# CAVEAT: If import statement fails for reason other than Bootstrap absence,
# then that failure, and the failure of this plugin, is silent
except ImportError:
pass
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Reregister unregistered PicturePlugin without uninstalling Bootstrap4's
# Re-register unregistered PicturePlugin without uninstalling Bootstrap4's
# FAQ: A Bootstrap picture has superfluous options that are not always desirable
# TODO: Drop try/except & load non-standard plugin set for migrated legacy sites
# FAQ: If we can import both plugins, then re-register PicturePlugin
# (because Bootstrap4Picture unregistered PicturePlugin)
try:
Expand Down
Loading