DjangoCMS Plugin Tutorial: Poll Plugin list shows `poll object` for list of options - django-cms

I went through the plugin tutorial, as well as the preceding few, but it seems like there's a bug while trying to add a plugin.
On a page in Structure view, I have an empty placeholder. I click +. Click on Poll Plugin, and a modal pops up with a <select> that seems to have been generated through xhr at this route:
/en/admin/cms/page/add-plugin/?placeholder_id=13&plugin_type=PollPluginPublisher&plugin_language=en HTTP/1.1
Inside of that select is <option>s with "Poll object" for each poll that I've created. I choose one, and press save. The object shows up as a plugin for the placeholder. The odd part is that the correct __str__ (I use Python3, so I'm not using __unicode__) is being used here, which was gotten from the route /en/ HTTP/1.1: "Which browser do you prefer?"
Why is /en/ giving me the correct string representation of the PollPluginModel, but when using the Add Plugin modal /en/admin/cms/page/add-plugin/?... I get the Poll's string representation?

Related

What happens with WordPress after I activate a plugin

I would like to know what happens when I click on activate on a WordPress-Plugin on "Activate". Which files and functions get Triggered by WordPress.
How I actually think WordPress is working are these steps:
A file and function from WordPress is in a loop which gets triggered like this:
WordPress gets from the main-file the Header-fields and calls a file(which?) with the functions and defines it to the public output with echo or return.
WordPress calls the activation_function. When the user has not defined it then it does nothing.
The main file runs now like each other program.
While the program runs, WordPress has a file/function which gets triggered on "plugin->deactivate" and a function which will look similarly:"
(I am a type of human who likes to play compiler)
(I add a picture because I got only: "Your post appears to contain code that is not properly formatted as code" and could not solve like 10 minutes.)
This "Your post appears to contain code that is not properly formatted as code" is driving me crazy. I had to delete a few things.
I have looked on pages like these but no one goes so deep inside:
https://developer.wordpress.org/plugins/plugin-basics/
I appreciate you are thinking this way.
But before you get any answer to this, may i ask why you are asking this?
Meaning, what you want to understand? Is there any specific thing you want to achieve at plugin activation?
There is not much WordPress does while activating plugin.
WordPress scans each file or top level directory inside plugin directory and looks for header comment
See for more details: https://developer.wordpress.org/plugins/plugin-basics/#getting-started
Once it recognizes a plugin, it offers to activate it.
Here is a ruff sketch what happens once you click activate:
WordPress runs any callback function that is bound with register_activation_hook. Its not required to have an activation hook. If you have a callback function, WordPress runs it, if not, WordPress does not do anything. This callback function is used by plugins to do all sort of stuff like creating default options, creating required database tables, checking for dependent plugins , WordPress and PHP required version compatibility to name a few.
WordPress updates an option in DB to keep track of active plugins. so that these can be loaded for each page call. option id is active_plugins. Screenshot: https://snipboard.io/e7sjB9.jpg
On Next page load, WordPress check this option active_plugins and looks for these active plugins and load/run their header comments file code.
Hope it helps.
Regards,
Rao
P.S. this question belongs to https://wordpress.stackexchange.com/

Custom Template & Rapido Breaks URL Paths

