Any way to organize images into folders in Wagtail CMS? - django

I'm trying to use Wagtail, the Django CMS. The images uploaded via the admin interface all go to the same place and it seems there is no way to organize images except by tagging them. Is there any way to organize them into folders or to search for them by date uploaded?
Furthermore, the search function for the images at least on the Wagtail demo installation, does not pull up any results if searching by the tag name (it does work with the search term in the title field).
Any suggestions for how to organize images in Wagtail would be appreciated!

Wagtail 1.4 introduced the concept of Collections which was their way of address this need:
Images and documents can now be organised into collections, set up by
administrators through the Settings -> Collections menu item. User
permissions can be set either globally (on the ‘Root’ collection) or
on individual collections, allowing different user groups to keep
their media items separated.
Don't think you can search by tag though...

If you need more than a flat folder structure, there is also this project:
https://github.com/anteatersa/Wagtail-Image-Folders
which is a replacement for the built-in wagtailimages app. I haven't tried it myself though.

Related

How might one implement Site-specific Tags?

My code shop is developing a multi-tenant Wagtail site, and we'd like each Site to have its own set of tags. We want this so that tags defined by users of Site A don't appear in the autocompleter or the "popular tags" listing for users of Site B.
Would this be possible with a custom Tag model? I'm thinking that we could prefix the tag's slugs with the hostname of the current Site, then filter them based on that prefix when pulling tags for the "popular tags" listing or the autocompleter.
If this is not currently possible, could Wagtail be monkey-patched to support it? If so, what code might need to change?
A custom tag model would be the way to go, yes. One issue you'd currently have to work around (logged here: https://github.com/wagtail/wagtail/issues/3577) is that the autocomplete view is hard-coded to use the default tag model, so to use a custom one you'd need to duplicate that view in your own app, along with the AdminTagWidget that references it.

Exclude plugins from Django cms search

I'm using aldryn-search on my Django CMS site. One of my custom plugins has a ManyToMany field to Django groups, to indicate which user groups may see the plugin (and of course the child plugins). I'm considering this field in the render() method of the plugin.
This works fine on the page, but I can't find a way to prevent the regarding plugins from being indexed by the search (which is Elastic Search). Any idea?
So to exclude the plugin from being searched completely.
You can set search_fulltext = False in your plugin class or plugin model.
To exclude the plugin only from users who do not have access to it is a bit more work but is not too complex.
You would have to create a dedicated index class for this plugin and deactivate it from cms page search as shown below.
Then in the dedicated plugin index class, add a MultiValueField to hold a list of user ids that can see this plugin, note that you'll have to make sure to only index plugins that have a page attached to them plugins.filter(placeholder__page__isnull=False) and also only plugins whose page is published and public.
After finishing the index class/logic, if using solr, then update schema to reflect new field.
Rebuild the index.
Here's an example on how the query could look like:
if request.user.is_authenticated():
SearchQueryset().models(PluginClass).filter(allowed_user_ids=request.user.pk)
Let me know how it goes :)

What is a good Django file-browser for non-admin users?

Do any of you know of a Django app out there for allowing users to browse for files, and upload new ones? The ones I have found seem to be built as an add-on for the admin interface (django-filebrowser, django-filer).
Not aiming for anything incredibly complex, just something that allows a user to upload files and then browse between folders (either specific directories on the server, or artificially generated "folders" out of some model field).
I recall the admin tutorial mentioned "The admin isn’t intended to be used by site visitors. It’s for site managers."
My thought from above is that it would be bad practice to simply allow users to see content via the admin interface, and that it would be better to create an app to allow for this.
To get the convenience that your end users usually expect in the age of google drive, you really want a complex javascript filebrowser that plays nicely with django.
I'm using yawd-elfinder which is a great django backend for elfinder to manage my students' association's website with great success ( About 1500 users with different groups and privileges).
Features:
Yawd-elfinder can manage local files but also use Django filesystem storages to connect to remote filesystems. A set of django options allows control over file and directory permissions, accepted mime types, max file sizes etc.
It allows you to have fairly complex management of files and different permissions for different users by activating different roots and/or mapping them differently based on the user.
Furthermore you have capabilities like drag and drop, upload by drag and drop and it's very customizable.
I'm not sure it's maintained anymore, but you can find working code here with the relevant views and templates.

Django search engine for tempates

I have a Django app that has an accompanying user guide. Page content for the user guide is stored in a directory of templates. Haystack seems to be the most popular Django search engine, but it is only recommended for use on model data and doesn't seem to provide template indexing.
What's the best method of indexing the Django template content for search? I could create a model which stores the rendered templates, and index that using Haystack. Is there any software out there that does this already? Or any alternative ways of doing this? Any solution needs should preferably include rendered content (i.e. can't just index the templates straight from disk). I also wish to avoid any external ad-supported search engines like Google Custom Search and Django integration is desirable.
Any suggestions would be much appreciated, thanks.
haystack_static_pages is made just for this purpose.
The app is designed to crawl and index specified rendered pages on your own site. You configure the URLs or URL names and then use the management command to crawl your site.
It's worth noting a few things about this up front. Haystack is pretty tightly coupled to the Django ORM, so what haystack_static_pages does is add a model for static content and then dump crawled content into the model as a precursor to indexing. It also appears to be designed around the 1.x version of Haystack.

How to setup groups (sub-sites) in Django

I'm new to Django and I come from Drupal family. There we have Organic Groups with which we can create groups of content and subsites; how do I do something like that with Django?
Say I'm making this site for my company using Django and every department in my company needs a private section on the site. For example, the design people have their own part of the website into which the back-end developers can not come in. And the back-end developers will have the same thing too.
I want to build the site in such a way that I just login into Django admin and add a new category or subsite or group (whatever the Django term is) with the same settings from other groups or with similar settings.
It depends on what you mean by "private section". You should probably try looking at it from a different angle:
Django splits a site's functionality by means of "apps". Each app does its specific thing, and gets a set of tables in the database. Apps can access each others' tables. For example, it's common for other apps to access the Auth app's user, group, and permissions tables. Is this what you mean by "sub sites"?
As for access control, users can be assigned to groups and they can have various administrative permissions assigned to them. Add, change, and delete permissions are automatically generated for each model (i.e. database table). You can also add your own permissions.
I don't think you'll be able to separate the designers from the back-end developers at the Django level. You'll need to do something else, such as maintain separate source repositories for each and merge them to create the usable site (each group would have read-only access to the other). It really depends on your teams' discipline, because these elements can get intertwined.
Django recommends that static files be served by something else, say directly from your web server, or from another machine with a simple HTTP server (no CGI/WSGI/whatever). This is because Django can only slow down static files compared to direct service. However, for testing, ther is a static page server you can enable.
Given all that, static files usually amount to CSS, images, media, and JavaScript. Of these, the back-end people might want to mess with the JS, but that's it, so this could be in the designers' repo.
The Django tree itself has the code for the site and the apps. It's almost all back end stuff. The exception is the HTML template files, located in the "templates" directory in each app. These are the files that are filled in with the context data supplied by the back-end view code. I have no idea if this is front or back end for you guys; it could be mostly back end if there's a lot of CSS discipline, but I think that's unlikely.
There are a lot of things that you can do in Django that make life easier for one side or the other. For example, template tags allow custom Python code to generate HTML to insert into the page. I use these to generate tab bars and panes, for example.
I really can't help much more without getting a better picture of what your needs are. The question is still vague. You're probably best off taking a day or two going through the tutorial, seeing what the Django perspective is, and then working out how (or if!) it fits into your needs.