-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into task/GH-101-header-redesign
- Loading branch information
Showing
67 changed files
with
1,892 additions
and
86 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
Empty file.
78 changes: 78 additions & 0 deletions
78
taccsite_cms/contrib/_docs/how-to-extend-django-cms-plugin.md
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,78 @@ | ||
# 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 | ||
|
||
from taccsite_cms.contrib.helpers import clean_for_abstract_link | ||
|
||
class Taccsite______(AbstractLink): | ||
""" | ||
Components > "Article List" Model | ||
https://confluence.tacc.utexas.edu/x/OIAjCQ | ||
""" | ||
# ... | ||
|
||
|
||
|
||
# Parent | ||
|
||
link_is_optional = True # or False | ||
|
||
class Meta: | ||
abstract = False | ||
|
||
# Validate | ||
def clean(self): | ||
clean_for_abstract_link(__class__, self) | ||
``` | ||
|
||
`.../cms_plugins.py`: | ||
|
||
```python | ||
from djangocms_link.cms_plugins import LinkPlugin | ||
|
||
from .models import ______Preview | ||
|
||
class ______Plugin(LinkPlugin): | ||
# ... | ||
render_template = 'static_article_preview.html' | ||
def get_render_template(self, context, instance, placeholder): | ||
return self.render_template | ||
|
||
fieldsets = [ | ||
# ... | ||
(_('Link'), { | ||
'fields': ( | ||
# 'name', # to use LinkPlugin "Display name" | ||
('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_target': instance.target | ||
# 'link_text': instance.name, # to use LinkPlugin "Display name" | ||
}) | ||
return context | ||
``` | ||
|
||
`.../templates/______.py`: | ||
|
||
```handlebars | ||
<a class="______" href="{{ link_url }}" | ||
{% if link_target %}target="{{ link_target }}"{% endif %}> | ||
<span>{{ link_text }} | ||
</a> | ||
``` |
62 changes: 62 additions & 0 deletions
62
taccsite_cms/contrib/_docs/how-to-override-validation-error-from-parent-model.md
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,62 @@ | ||
# 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 | ||
|
||
if err.messages: | ||
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: | ||
# ... | ||
``` |
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
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
Empty file.
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,66 @@ | ||
from cms.plugin_base import CMSPluginBase | ||
from cms.plugin_pool import plugin_pool | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from taccsite_cms.contrib.helpers import concat_classnames | ||
from taccsite_cms.contrib.taccsite_offset.cms_plugins import get_direction_classname | ||
|
||
from .models import TaccsiteBlockquote | ||
|
||
@plugin_pool.register_plugin | ||
class TaccsiteBlockquotePlugin(CMSPluginBase): | ||
""" | ||
Components > "Blockquote" Plugin | ||
https://confluence.tacc.utexas.edu/x/FIEjCQ | ||
""" | ||
module = 'TACC Site' | ||
model = TaccsiteBlockquote | ||
name = _('Blockquote') | ||
render_template = 'blockquote.html' | ||
|
||
cache = True | ||
text_enabled = True | ||
allow_children = False | ||
|
||
fieldsets = [ | ||
(None, { | ||
'fields': ( | ||
'text', | ||
'origin', | ||
'use_cite', | ||
) | ||
}), | ||
(_('Citation'), { | ||
'classes': ('collapse',), | ||
'fields': ( | ||
'cite_person', | ||
('cite_text', 'cite_url'), | ||
) | ||
}), | ||
(_('Layout'), { | ||
'fields': ( | ||
'offset', | ||
) | ||
}), | ||
(_('Advanced settings'), { | ||
'classes': ('collapse',), | ||
'fields': ( | ||
'attributes', | ||
) | ||
}), | ||
] | ||
|
||
# Render | ||
|
||
def render(self, context, instance, placeholder): | ||
context = super().render(context, instance, placeholder) | ||
request = context['request'] | ||
|
||
classes = concat_classnames([ | ||
's-blockquote', | ||
get_direction_classname(instance.offset), | ||
instance.attributes.get('class'), | ||
]) | ||
instance.attributes['class'] = classes | ||
|
||
return context |
Oops, something went wrong.