Outline
I have a custom type (Dexterity) called "Gallery Profile", for this type I went into the ZMI (portal_skins/custom), created a new "Page Template" and wrote a custom template for my gallery. The gallery contains a bunch of lower down images and one main image of the owner of the gallery, like a News Item view but a gallery tacked on the bottom.
The customer wants this main image to be published to Facebook when someone hits 'Share' and some more specific info in the title when published.
Work carried out
Configured a Rapido script to write the 'og:image' meta data etc HTML that is required to get this to work (the default Plone stuff only publishes the sites logo unless you're viewing one Image type).
If I go to test the HTML coming out of Rapido via direct web address it works swimmingly. (site.com/##rapido/og_share/block/og_share) - I'm on the slightly older version of Rapido hence the non-plural version of block.
The problem
If you go to my gallery page where we have applied the template, then check the HTML, all of the OG meta data is pointing to the template instead of the current page its on.
This effects queries too (if for example you're using a script to find out what images are within a folder) - it searches /my_template instead of site.com/a_folder/my_template_is_on
In the Rapido Python file I've tried things like:
context.content.absolute_url()
context.content.absolute_url_path()
context.request['URL']
context.request['VIRTUAL_URL']
context.request['ACTUAL_URL']
... and probably more as I've been at this a while.
If you're not on the custom template, it works.
To Reproduce
Create a custom template
Assign it as the default view of a folder or any type.
In your template put <div tal:replace="structure python:context.REQUEST"></div> (just to see the difference)
In your Rapido try using context.app.log() and any of the above
Refresh your templated folder while checking the logs and the output from the context.REQUEST stuff.
You will see the differences and how Rapido is having a hard time getting the URL of the page you are on even though its there.
I've always had this problem with Rapido I just tend to work around it but in this particular situation I am stumped.
So in summary
Am I being an idiot and missing something obvious?
Is this possible?
Thank you for your time.

Programmatically render 404 in single page in concrete5 (version 7)

I've got a single page, where it checks a slug. If this slug can not be found in a database table, the single page should render the 404 page.
Something like this I have tried:
$this->render('/page_not_found');
Now, this goes to your active package single pages directory (packages/your_pkg_handle/single_pages/page_not_found.php). It should go to the active theme instead though... I have tried setting the second parameter to "null", as I thought that would be the pkgHandle, but no result. Obviously I'm missing something or this is not possible?
Try
$this->replace('/page_not_found');
instead.
This is a little convoluted, but the reasoning behind this is $this->render() actually renders the view with the current controller (which will mean looking into the package for the view), whereas $this->replace() will replace the rendering session entirely with a new controller, view and exit output.

Linking to a "File type" Dexterity Content Type

We're creating a database of files on a new Plone 4.3.2 website, using eea.facetednav as the main interface. In order to have multiple searchable "tags" plus additional information like publish year, article type, etc etc, we've created custom Dexterity content types for these "files". One of the fields on the Dexterity content type is to upload the actual file.
Everything was going swimmingly UNTIL I realized...
One of the basic functionalities of linking to "files" is now broken. Whereas we would expect creating an internal link to a file will prompt opening the file or downloading it when clicked, now it just takes you to the "view" for the new Dexterity content type, where there's a link to the actual file.
This is pretty cumbersome. Has anyone done this before, or found a way to have it automatically link to download the file? If we need to disable/scrap the Dexterity content type view in favor of the direct link, that's probably fine, but bonus points if you can think of a way to make this work both ways (i.e. have a linking method that takes it to the file and a linking method that takes it to the view).
This is the page I mean by "view", in case it's unclear:
... Off the top of my head, I can think of a weird Diazo solution of making a custom template that parses this view and automatically redirects to the file link, but that seems wrong/weird. Other thoughts?
I'll go for the bonus points, though I haven't fully tested this...
First, you have to designate your file field as the content type's "primary" field. Unfortunately this option doesn't show up in the UI so you have to edit the XML version of the schema (there's a button for this in recent versions of the dexterity control panel). Add xmlns:marshal="http://namespaces.plone.org/supermodel/marshal" as a namespace at the top, and add marshal:primary="true" to the field tag in question.
Then, find your type in portal_types and change the "Default view method" to ##download. (It usually starts out as view for Dexterity content types.) This should make the item's URL download the file rather than showing the normal view. It knows which field to use because you designated it as primary.
You can still access the normal view by adding /view to the end of the item's URL. If you want Plone to do this when linking to the type from navigation and folder contents (just like it does for built-in images and files), go to portal_properties/site_properties and add the type's id to the typesUseViewActionInListings list.
If I had to solve this problem, I'd take the "link" content type view in plone.app.contenttypes as a model.
When someone asks to see a link content type object, the view looks to see if the requestor has the Modify portal content permission on the link object. If they do, they see the conventional view, giving them the opportunity to edit. If they don't, the view returns a redirect to the target URL.
Your code would be simpler. After checking the permission, you'd only need to append ##download/field_name to get the redirect URL.

Drupal: can I specify a View for my search results?

I have a "Search" field in my website and I was wondering if I can assign my View to the search results, instead of using the default list.
Is this feasible ? How ?
thanks
It is possible to handle the search output by a view using the default search forms without exposing filters:
create a view of type content which displays all content types, display page
set Path: /search/node/%
add Contextual Filter "Search: Search Terms", then set "Provide default value" and "Raw value from URL" and "Path Component" to "3".
Now, every time you search for a node your view gets called instead of the default search result page because it is using the same path than the default search. The % is the argument which is handled by the Contextual Filter. Do not forget to set the filter to the 3rd component of the path which is the placeholder "%".
You can replace the default Search with a Views search instead. I haven't done this personally, but from what I've read it sounds straight forward. Create your "Search" View, then display it's "exposed filter" form instead of the default search form. More details here... http://groups.drupal.org/node/18582
Or, if you just want to make the search results look different, you can simply theme them, instead of using Views to do the searching. You can also control what fields (CCK and such) get displayed in the search results on the Display Fields > Search tab when editing the content type. I don't know the name of the template file for themeing search results of the top of my head, but if you have Theme Developer installed you can easily figure this out.
I've actually found the item "Search" in my Filters options in Views. I dunno how I could ignored it before. It actually exists, and works quite well. Solved.
You can use views to do search with exposed filters etc, but this is not a functionality that you can put on the search you have already. You can create a block in your search view and with theming replace what you got now with it instead.
This probably requires some work since the search box is usually not located in a region.

Resources