summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas NOEL <tnoel@entrouvert.com>2015-05-29 10:04:17 (GMT)
committerThomas NOEL <tnoel@entrouvert.com>2015-05-29 12:26:52 (GMT)
commit82e4bef24017f352baab60fd275858ead1700858 (patch)
treeaf0836479c4067b5befbc0e930ff565ed98a155c
parentb1bb35a952394fe0d0a441a774caf63fcbdbcd65 (diff)
downloadcombo-82e4bef24017f352baab60fd275858ead1700858.zip
combo-82e4bef24017f352baab60fd275858ead1700858.tar.gz
combo-82e4bef24017f352baab60fd275858ead1700858.tar.bz2
linkcell: can link to a page; can have an anchor(#7400)
-rw-r--r--combo/data/migrations/0007_auto_20150529_1003.py38
-rw-r--r--combo/data/models.py17
-rw-r--r--combo/public/templates/combo/link-cell.html2
3 files changed, 54 insertions, 3 deletions
diff --git a/combo/data/migrations/0007_auto_20150529_1003.py b/combo/data/migrations/0007_auto_20150529_1003.py
new file mode 100644
index 0000000..9a26b34
--- /dev/null
+++ b/combo/data/migrations/0007_auto_20150529_1003.py
@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('data', '0006_linkcell'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='linkcell',
+ name='anchor',
+ field=models.CharField(max_length=150, verbose_name='Anchor', blank=True),
+ preserve_default=True,
+ ),
+ migrations.AddField(
+ model_name='linkcell',
+ name='link_page',
+ field=models.ForeignKey(related_name='link_cell', to='data.Page', null=True),
+ preserve_default=True,
+ ),
+ migrations.AlterField(
+ model_name='linkcell',
+ name='title',
+ field=models.CharField(max_length=150, verbose_name='Title', blank=True),
+ preserve_default=True,
+ ),
+ migrations.AlterField(
+ model_name='linkcell',
+ name='url',
+ field=models.URLField(verbose_name='URL', blank=True),
+ preserve_default=True,
+ ),
+ ]
diff --git a/combo/data/models.py b/combo/data/models.py
index 699a6ee..9723e0f 100644
--- a/combo/data/models.py
+++ b/combo/data/models.py
@@ -440,8 +440,10 @@ class MenuCell(CellBase):
@register_cell_class
class LinkCell(CellBase):
- title = models.CharField(_('Title'), max_length=150)
- url = models.URLField(_('URL'))
+ title = models.CharField(_('Title'), max_length=150, blank=True)
+ url = models.URLField(_('URL'), blank=True)
+ link_page = models.ForeignKey('data.Page', related_name='link_cell', null=True)
+ anchor = models.CharField(_('Anchor'), max_length=150, blank=True)
template_name = 'combo/link-cell.html'
@@ -452,3 +454,14 @@ class LinkCell(CellBase):
if not self.title:
return None
return utils.ellipsize(self.title)
+
+ def render(self, context):
+ if self.link_page:
+ context['url'] = self.link_page.get_online_url()
+ context['title'] = self.title or self.link_page.title
+ else:
+ context['url'] = self.url
+ context['title'] = self.title or self.url
+ if self.anchor:
+ context['url'] += '#' + self.anchor
+ return super(LinkCell, self).render(context)
diff --git a/combo/public/templates/combo/link-cell.html b/combo/public/templates/combo/link-cell.html
index c96b7d8..75a5b59 100644
--- a/combo/public/templates/combo/link-cell.html
+++ b/combo/public/templates/combo/link-cell.html
@@ -1 +1 @@
-<a href="{{cell.url}}">{{cell.title}}</a>
+<a href="{{url}}">{{title}}</a>