Code Monkey home page Code Monkey logo

djangocms-link's Introduction

django CMS Link

pypi build coverage

django CMS Link is a plugin for django CMS that allows you to add links on your site.

This plugin supports child plugins. If you add an other plugin as a child it will take this content instead of the link name as the content of the link.

This addon is compatible with Divio Cloud and is also available on the django CMS Marketplace for easy installation.

image

Contributing

This is a an open-source project. We'll be delighted to receive your feedback in the form of issues and pull requests. Before submitting your pull request, please review our contribution guidelines.

We're grateful to all contributors who have helped create and maintain this package. Contributors are listed at the contributors section.

One of the easiest contributions you can make is helping to translate this addon on Transifex.

Documentation

See REQUIREMENTS in the setup.py file for additional dependencies:

python django djangocms

  • Django Filer 1.7 or higher

Make sure django Filer is installed and configured appropriately.

Installation

For a manual install:

  • run pip install djangocms-link
  • add djangocms_link to your INSTALLED_APPS
  • run python manage.py migrate djangocms_link

Configuration

Note that the provided templates are very minimal by design. You are encouraged to adapt and override them to your project's requirements.

This addon provides a default template for all instances. You can provide additional template choices by adding a DJANGOCMS_LINK_TEMPLATES setting:

DJANGOCMS_LINK_TEMPLATES = [
    ('feature', _('Featured Version')),
]

You'll need to create the feature folder inside templates/djangocms_link/ otherwise you will get a template does not exist error. You can do this by copying the default folder inside that directory and renaming it to feature.

To support environments where non-standard URLs would otherwise work, this project supports the defining of an additional RegEx pattern for validating the host-portion of the URL.

For example:

# RFC1123 Pattern:
DJANGOCMS_LINK_INTRANET_HOSTNAME_PATTERN = r'[a-z,0-9,-]{1,15}'

Either of these might accept a URL such as:

http://SEARCHHOST/?q=some+search+string

If left undefined, the normal Django URLValidator will be used.

Django Select2

This plugin supports django-select2 for simpler use of internal links. You need to manually enable it by:

  • run pip install django-select2
  • add django_select2 to your INSTALLED_APPS
  • add url(r'^select2/', include('django_select2.urls')), to your urls.py
  • set DJANGOCMS_LINK_USE_SELECT2 = True in your settings.py

Running Tests

You can run tests by executing:

virtualenv env
source env/bin/activate
pip install -r tests/requirements.txt
python setup.py test

Updating from cmsplugin-filer

Historically, cmsplugin-filer was used to create file, folder, image, link, teaser & video plugins on your django CMS projects. Now cmsplugin-filer has been archived, you can still migrate your old instances without having to copy them manually to the new djangocms-<file|picture|link|...> plugins.

There's a third-party management command that supports your migration:

migrate_cmsplugin_filer.py

This management command is only a starting point. It has worked out of the box for some people, but we encourage you to read the code, understand what it does, and test it on a development environment before running it on your production server.

The management command is only configured to transfer your cmsplugin_link, cmsplugin_file, cmsplugin_folder and cmsplugin_image plugins to modern djangocms_* plugins. If you need to transfer other cmsplugin_* plugins, you'll have to write your own code.

Alternatively you can use the deprecate_cmsplugin_filer app, which only adds a small migration that transfer the old cmsplugin-filer plugins instances to the new djangocms-<file|picture|link|...> plugins.

djangocms-link's People

Contributors

bplociennik avatar brente avatar chive avatar chronossc avatar czpython avatar digi604 avatar donce avatar evildmp avatar finalangel avatar fp4code avatar fygul avatar gkmngrgn avatar grigno avatar haricot avatar jsma avatar marksweb avatar mkoistinen avatar morganwahl avatar narenderrajub avatar ojii avatar otg-sandrey avatar petrklus avatar pre-commit-ci[bot] avatar rda-dev avatar stefanfoulis avatar tirkarthi avatar vthaian avatar vxsx avatar vytisb avatar yakky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

djangocms-link's Issues

Phone field restrictions

Hello.

Right now plugin have no restriction to the phone field, i think it will be great if phone links content will limited by digits and "+"/"-" chars and whitespaces .

Thanks.

Unwanted migration with django 1.7

Python 2.7.8
Django 1.7.8
Django CMS 3.1.0
djangocms-link 1.6.2

Running makemigrations creates unwanted migration for djangocms_link:

class Migration(migrations.Migration):

