Creating new Drupal nodes based on created HTML output - drupal

I have a module in Drupal 6 that parses an XML feed and creates HTML output. Essentially, I have a long string of the HTML that should populate that page. This is being done on a local server at the moment.
What I would like to do is take that output and create new nodes with it. I've seen that, with the Feeds module, I can import content. What I would like to do is have the following procedure:
Run script (cron or user-instigated)
Generate HTML content and put it to some sort of local file
Import that content with a module on my production server (Feeds or otherwise)
As I mentioned, my HTML content is currently exactly as I want it. However, it needs to become static nodes (for posterity's sake). I can programmatically generate the HTML for each node, however I'm not sure what the best way to do this would be.

Have a look at the Import HTML module.

I simply created Drupal nodes programmatically. Turned out to be easiest.

Related

Plone setuphandler- In a setuphandler, how can I programatically add/create a folderish content type at root of Plonesite?

I have have made a folderish content type called supplier_folder, which displays a list of suppliers that can be added under it, and their information. I can add it through the navigation bar, but I would like to add it programatically during setup.
I have been following the tutorial on custom installer code (http://docs.plone.org/develop/addons/components/genericsetup.html#custom-installer-code-setuphandlers-py) and have looked at creating objects programatically (http://docs.plone.org/develop/plone/content/creating.html).
Unfortunately, the second article says I need to have a folder created. How can I get around this and add the supplier_folder object at the Plone Site outside of a folder?
IIRC, only users with role Manager or Site Administrator can add content to the root of the site; you can overcome this limitation in two ways:
by using the _constructInstance method as it bypasses the permissions when creating an item
by switching roles inside your code with plone.api.env.adopt_roles
I personally prefer the second one.
you can see an example of a pretty complex setuphandlers.py in interlegis.portalmodelo.policy package.
When you create a new Plone site, it's also creating some default content types.
Look at how Plone do: https://github.com/plone/Products.CMFPlone/blob/1471828ee97a8dd84396bad4a3286be514819869/Products/CMFPlone/setuphandlers.py#L119
There are a couple of ways to achieve this. The buildin mechanism is to use GenericSetup in combination with "structure" folder as described here: http://koansys.com/tech/create-plone-initial-content-with-generic-setup
In short you need the following:
Create a folder "structure" in your Generic Setup profile (in general, under profiles/default)
Create a .objects file with the following content: "suppliers,supplier_folder"
in "structure" create a folder "suppliers" with a .properties file and content:
[DEFAULT]
title = Suppliers
description = Some usefull description text
As far as I remember this is ok for simple structures likes your. If you have complex structures with folders and sub-folders and want more specific control you probably need to write python code. I made some stuff here: https://github.com/collective/zettwerk.setup/blob/master/zettwerk/setup/structure.py
But zettwerk.setup is not yet released, but you should be able to integrate the structure.py right into your project. Than you can the handle_structure method into your setuphandlers.py and passing a structure dict like this:
handle_structure(portal, [{'id': 'suppliers', 'portal_type': 'supplier_folder'}])
The advantage of this method is, that you can also control metadata like workflow state, default page setting, portlets, local roles and some others.

Drupal6: View that shows a directory structure

I've built a content type to handle document upload. My content type uses a Book node to handle directories/subdirectories and I would like to show a couple of Views that shows the directories structure. When clicking on a directory I would like to show, in another view, all the documents inserted in that directory.
Do you know any existing examples of Views/Panels? That shows a similar structure, as in the Windows Explorer, using Views2?
You can use this module: views_tree
Also tree-like can be built via argument handlers...

How to create custom CSS "on the fly" based on account settings in a Django site?

So I'm writing a Django based website that allows users select a color scheme through an administration interface.
I already have middleware/context processors that links the current request (based on domain) to the account.
My question is how to dynamically serve the CSS with the account's custom color scheme.
I see two options:
Add a CSS block to the base template that overrides the styles w/variables passed in through a context processors.
Use a custom URL (e.g. "/static/dynamic/css/< website_id >/styles.css") that gets routed to a view that grabs all the necessary values and creates the css file.
I'm content with either option, but was wondering if anyone else out there has dealt with similar problems and could give some insight as to "Best Practices".
Update : I'm leaning towards option number 2, as I think this will allow for better caching down the road. So it's dynamic the first time, gets stored in memcache (or whatever), and invalidated when a user updates their settings in the admin site.
Update: Firstly, I'd like to thank everyone for their suggestions thus far. All the answers thus far have focused around generating static files. Though this would work great in production, it feels like a tremendous burden during development. If I wanted to add a new element to be styled, or tweak existing styles I'd have to go through and recreate each and every css file. Sure, this could be done with a management command, but I just don't feel it's worth it. Doing it dynamically would add 1 maybe 2 queries to each page load, which is something I'm not worried about at this stage. All I need to know is that at some point I will be able to cache it without rewriting the whole thing.
I've used option #2 with success. There are 2 decent ways of updating the generated static files that I know of:
Use a version querystring like /special_path.css?v=11452354234 where the v parameter is generated from a database field, key in memcached, or some other persistent file. Version gets updated by admin, or for development you would just make the generation not save if the parameter was something special like v=-1. You'll need a process to clean up the old generations after some time.
Don't use a version querystring, but have it look first for the generated file, if it can't find it, it generates it. You can create a cron job or WSGI app that looks for filesystem changes for development, and have a hook from your admin panel that deletes generations after an update. Here's an example of the monitoring, which you would have to convert to be specific to your generations and not to Django. http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Monitoring%5FFor%5FCode%5FChanges
Could generate the css and store it in a textfield in the same model as the user profile/settings. Could then have a view to recreate them if you change a style. Then do your option 1 above.
Nice question.
I would suggest to pre-generate css file after colors scheme is saved. This would have positive impact on caching and overall page loading time. You can store your css files in directory /media/css/custom/<id or stometing>/styles.css or /media/css/custom/<id or sth>.css and in template add <link rel="stylesheet" href="/media/css/custom/{{some_var_pointing _to_file_name}}" />
You can also do the trick with some random number or date in css file name that could be changed each time file is saved. Thanks to this browser will load the file immediately in case of changes.
UPDATE: example of using model to improve this example
To make managing of those file easy you can create simple model (one per user):
class UserCSS(models.Model):
bg_color = models.CharField(..)
...
...
Fields (like bg_color) can represent parts of your css file. You can ovveride save method to add logic that creates css file for user (by rendering some template).
In case your file format change you can make changes in your's model definition (with some default values for new fields), make little changes in template and run save method for each exisintg instance of class. This would renew your css files.
That should work nicely.
I would create an md5 key with the theme elements, store this key in the user profile and create a ccs file named after this md5 key : you gain static file access and automatic theme change detection.

Drupal module to manipulate every node's body

After importing content from a legacy website using the Feeds module, I'm left with node bodies that contains links back to the old website.
Is there a Drupal module that will perform a one-time process to iterate through each node, manipulating the content of nodes using some custom code?
You could easily write a PHP script to step through the node_revisions table and do your processing there. If you're comfortable with custom code, it's probably the fastest way.
You could write your own module with the intent of running it once. There is a Drupal hook_init() you can utilize to fire code when a module is on, and the page is loaded up. Within that function, you can query against all the nodes in the node table with db_query, iterate over each node and do a preg_replace on the link you want to change. After modifying the $node object, use node_save($node) at the end of the loop to save the node changes.
Alternatively, you can use a module like Link Checker, Path Redirect and/or Global Redirect to link old paths to new ones and look for busted links.
I usually run an SQL query in phpMyAdmin. See my post on http://drupal.org/node/718700#comment-2616682.
A late answer, but nevertheless.
There is a pathologic module which can be used to fix links in nodes. For example, to make them absolute or to rewrite host part.

Is there a Drupal module for importing text and images?

I'm very new to Drupal, and am wondering if there's an API that external programs can call to transfer text and images directly into my Drupal site.
Yes. There are several ways to accomplish this in Drupal:
If you're doing a one-time import, try the Node Import module --- this lets you import content from a CSV file.
If you want your Drupal site to provide a web-based API to which new content can be POSTed (via, for example, XMLRPC), check out the Services module.
If you want your Drupal site to periodically retrieve content from other sites (RSS feeds, for example), check out FeedAPI.
If you want to write your own PHP code to create new content, check out this article for an introduction.
Not sure what you mean by having a module for importing text, but there is one specifically for images: the Image module. Here is an excerpt from its project page:
... allows users with proper permissions to upload images into Drupal. Thumbnails and additional sizes are created automatically.
Images could be posted individually to the front page, included in stories or grouped in galleries.
Importing text can be performed directly as one of the other existing entity types.

Resources