From ac6ad632043485c4d8e50096a779fd5f57c6efbd Mon Sep 17 00:00:00 2001 From: akashmalakar Date: Mon, 20 Apr 2020 11:09:27 +0200 Subject: [PATCH] deleted field softpage_enabled and added field link target which has a property softpage_enabled so usage stays the same added posibility to choose between softpage and new window migrated field softpage ebabled so if it was set to true this would be represented in the new link_target field fix typo in readme --- README.md | 2 +- .../core_apps/allink_teaser/cms_plugins.py | 2 +- .../0007_allinkteaserplugin_link_target.py | 18 ++++++++ .../migrations/0008_auto_20200417_1052.py | 22 ++++++++++ ...ove_allinkteaserplugin_softpage_enabled.py | 17 +++++++ allink_core/core_apps/allink_teaser/models.py | 44 ++++++++++++++++--- .../allink_teaser/includes/_link.html | 2 + .../templates/allink_teaser/tile/item.html | 4 +- 8 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 allink_core/core_apps/allink_teaser/migrations/0007_allinkteaserplugin_link_target.py create mode 100644 allink_core/core_apps/allink_teaser/migrations/0008_auto_20200417_1052.py create mode 100644 allink_core/core_apps/allink_teaser/migrations/0009_remove_allinkteaserplugin_softpage_enabled.py diff --git a/README.md b/README.md index a96153b8..42490d83 100755 --- a/README.md +++ b/README.md @@ -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. diff --git a/allink_core/core_apps/allink_teaser/cms_plugins.py b/allink_core/core_apps/allink_teaser/cms_plugins.py index 04f18ef8..746a19e6 100644 --- a/allink_core/core_apps/allink_teaser/cms_plugins.py +++ b/allink_core/core_apps/allink_teaser/cms_plugins.py @@ -51,7 +51,7 @@ class CMSAllinkTeaserPlugin(AllinkMediaAdminMixin, CMSPluginBase): 'teaser_technical_title', 'teaser_description', 'teaser_link_text', - 'softpage_enabled', + 'link_target', ) }) ) diff --git a/allink_core/core_apps/allink_teaser/migrations/0007_allinkteaserplugin_link_target.py b/allink_core/core_apps/allink_teaser/migrations/0007_allinkteaserplugin_link_target.py new file mode 100644 index 00000000..0274e3c0 --- /dev/null +++ b/allink_core/core_apps/allink_teaser/migrations/0007_allinkteaserplugin_link_target.py @@ -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'), + ), + ] diff --git a/allink_core/core_apps/allink_teaser/migrations/0008_auto_20200417_1052.py b/allink_core/core_apps/allink_teaser/migrations/0008_auto_20200417_1052.py new file mode 100644 index 00000000..a533cf1a --- /dev/null +++ b/allink_core/core_apps/allink_teaser/migrations/0008_auto_20200417_1052.py @@ -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), + ] diff --git a/allink_core/core_apps/allink_teaser/migrations/0009_remove_allinkteaserplugin_softpage_enabled.py b/allink_core/core_apps/allink_teaser/migrations/0009_remove_allinkteaserplugin_softpage_enabled.py new file mode 100644 index 00000000..39d69b99 --- /dev/null +++ b/allink_core/core_apps/allink_teaser/migrations/0009_remove_allinkteaserplugin_softpage_enabled.py @@ -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', + ), + ] diff --git a/allink_core/core_apps/allink_teaser/models.py b/allink_core/core_apps/allink_teaser/models.py index 7e4fcb91..775e3886 100644 --- a/allink_core/core_apps/allink_teaser/models.py +++ b/allink_core/core_apps/allink_teaser/models.py @@ -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 = ( + (NEW_WINDOW, 'New window'), + (SOFTPAGE, 'Softpage'), +) + class AllinkTeaserPlugin(AllinkInternalLinkFieldsModel, AllinkTeaserFieldsModel, AllinkTeaserTranslatedFieldsModel, CMSPlugin): @@ -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() @@ -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): + 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 + + @property + def link_icon(self): + if self.link_target == NEW_WINDOW: + return 'arrow-external' + elif self.link_target == SOFTPAGE: + return 'softpage' + else: + return None diff --git a/allink_core/core_apps/allink_teaser/templates/allink_teaser/includes/_link.html b/allink_core/core_apps/allink_teaser/templates/allink_teaser/includes/_link.html index b4ce23fc..bd75db76 100644 --- a/allink_core/core_apps/allink_teaser/templates/allink_teaser/includes/_link.html +++ b/allink_core/core_apps/allink_teaser/templates/allink_teaser/includes/_link.html @@ -4,6 +4,8 @@