dependencies = [
    ('djangocms_link', '0003_auto_20150212_1310'),
]

operations = [
    migrations.AlterField(
        model_name='link',
        name='anchor',
        field=models.CharField(help_text='This applies only to page and text links. Do <em>not</em> include a preceding "#" symbol.', max_length=128, verbose_name='anchor', blank=True),
        preserve_default=True,
    ),
    migrations.AlterField(
        model_name='link',
        name='url',
        field=models.CharField(blank=True, max_length=2048, null=True, verbose_name='link', validators=[djangocms_link.validators.IntranetURLValidator(intranet_host_re=None)]),
        preserve_default=True,
    ),
]

Class option

What do you think about adding class option to the model? We use several different link classes, so option like this is crucial for us - maybe it's worth adding it for everybody? I can make a pull request if you agree.

Add support for django-select2 5.0+

django-select2 5.0+ is a complete rewrite. This plugin is currently not compatible with it, but we need to make it compatible as it will be needed to support future Django versions

no such table: cms_page

If i try to run syncdb, i get this error:

$ ./manage.py syncdb
...
  File "/home/jens/PyLucid_env/lib/python3.4/site-packages/djangocms_link/cms_plugins.py", line 8, in <module>
    from djangocms_link.forms import LinkForm
  File "/home/jens/PyLucid_env/lib/python3.4/site-packages/djangocms_link/forms.py", line 9, in <module>
    class LinkForm(ModelForm):
  File "/home/jens/PyLucid_env/lib/python3.4/site-packages/djangocms_link/forms.py", line 12, in LinkForm
    page_link = PageSearchField(queryset=Page.objects.drafts(), label=_("Page"), required=False)
  File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django_select2/fields.py", line 305, in __call__
    if not queryset and hasattr(cls, '_subclass_queryset'):
  File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/db/models/query.py", line 122, in __len__
    self._fetch_all()
  File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/db/models/query.py", line 966, in _fetch_all
    self._result_cache = list(self.iterator())
  File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/db/models/query.py", line 265, in iterator
    for row in compiler.results_iter():
  File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 700, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 786, in execute_sql
    cursor.execute(sql, params)
  File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/db/backends/utils.py", line 81, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/utils/six.py", line 658, in reraise
    raise value.with_traceback(tb)
  File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 485, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: cms_page

