Integrating a third-party application

We’ve already written our own django CMS plugins and apps, but now we want to extend our CMS with a third party app, Aldryn News & Blog.

First, we need to install the app into our virtual environment from PyPI:

  1. pip install aldryn-newsblog

Add the app and any of its requirements that are not there already to INSTALLED_APPS in settings.py. Some will be already present; it’s up to you to check them:

  1. 'aldryn_apphooks_config',
  2. 'aldryn_boilerplates',
  3. 'aldryn_categories',
  4. 'aldryn_newsblog',
  5. 'aldryn_people',
  6. 'aldryn_reversion',
  7. 'djangocms_text_ckeditor',
  8. 'easy_thumbnails',
  9. 'filer',
  10. 'parler',
  11. 'reversion',
  12. 'sortedm2m',
  13. 'taggit',

One of the dependencies is django-filer. It provides a special feature that allows nicer image cropping. For this to work it needs it’s own thumbnail processor (easy-thumbnails) to be inserted in settings.py:

  1. THUMBNAIL_PROCESSORS = (
  2. 'easy_thumbnails.processors.colorspace',
  3. 'easy_thumbnails.processors.autocrop',
  4. # 'easy_thumbnails.processors.scale_and_crop',
  5. 'filer.thumbnail_processors.scale_and_crop_with_subject_location',
  6. 'easy_thumbnails.processors.filters',
  7. )

aldryn-newsblog uses aldryn-boilerplates to provide multiple sets of templates and staticfiles for different css frameworks. We’re using bootstrap3 in this tutorial, so lets choose bootstrap3.:

  1. ALDRYN_BOILERPLATE_NAME='bootstrap3'

Add boilerplates finder to STATICFILES_FINDERS:

  1. STATICFILES_FINDERS = [
  2. 'django.contrib.staticfiles.finders.FileSystemFinder',
  3. # important! place right before django.contrib.staticfiles.finders.AppDirectoriesFinder
  4. 'aldryn_boilerplates.staticfile_finders.AppDirectoriesFinder',
  5. 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
  6. ]

If STATICFILES_FINDERS is not defined in your settings.py just copy and paste the above code.

Add the boilerplate template loader to TEMPLATE_LOADERS:

  1. TEMPLATE_LOADERS = (
  2. 'django.template.loaders.filesystem.Loader',
  3. 'aldryn_boilerplates.template_loaders.AppDirectoriesLoader',
  4. 'django.template.loaders.app_directories.Loader',
  5. 'django.template.loaders.eggs.Loader'
  6. )

Add the boilerplates context processor to TEMPLATE_CONTEXT_PROCESSORS:

  1. TEMPLATE_CONTEXT_PROCESSORS = [
  2. # ...
  3. 'aldryn_boilerplates.context_processors.boilerplate',
  4. ]

Since we added a new app, we need to update our database:

  1. python manage.py migrate

Start the server again.

The newsblog application comes with a django CMS apphook, so add a new django CMS page (let’s call it ‘Blog’), and add the blog application to it as you did for Polls in the previous tutorial step. In this case we also have to add an “Application configuration” (see the field right under the apphook field). You can configure some settings here, like the url format. It’s also possible to add multiple instances of the application, if you like. The Instance namespace should be blog (this is used for reversing urls). Choose Blog as the Application title and choose whatever Permalink type you prefer.

Publish the new page, and you should find the blog application at work there.

You may need to restart your server at this point.

You can add new blog posts using the admin, but also have a look at the toolbar. When you’re within the urls of the blog, you should see an extra menu item called “Blog”. You can now select “Blog” > “Add new article…” from it and add a new blog post directly from there.

Try also inserting a “Latest articles” plugin into another page - as a good django CMS application, Aldryn News & Blog comes with plugins.

In the next tutorial, we’re going to integrate our Polls app into the toolbar in, just like the blog application has been.