Exclude plugins from Django cms search - django

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 :)

Related

Wagtail add page between two existing pages

I'm using wagtail in a django application with a graphql interface. Wagtail is only the backend and I'm implementing an editor with vuejs and a graphql interface using graphene.
I'd like to add a new page between two existing pages. The page order depends on the path parameter of the page. Is it possible to achieve this without manipulating the path param?
I can change the path param of the pages in wagtail, but this seems to me to be error prone and not as the creators of wagtail intended to be done.
Wagtail uses Django treebeard to enforce the tree structure of pages, and the Wagtail Page model subclasses the Treebeard Node model. I would strongly discourage manipulating the path parameters manually, that could completely mess up your structure. Instead use the Treebeard API to add/remove/move pages/nodes around.
The add_sibling method seems like it'd be the most appropriate here, used like this:
new_page = MyPageModel(
title='My Title'
slug='foo'
...
)
page = Page.objects.get(path='0001...')
page.add_sibling('right', instance=new_page)
Your new_page will be inserted to the right of your chosen page, and all other pages after it will be shifted to the right.

Adding a new section in Mezzanine CMS (Django) admin

I'm totally new to Mezzanine CMS. I got handed a site to work with and so far I've been able to do all the changes without problem. I've run across a problem in which they want a new section in the home page. I go to the admin section to edit the home page, but there is no extra content field.
On the home page, I see 4 sections "content" "priorities" "testimonials" and "clients". I would like to have another "content" area as a 5th section. How do I go on and add this section? I'm totally new to Django but would be appreciative if someone could explain or point in the right direction.
Here is a link to an image for reference.
https://imgur.com/a/sUKOtvS
Thanks in advance
The homepage content would be backed by a Django model with attributes for the partners and testimonial fields. You'll need to find the Python class for this model in your code base (you could search for those field names), and you'll need to add a new attribute for the new section you need.
Django and Mezzanine have lots of different field types you can use for these attributes, so consult their respective documentation for how those work (Django's are a lot more comprehensive, so start there).
Once you've done that, you'll need to create a database migration for the new attribute - that adds the field to the database table that will store the actual content, again consult the Django documentation for how these work.
Finally you may need to add the new field to the Admin class, which is the Python class (similar to the model) that controls which fields appear in the admin interface, and how they appear. I say "may" as these generally appear automatically without any code, but if things have been modified to a certain extent, you may need to do this manually.

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.

Ember nested dynamic forms

I'm new to Ember.js but I decided to try it for my task.
The task is to make a dynamic form builder: user should be able to add boxes with names and then insert field configs (which are forms) into that boxes.
Field configs are editable and they should be saved after edit.
In the backend I use Rails+AMS+Mongo and the data structure looks like that:
Company has one UsersProfileConfig
UsersProfileConfig has many BoxConfigs
BoxConfig has many FieldConfigs
In Ember I've already created models for BoxConfigs and FieldConfigs and basic routes for them.
Now I feel stuck and don't know what to do next and whether it was a good idea to use Ember for that.
Could anyone suggest me workflow or next development steps?

Integrate existing blog code into Django-CMS?

If I already have a blog app done with Django and I want to use it with my new Django CMS site, is it okay to simply drop it into my new Django CMS project as a decoupled app and match anything /blog/ to the blog app as apposed to a Django CMS plugin? I guess what I need to know is when is it best to write my Django app as a plugin vs an entire app?
Thx
JeffC
Yes, but you don't just drop it into the urls.py, instead you can write an AppHook to tie your blog's URL scheme to a particular page in your CMS.
Plugins on the other hand are useful if you want to inserts particular aspects of you app into other page's placeholders - for example to show your latest 3 posts on the frontpage.
You might also want to include your blog's paths in a breadcrumb or menu on your site - in that case you need to write a custom Menu too.
Finally, it might also be useful to make use of django cms's placeholders in you blog model. His would allow you to post a variety of content via plugins.