Think the related code is: PageSearchField(queryset=Page.objects.drafts()

Tests are broken and outdated...

The tests are broken because of:

  File "/home/travis/build/divio/djangocms-link/djangocms_link/fields.py", line 10, in <module>
    select2_version = LooseVersion(django_select2.__version__)
AttributeError: 'module' object has no attribute '__version__'

see: https://travis-ci.org/divio/djangocms-link/builds/317713548

And the test matrix is IMHO out of date:

djangocms-link$ tox -l
flake8
py34-latest
py27-latest
py34-dj18-cms34
py34-dj18-cms33
py27-dj18-cms34
py27-dj18-cms33
py34-dj19-cms34
py34-dj19-cms33
py27-dj19-cms34
py27-dj19-cms33

django 1.9 should be changed to 1.11
Django CMS 3.3 not needed
Python 3.5 is missing

isn't it?

Display link with some custom style

Could be useful to add some form field choice to add class="myclass" to the HTML included in the in the template. As a use case, suppose do you want to display a link as a Twitter Bootstrap Button, adding class="btn btn-default".

May be this choices, would be configurable via settings, in case you use another CSS framework, or custom css stylesheet. Or just disable this field in case you want the standard LinkPlugin.

Another simple solution for this is to create another ButtonLinkPlugin class, with the same model (or another inherited from LinkPlugin with extra cssclass field), the same form (or another inherited from LinkForm), and another template... I don know.. just some ideas.

Unable to use either of the Page fields to create links to CMS pages

I've extended LinkForm in my own plugin to also provide links to a custom news application but I seem to be having trouble with page_link.

If I'm using Select2 then in the the field queryset is not being defined so I'm getting an AttributeError from within Django where it tries to do self.queryset.model but I am able to search through all my pages in the form. The get_queryset on the field is definitely returning values.

If I drop to using PageSelectFormField then after selecting a page the form errors with Enter a list of values. The data coming through the form is;

page_link_0 = 1
page_link_1 = 7
page_link_2 = 7

So I assume that's correctly providing Site ID 1 and Page ID 7...

I can't see anything particularly unusual about the way the standard plugin works, and my additions is simply a change to a similar model & my additional field in the clean method, with an almost identical plugin;

    class RelatedArticlePlugin(LinkPlugin):
        model = RelatedArticle
        name = _("Related Article")
        form = RelatedArticleForm
        render_template = "related_articles.html"
        change_form_template = "filesets.html"

        def render(self, context, instance, placeholder):
            link = instance.link()
            context.update({
                'instance': instance,
                'link': link,
                'placeholder': placeholder,
            })
            return context

    plugin_pool.register_plugin(RelatedArticlePlugin)

Cannot create new link instance anymore

Hey,

after upgrading to Django 1.10.5 (from 1.9) I'm not able to create a Link widtget within the editor anymore.
I already tried to make and apply migrations which did not solve the problem.

Here is the error message I find in the logs:

[Sat Jan 21 13:12:53.217899 2017] [wsgi:error] [pid 26297] Internal Server Error: /admin/cms/page/add-plugin/
[Sat Jan 21 13:12:53.217928 2017] [wsgi:error] [pid 26297] Traceback (most recent call last):
[Sat Jan 21 13:12:53.217934 2017] [wsgi:error] [pid 26297]   File "/var/www/virtualenv/www_django/lib/python3.4/site-packages/django/core/handlers/exception.py", line 39, in inner
[Sat Jan 21 13:12:53.217940 2017] [wsgi:error] [pid 26297]     response = get_response(request)
[Sat Jan 21 13:12:53.217946 2017] [wsgi:error] [pid 26297]   File "/var/www/virtualenv/www_django/lib/python3.4/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_$
[Sat Jan 21 13:12:53.217951 2017] [wsgi:error] [pid 26297]     response = self._get_response(request)
[Sat Jan 21 13:12:53.217961 2017] [wsgi:error] [pid 26297]   File "/var/www/virtualenv/www_django/lib/python3.4/site-packages/django/core/handlers/base.py", line 187, in _get_response
[Sat Jan 21 13:12:53.217967 2017] [wsgi:error] [pid 26297]     response = self.process_exception_by_middleware(e, request)
[Sat Jan 21 13:12:53.217973 2017] [wsgi:error] [pid 26297]   File "/var/www/virtualenv/www_django/lib/python3.4/site-packages/django/core/handlers/base.py", line 185, in _get_response
[Sat Jan 21 13:12:53.217978 2017] [wsgi:error] [pid 26297]     response = wrapped_callback(request, *callback_args, **callback_kwargs)
[Sat Jan 21 13:12:53.217984 2017] [wsgi:error] [pid 26297]   File "/var/www/virtualenv/www_django/lib/python3.4/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
[Sat Jan 21 13:12:53.217989 2017] [wsgi:error] [pid 26297]     response = view_func(request, *args, **kwargs)
[Sat Jan 21 13:12:53.217994 2017] [wsgi:error] [pid 26297]   File "/var/www/virtualenv/www_django/lib/python3.4/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_$
[Sat Jan 21 13:12:53.217999 2017] [wsgi:error] [pid 26297]     response = view_func(request, *args, **kwargs)
[Sat Jan 21 13:12:53.218004 2017] [wsgi:error] [pid 26297]   File "/var/www/virtualenv/www_django/lib/python3.4/site-packages/django/contrib/admin/sites.py", line 211, in inner
[Sat Jan 21 13:12:53.218009 2017] [wsgi:error] [pid 26297]     return view(request, *args, **kwargs)
[Sat Jan 21 13:12:53.218013 2017] [wsgi:error] [pid 26297]   File "/var/www/virtualenv/www_django/lib/python3.4/site-packages/django/views/decorators/clickjacking.py", line 39, in wr$
[Sat Jan 21 13:12:53.616782 2017] [wsgi:error] [pid 26297]     resp = view_func(*args, **kwargs)
[Sat Jan 21 13:12:53.616809 2017] [wsgi:error] [pid 26297]   File "/var/www/virtualenv/www_django/lib/python3.4/site-packages/cms/admin/placeholderadmin.py", line 289, in add_plugin
[Sat Jan 21 13:12:53.616815 2017] [wsgi:error] [pid 26297]     response = plugin_instance.add_view(request)
[Sat Jan 21 13:12:53.616820 2017] [wsgi:error] [pid 26297]   File "/var/www/virtualenv/www_django/lib/python3.4/site-packages/django/contrib/admin/options.py", line 1509, in add_view
[Sat Jan 21 13:12:53.616835 2017] [wsgi:error] [pid 26297]     return self.changeform_view(request, None, form_url, extra_context)
[Sat Jan 21 13:12:53.616841 2017] [wsgi:error] [pid 26297]   File "/var/www/virtualenv/www_django/lib/python3.4/site-packages/django/utils/decorators.py", line 67, in _wrapper
[Sat Jan 21 13:12:53.616848 2017] [wsgi:error] [pid 26297]     return bound_func(*args, **kwargs)
[Sat Jan 21 13:12:53.616853 2017] [wsgi:error] [pid 26297]   File "/var/www/virtualenv/www_django/lib/python3.4/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
[Sat Jan 21 13:12:53.616859 2017] [wsgi:error] [pid 26297]     response = view_func(request, *args, **kwargs)
[Sat Jan 21 13:12:53.616864 2017] [wsgi:error] [pid 26297]   File "/var/www/virtualenv/www_django/lib/python3.4/site-packages/django/utils/decorators.py", line 63, in bound_func
[Sat Jan 21 13:12:53.616869 2017] [wsgi:error] [pid 26297]     return func.__get__(self, type(self))(*args2, **kwargs2)
[Sat Jan 21 13:12:53.616874 2017] [wsgi:error] [pid 26297]   File "/usr/lib/python3.4/contextlib.py", line 30, in inner
[Sat Jan 21 13:12:53.616878 2017] [wsgi:error] [pid 26297]     return func(*args, **kwds)
[Sat Jan 21 13:12:53.616884 2017] [wsgi:error] [pid 26297]   File "/var/www/virtualenv/www_django/lib/python3.4/site-packages/django/contrib/admin/options.py", line 1441, in changefo$
[Sat Jan 21 13:12:53.616889 2017] [wsgi:error] [pid 26297]     if form.is_valid():
[Sat Jan 21 13:12:53.616894 2017] [wsgi:error] [pid 26297]   File "/var/www/virtualenv/www_django/lib/python3.4/site-packages/django/forms/forms.py", line 169, in is_valid
[Sat Jan 21 13:12:53.616899 2017] [wsgi:error] [pid 26297]     return self.is_bound and not self.errors
[Sat Jan 21 13:12:53.616904 2017] [wsgi:error] [pid 26297]   File "/var/www/virtualenv/www_django/lib/python3.4/site-packages/django/forms/forms.py", line 161, in errors
[Sat Jan 21 13:12:53.616909 2017] [wsgi:error] [pid 26297]     self.full_clean()
[Sat Jan 21 13:12:53.616914 2017] [wsgi:error] [pid 26297]   File "/var/www/virtualenv/www_django/lib/python3.4/site-packages/django/forms/forms.py", line 372, in full_clean
[Sat Jan 21 13:12:53.616919 2017] [wsgi:error] [pid 26297]     self._post_clean()
[Sat Jan 21 13:12:53.616923 2017] [wsgi:error] [pid 26297]   File "/var/www/virtualenv/www_django/lib/python3.4/site-packages/django/forms/models.py", line 398, in _post_clean
[Sat Jan 21 13:12:53.616928 2017] [wsgi:error] [pid 26297]     self.instance.full_clean(exclude=exclude, validate_unique=False)
[Sat Jan 21 13:12:53.616933 2017] [wsgi:error] [pid 26297]   File "/var/www/virtualenv/www_django/lib/python3.4/site-packages/django/db/models/base.py", line 1217, in full_clean
[Sat Jan 21 13:12:53.616938 2017] [wsgi:error] [pid 26297]     self.clean()
[Sat Jan 21 13:12:53.616943 2017] [wsgi:error] [pid 26297]   File "/var/www/virtualenv/www_django/lib/python3.4/site-packages/djangocms_link/models.py", line 163, in clean
[Sat Jan 21 13:12:53.616948 2017] [wsgi:error] [pid 26297]     self._meta.get_field_by_name(anchor_field_name)[0].verbose_name)
[Sat Jan 21 13:12:53.616962 2017] [wsgi:error] [pid 26297] AttributeError: 'Options' object has no attribute 'get_field_by_name'

