Skip to main content

Adds a link plugin to django CMS

Project description

pypi coverage python django djangocms djangocms4

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.

preview.gif

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:

django CMS Link has a weak dependency on django Filer. If django Filer is installed and configured appropriately, django CMS Link will allow linking files.

  • Django Filer 1.7 or higher

  • djangocms-atrributes-field 1.0 or higher

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

Linkable models

Added in version 5:

By default, django CMS Link will autodetect which Django or Django CMS models it can create internal links to. To make a model appear in the list of internal links, you need to

  • register a model admin for the model and provide a search_fields attribute. django CMS Link uses the same search logic as the Django admin.

  • provide a get_absolute_url() method on the model. This method should return the URL of the model instance.

If you do not want to use auto detection, you can provide a list of models in the DJANGOCMS_LINKABLE_MODELS setting using dotted strings:

DJANGOCMS_LINKABLE_MODELS = [
    'myapp.mymodel',
]

Attention: Page objects are always linkable.

django CMS Link will use the model admin’s get_queryset method to retrieve the list of objects. If you want to add custom filters, sorting or site handling, you can add a get_link_queryset method to the model admin:

class MyModelAdmin(admin.ModelAdmin):
    def get_link_queryset(self, request, site_id):
        """Only used by djangocms-link: returns queryset to select link targets from."""
        qs = self.get_queryset(request)
        return qs.filter(is_public=True)

Large search-sets

If you have a large number of internally linkable models, you can use the DJANGOCMS_LINK_MINIMUM_INPUT_LENGTH setting to require a minimum number of characters typed before the search is triggered. The higher the number, the smaller the average result set size. The default is 0:

# Require at least 2 characters to be typed before searching for pages
DJANGOCMS_LINK_MINIMUM_INPUT_LENGTH = 2

By default django CMS Link will paginate the search results. You can change the page size by setting the DJANGOCMS_LINK_PAGINATE_BY setting. The default is 50:

# Show 100 results per "page"
DJANGOCMS_LINK_PAGINATE_BY = 100

Note, that in the admin paginated search results repeat the modle verbose name.

Non-standard hostnames

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.

Running Tests

You can run tests by executing:

virtualenv env
source env/bin/activate
pip install -r tests/requirements.txt
pytest

Upgrading from version 4 or lower

django CMS Link 5 is a rewrite of the plugin. If you are updating from version 4 or lower, you will notice

  • the new re-usable link widget, greatly simplifying the user interface

  • an improved management of multi-site situations, essentially avoiding the unnecessary additon of the host name to the URL in plugin instances that are not in a page placeholder (such as links on aliases or static placeholder)

  • a re-usable admin endpoint for querying available links which can be used by other apps such as djangocms-text.

  • Links are generated by template tags or template filters instead of the model’s get_link() method. This allows multiple links in future models. The get_link() method on the plugin’s model is still available for backwards compatibility.

Migrations should automatically existing plugin instances to the new model fields.

WARNING: We strongly recommend to backup your database before updating to version 5. The migration is tested but they do remove unused fields from the database. If you encounter any issues, please report them on GitHub.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djangocms_link-5.0.0.tar.gz (502.3 kB view details)

Uploaded Source

Built Distribution

djangocms_link-5.0.0-py3-none-any.whl (161.9 kB view details)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page