Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ To work on the allink-core repo you first need to pull the [allink-core](https:/

1. make sure you are up to date with the current version branch e.g "v2.0.x" and you working on your own branch.
2. create a virtualenv `virtualenv env`
3. install requirements `pip install -r requiremnts_dev.txt`
3. install requirements `pip install -r requirements_dev.txt`

For the next steps, we assume you are working on the [boilerplate-2.0](https://github.com/allink/boilerplate-2.0) project, but this should work with every project which follows the same principles and have allink-core installed.

Expand Down
2 changes: 1 addition & 1 deletion allink_core/core_apps/allink_teaser/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CMSAllinkTeaserPlugin(AllinkMediaAdminMixin, CMSPluginBase):
'teaser_technical_title',
'teaser_description',
'teaser_link_text',
'softpage_enabled',
'link_target',
)
})
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.12 on 2020-04-17 10:50

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('allink_teaser', '0006_auto_20200205_1436'),
]

operations = [
migrations.AddField(
model_name='allinkteaserplugin',
name='link_target',
field=models.IntegerField(blank=True, choices=[(1, 'New window'), (2, 'Softpage')], null=True, verbose_name='Link Target'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 2.2.12 on 2020-04-17 10:52

from django.db import migrations


def set_new_default_value(apps, schema_editor):
AllinkTeaserPlugin = apps.get_model('allink_teaser', 'AllinkTeaserPlugin')
for teaser in AllinkTeaserPlugin.objects.all():
if teaser.softpage_enabled:
teaser.link_target = 2
teaser.save()


class Migration(migrations.Migration):

dependencies = [
('allink_teaser', '0007_allinkteaserplugin_link_target'),
]

operations = [
migrations.RunPython(set_new_default_value),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 2.2.12 on 2020-04-17 11:17

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('allink_teaser', '0008_auto_20200417_1052'),
]

operations = [
migrations.RemoveField(
model_name='allinkteaserplugin',
name='softpage_enabled',
),
]
44 changes: 39 additions & 5 deletions allink_core/core_apps/allink_teaser/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
from allink_core.core.utils import get_additional_templates
from allink_core.core.models.fields_model import AllinkTeaserFieldsModel, AllinkTeaserTranslatedFieldsModel

NEW_WINDOW = 1
SOFTPAGE = 2

TARGET_CHOICES = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move "TARGET_CHOICES" to AllinkTeaserPlugin as a class attribute.

(NEW_WINDOW, 'New window'),
(SOFTPAGE, 'Softpage'),
)


class AllinkTeaserPlugin(AllinkInternalLinkFieldsModel, AllinkTeaserFieldsModel, AllinkTeaserTranslatedFieldsModel,
CMSPlugin):
Expand All @@ -16,11 +24,11 @@ class AllinkTeaserPlugin(AllinkInternalLinkFieldsModel, AllinkTeaserFieldsModel,
max_length=50
)

softpage_enabled = models.BooleanField(
'Show detailed information in Softpage',
help_text='If checked, the detail view of an entry will be displayed in a "softpage".'
' Otherwise the page will be reloaded.',
default=False
link_target = models.IntegerField(
'Link Target',
choices=TARGET_CHOICES,
null=True,
blank=True
)

cmsplugin_ptr = CMSPluginField()
Expand All @@ -34,3 +42,29 @@ def get_templates(cls):
for x, y in get_additional_templates('TEASER'):
templates += ((x, y),)
return templates

@property
def softpage_enabled(self):
return True if self.link_target == SOFTPAGE else False

@property
def new_window(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming

return True if self.link_target == NEW_WINDOW else False

@property
def link_attributes(self):
if self.link_target == NEW_WINDOW:
return 'target=_blank'
elif self.link_target == SOFTPAGE:
return 'data-icon-softpage'
else:
return None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is "None" the correct default value to return here, when we want to open in the same window?


@property
def link_icon(self):
if self.link_target == NEW_WINDOW:
return 'arrow-external'
elif self.link_target == SOFTPAGE:
return 'softpage'
else:
return None
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<div class="teaser__link">
{% if instance.softpage_enabled %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this if/ else statement is probably obsolete, since you added the properties "link_icon" and "link_attributes" on the model, right?

{% include "partials/buttons/link.html" with link_url=teaser_link link_label=teaser_link_text link_classes="btn" link_attributes='data-trigger-softpage' icon="softpage" %}
{% elif instance.new_window %}
{% include "partials/buttons/link.html" with link_url=teaser_link link_label=teaser_link_text link_classes="btn" link_attributes='target=_blank' icon="arrow-external" %}
{% else %}
{% include "partials/buttons/link.html" with link_url=teaser_link link_label=teaser_link_text link_classes="btn" %}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<div class="teaser teaser--tile">
<a href="{{ teaser_link }}" class="teaser__tile-link" {% if instance.softpage_enabled %}data-trigger-softpage{% endif %}>
<a href="{{ teaser_link }}" class="teaser__tile-link" {{instance.link_attributes}}>
{% include 'allink_teaser/includes/_image.html' with teaser_image=teaser_image %}
{% include 'allink_teaser/includes/_technical-title.html' with teaser_technical_title=teaser_technical_title %}
{% include 'allink_teaser/includes/_title.html' with teaser_title=teaser_title %}
{% include 'allink_teaser/includes/_description.html' with teaser_description=teaser_description %}
{% if instance.softpage_enabled %}
{% include 'allink_teaser/tile/_link.html' with teaser_link=teaser_link teaser_link_text=teaser_link_text icon="softpage" %}
{% elif instance.new_window %}
{% include 'allink_teaser/tile/_link.html' with teaser_link=teaser_link teaser_link_text=teaser_link_text icon="arrow-external" %}
{% else %}
{% include 'allink_teaser/tile/_link.html' with teaser_link=teaser_link teaser_link_text=teaser_link_text %}
{% endif %}
Expand Down