Edit:
I have installed django-cms link via pip:
Django==1.10.5
django-cms==3.4.1
djangocms-link==2.1.0
...

Have you any idea how I can make it work again?

Thank you!
Best,
Matthias

'render_plugin' fails

As soon as I try to insert a link, I get this error:

In template E:.virtualenvs\vcms235\lib\site-packages\djangocms_link\templates\cms\plugins\link.html, error at line 1
Invalid block tag: 'render_plugin', expected 'empty' of 'endfor'
1 {% load cms_tags %}{% if object.child_plugin_instances %}{% endif %}<a href="{{ link }}"{% if target %} target="{{ target }}"{% endif %}>{% for plugin in object.child_plugin_instances %}{% render_plugin plugin %}{% empty %}{{ name }}{% endfor %}{% if object.child_plugin_instances %}{% endif %}

When I comment out "{% render_plugin plugin %}", it runs further

django-select2 issues

I just enabled django-select2 per the README and I've encountered a few issues.

For example, I have a CMS page with a link to the home page that was created with the default select widgets, not django-select2.

screen shot 2017-01-26 at 2 25 09 am

Next I set DJANGOCMS_LINK_USE_SELECT2 = True in my settings file. When I reload, the link plugin no longer shows the existing link to the home page, the auto-complete field is empty.

screen shot 2017-01-26 at 2 25 32 am

If I then use the django-select2 widget to select the home page, I get the following error:

screen shot 2017-01-26 at 2 25 46 am

Any ideas? Are there any additional steps required on my part beyond what is mentioned in the current README?

usage of select2 field should be configurable

currently the select2 field is automatically used for the page selector if select2 is installed. Otherwise it falls back to using the standard cms page selector widget.

The select2 widget is not really usable if you don't know exactly what page you want to add.
It should use the cms page selector widget by default and have a setting to enable select2 for the edge cases where there are so many pages that the select2 widget makes more sense.

'name' should be optional

Currently it seems to be impossible to wrap this link element around another plugin (i.e. image) without having to specify an anchor text for the link plugin.

This behaviour makes it difficult to use it together with other plugins. I suggest making the 'name' field optional.

change migrations to standard location

In the readme:
"when django CMS 3.1 will be released, migrations for Django 1.7 will be moved to the standard location "

Same with other plugins like djangocms-picture djangocms-file etc

No link icon

django-cms 3.0.3
I have GET http://x.x.x.x:8000/static/cms/images/plugins/link.png 404 (NOT FOUND)

pip install djangocms-link fails on Ubuntu 14.04 with python 3.4.0 and Django 1.8

I'm setting up a Django-CMS instance on a Digital Ocean Ubuntu 14.04 VPS. I've installed Python 3.4.0, Django 1.8 and used a requirements.txt file to install the packages from my testing area. However, of the list, only djangocms-link fails to build and install. The error is as follows:

Collecting djangocms-link
Downloading djangocms-link-1.6.2.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
  File "<string>", line 20, in <module>
  File "/tmp/pip-build-2nuoeqle/djangocms-link/setup.py", line 36, in <module>
    long_description=open('README.rst').read(),
  File "/usr/share/nginx/python/code-root/env/lib/python3.4/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 1844: ordinal not in range(128)

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-2nuoeqle/djangocms-link

Based off the error, I have a feeling the README.rst file is in unicode encoding, but for some reason Python thinks it's ascii. But I'm by no means certain of this.

I have successfully installed the package in the last two days on both Ubuntu 15.04 and Mac OS X, which means it could just as easily be an issue on my server. However, I'm not sure then what to make of the error, nor am I sure how to test anything with a pip package like this. Any advice/direction would be appreciated.

How to handle non CMS internal links

I need to make a link to an internal page, that is not managed in the CMS (eg: an aldryn newsblog article).
The external_link field requires me to add a domain name at the beginning of my link, but I would prefer to have my links starting at / (eg: /my-page/ instead of http://mydomain.com/my-page/).

Is it possible to manage this with DJANGOCMS_LINK_INTRANET_HOSTNAME_PATTERN?

Internal Link to Page on another Site

In a multisite setup an internal link may need to contain the domain to be valid. Currently this is not the case.

https://github.com/divio/djangocms-link/blob/2.1.1/djangocms_link/models.py#L134

It is unclear how to cleanly fix this. If we need to include the domain in the link it means we have to know stuff about the protocol (http vs https). In the example below I've chosen to use the protocol agnostic notation for the link. But this is not correct for all cases, as different sites may differing configurations regarding http and https.

    def get_link(self):
        if self.internal_link_id:
            link = self.internal_link.get_absolute_url()
            if (
                not self.page or
                self.page and self.internal_link.site_id != self.page.site_id
            ):
                link = '//{}{}'.format(
                    self.internal_link.site.domain,
                    link,
                )
        elif ...

Need tests!

This project is too important to not have tests.

Make use of the PageSmartLinkField from django-cms

I think we could merge both link and page field in one field in the same fashion we did it for the redirect field in django-cms.

Also this relates to django-cms/django-cms#2916, as you are using a FK here and we are not in the redirect field... would be nice to have the same behavior in both.

If you agree, I will try to make this happen in django-cms so we can just inherit from that here.

edit: also it would drop the django-select2 dependency.

"site_id" warning for future cms-version 3.6

Currently getting a warning from django-cms (cms version 3.5.2):

/usr/local/lib/python3.6/site-packages/djangocms_link/models.py:138: UserWarning: Pages no longer have a "site_id" attribute. To get the site id of any given page, call "site_id" on the page "node" object. This backwards compatible shim will be removed in version 3.6
if ref_page.site_id != getattr(self.page, 'site_id', None):
/usr/local/lib/python3.6/site-packages/djangocms_link/models.py:138: DontUsePageAttributeWarning: Don't use the page attribute on CMSPlugins! CMSPlugins are not guaranteed to have a page associated with them!
if ref_page.site_id != getattr(self.page, 'site_id', None):
/usr/local/lib/python3.6/site-packages/djangocms_link/models.py:139: UserWarning: Pages no longer have a "site_id" attribute. To get the site id of any given page, call "site_id" on the page "node" object. This backwards compatible shim will be removed in version 3.6
ref_site = Site.objects._get_site_by_id(ref_page.site_id)

"ref_page.site_id" should be changed in a future version for compatibility with upcoming cms version 3.6.

page_link field hidden by default when using Select2

Is there something that you need to do to get the select2 version of page_link to display?

If I import the standard CMS page select field it is visible in the form, but if I use Select2 there's a class of 'hidden' added to the field.

I really like the select2 field, so have I missed something glaringly obvious in the settings to get it to display?

select2 updates to v6

I've noticed that select2 updates to version 6 - which is not Django 1.8 compatible anymore.

djangocms-ckeditor + djangocms-link

An ongoing issue with multiple versions, the link plugin does not render within the ckeditor, when editing an existing plugin. No markup representing the link is being rendered into the editor. The issue only seems to exist when editing an existing plugin, it renders fine when adding a new one.

Current versions:
Django==1.6.8
djangocms-text-ckeditor==2.4.1
djangocms-link==1.5
django-cms==3.0.7

Steps:
Add a djangocms-ckeditor plugin
Add an djangocms-link plugin inline
Click source or save and re-edit

Allow optional link

I have made a CMS Plugin that inherit from AbstractLink but the link should be optional.

I looked into djangocms_link.models.BaseLink.clean() and think this is not possible, because of:

        if len(provided_link_fields) == 0 and not self.anchor:
            raise ValidationError(
                _('Please provide a link.')
            )

Internal links to published pages

Hello,

I notice that the drop-down for internal links only shows draft pages. Why is that? Shouldn't it be possible to add a link to a page that has already been published?

Ross

djangocms-link not setup properly in default Addon setup

originally reported by @digiology in django-cms/django-cms#6032

Summary

The default divio project has djangocms-link's LinkPlugin installed. However the settings file is missing DJANGOCMS_LINK_USE_SELECT2 = True which results in the Internal Link dropdown being empty without any errors or explanation.

Environment

  • Python version: 2.7.13
  • Django version: 1.8.18.1
  • django CMS version: 3.4.4.2

Fix

Needs to be fixed in aldryn_config.py

Exception in Django 1.11

Scope

flatatt seemed to be removed from django.form.widgets in this version.

Proposed fix

change
from django.forms.widgets import flatatt
to
from django.forms.utils import flatatt

Traceback

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/var/www/myproject/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "/var/www/myproject/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 337, in execute
    django.setup()
  File "/var/www/myproject/env/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/var/www/myproject/env/lib/python3.6/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models()
  File "/var/www/myproject/env/lib/python3.6/site-packages/django/apps/config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "/var/www/myproject/env/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "/var/www/myproject/env/lib/python3.6/site-packages/djangocms_link/models.py", line 16, in <module>
    from djangocms_attributes_field.fields import AttributesField
  File "/var/www/myproject/env/lib/python3.6/site-packages/djangocms_attributes_field/fields.py", line 17, in <module>
    from .widgets import AttributesWidget
  File "/var/www/myproject/env/lib/python3.6/site-packages/djangocms_attributes_field/widgets.py", line 6, in <module>
    from django.forms.widgets import flatatt
ImportError: cannot import name 'flatatt'

Release notes should mention backwards incompatible changes

There was recently a migration to rename fields on the Link model, this should be documented in the release notes since anyone who interacted directly with Link objects likely has broken code now.

Also, the path for the default template was changed, so any template overrides will be ignored after updating to 2.0.*.

Finally, several variables were removed from the context when rendering the template so any template overrides that depended on the old context variables will break.

AttributeError: 'Instance' object has no attribute 'page'

The get_link() method access self.page if internal link is used:

    def get_link(self):
        if self.internal_link:
            ref_page = self.internal_link
            link = ref_page.get_absolute_url()

            if ref_page.site_id != getattr(self.page, 'site_id', None):
                ref_site = Site.objects._get_site_by_id(ref_page.site_id).domain
                link = '//{}{}'.format(ref_site, link)

There is a warning in CMSPlugin():

    @property
    def page(self):
        warnings.warn(
            "Don't use the page attribute on CMSPlugins! CMSPlugins are not "
            "guaranteed to have a page associated with them!",
            DontUsePageAttributeWarning)
        return self.placeholder.page if self.placeholder_id else None

In my case i get a AttributeError: 'Instance' object has no attribute 'page'

Found no way to edit link when display name was forgotten

In a CKEditor Text Plugin, if a Link is created leaving blank the display name entry, there is no way to edit it. I see three solutions

  • add documentation if there is a way to edit the link!
  • add something like missing display name if the field is blank
  • authorize link editing in page structure

Adding a style field to the link plugin?

An option I frequently use on sites where we have cmsplugin-filer installed is the ability to define a list of classes for use in a dropdown in the link plugin form. On sites where we use djangocms-link, I often find myself wishing the same feature was available. Would be a pretty simple addition if you think it makes sense to port over. https://github.com/divio/cmsplugin-filer/blob/develop/cmsplugin_filer_link/models.py#L29

Wondering what the devs here think. Thanks a lot.

Spurious Django 1.7 migration

Running makemigrations in a 1.7 Django project with python 3 brings an unwanted migration:

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

    dependencies = [
        ('djangocms_link', '0002_auto_20140929_1705'),
    ]

    operations = [
        migrations.AlterField(
            model_name='link',
            name='mailto',
            field=models.EmailField(null=True, blank=True, help_text='An email address has priority over a text link.', verbose_name='email address', max_length=75),
            preserve_default=True,
        ),
    ]

The change is verbose_name='email address'

I think this is due to the en django.po file:

#: models.py:13
msgid "mailto"
msgstr "email address"

Removing email address and running compilemessages fixes the issue.

I do not know if this is intended or not by Django.

Issue or browser/OS behaviour when editing a link?

I've just had an issue raised with regard to editing an existing link in the editor.

If you double click on a link & the link dialog opens with only a part/word of the link selected, when you hit OK and save the link, it replaces the selected part of the link only. I'm not sure if that's easy to understand, so let me explain; if you have a link called click here and double click to edit it in the editor and the link dialog opens with only here selected, once you hit OK to save, the editor will then display click click here.

Is that initial selection behaviour controlled by the browser/OS or should the CKeditor/CMS ensure the whole link is selected when making the edit?

No selectable pages

I've got a really strange problem with an EC2 server. There are no selectable pages in the drop down :(

Running locally, connected to the same db, I get selectable pages. Also on a virtual server for development I can get a choice of pages, the database here is based on the same database and running the same code as the EC2 server.

I've also got a custom plugin which provides internal page links, using the same form field code that this plugin uses which has the same issues.

Is the page query which populates the field cached? I've got cache clearing available via a link in admin, clearing cache doesn't help the issue, so I'm just confused.

Not possible to use AbstractLink as associated link in own CMSPlugin

I would like to do something like this:

from django.db import models
from cms.models.pluginmodel import CMSPlugin

from djangocms_link.models import AbstractLink


class FooPluginModel(CMSPlugin):
    title = models.CharField(max_length=50)

class AssociatedLink(AbstractLink):
    plugin = models.ForeignKey(FooPluginModel, related_name="links")

This doesn't work and raise into a error like this:

ValueError: 'AssociatedLink' has more than one ForeignKey to 'FooPluginModel'.

This raised in django.forms.models._get_foreign_key() with local variables like:

fks_to_parent=[
    <django.db.models.fields.related.ForeignKey: parent>,
    <django.db.models.fields.related.OneToOneField: cmsplugin_ptr>
]

The problem is IMHO that djangocms_link.models.AbstractLink inherit from CMSPlugin

Any idea how to handle this?

Think there should be a Base-Link-class that inherit only from models.Model ?!?

Exception is raised when copying internal links between languages

If you create a link to a page in a language (eg. de) and your user has a different defined user language (by going to /admin/cms/usersettings/ and setting it eg. to en), you then get the following exception, because apparently get_language() then returns the user language instead of the current page language.

The same happens if a page in a given language contains a link plugin pointing to an internal page and a translation of this page is created and all plugins from the other language are copied.

Traceback (most recent call last):
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
    return self.application(environ, start_response)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 177, in __call__
    response = self.get_response(request)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/core/handlers/base.py", line 230, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/core/handlers/base.py", line 289, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/six.py", line 686, in reraise
    raise value
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/core/handlers/base.py", line 174, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/core/handlers/base.py", line 172, in get_response
    response = response.render()
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/response.py", line 160, in render
    self.content = self.rendered_content
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/response.py", line 137, in rendered_content
    content = template.render(context, self._request)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/backends/django.py", line 95, in render
    return self.template.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 206, in render
    return self._render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/test/utils.py", line 92, in instrumented_test_render
    return self.nodelist.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/loader_tags.py", line 173, in render
    return compiled_parent._render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/test/utils.py", line 92, in instrumented_test_render
    return self.nodelist.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/classytags/core.py", line 153, in render
    return self.render_tag(context, **kwargs)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/sekizai/templatetags/sekizai_tags.py", line 93, in render_tag
    rendered_contents = nodelist.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/classytags/core.py", line 153, in render
    return self.render_tag(context, **kwargs)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/cms/templatetags/cms_tags.py", line 499, in render_tag
    toolbar = render_to_string('cms/toolbar/toolbar.html', flatten_context(context))
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/loader.py", line 97, in render_to_string
    return template.render(context, request)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/backends/django.py", line 95, in render
    return self.template.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 206, in render
    return self._render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/test/utils.py", line 92, in instrumented_test_render
    return self.nodelist.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/templatetags/i18n.py", line 190, in render
    output = self.nodelist.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/defaulttags.py", line 220, in render
    nodelist.append(node.render_annotated(context))
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/defaulttags.py", line 220, in render
    nodelist.append(node.render_annotated(context))
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/loader_tags.py", line 209, in render
    return template.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/backends/django.py", line 95, in render
    return self.template.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 208, in render
    return self._render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/test/utils.py", line 92, in instrumented_test_render
    return self.nodelist.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/defaulttags.py", line 584, in render
    return self.nodelist.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/defaulttags.py", line 326, in render
    return nodelist.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/defaulttags.py", line 220, in render
    nodelist.append(node.render_annotated(context))
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/loader_tags.py", line 209, in render
    return template.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/backends/django.py", line 95, in render
    return self.template.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 208, in render
    return self._render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/test/utils.py", line 92, in instrumented_test_render
    return self.nodelist.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/defaulttags.py", line 584, in render
    return self.nodelist.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/templatetags/i18n.py", line 190, in render
    output = self.nodelist.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 1043, in render
    output = self.filter_expression.resolve(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 709, in resolve
    obj = self.var.resolve(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 850, in resolve
    value = self._resolve_lookup(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 913, in _resolve_lookup
    current = current()
  File "/home/vagrant/ENV/lib/python3.4/site-packages/djangocms_link/models.py", line 129, in get_short_description
    return '{} ({})'.format(self.name, self.get_link())
  File "/home/vagrant/ENV/lib/python3.4/site-packages/djangocms_link/models.py", line 140, in get_link
    link = self.internal_link.get_absolute_url()
  File "/home/vagrant/ENV/lib/python3.4/site-packages/cms/models/pagemodel.py", line 177, in get_absolute_url
    return reverse('pages-details-by-slug', kwargs={"slug": path})
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/core/urlresolvers.py", line 600, in reverse
    return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/core/urlresolvers.py", line 508, in _reverse_with_prefix
    (lookup_view_s, args, kwargs, len(patterns), patterns))
django.core.urlresolvers.NoReverseMatch: Reverse for 'pages-details-by-slug' with arguments '()' and keyword arguments '{'slug': ''}' not found. 1 pattern(s) tried: ['en/(?P<slug>[0-9A-Za-z-_.//]+)/$']

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.