This is a very simple script to do a **simple** migration from plone content to django.
ATNewsItems and PloneArticles are imported into the django model *Article* (with Foreignkey to the django models *File* and *Image*). ATDocuments are imported into the django model *Page*.
**Usage**
1. Make sure that the Python version running Zope can import django
2. The django database should be writeable from within the Zope environment
3. Set the shell variable *DJANGO_MODULE_SETTING* to the settings file of the django project you want to import your Plone content to
4. Start the Zope server in the debug modus:
$ bin/zopectl debug
Then import the python module above, and pass the site you want to migrate to the start function:
import simple_migration
mysite = app.mysite
simple_migration.start(mysite)
Found 1253 objects
Saved Test Document Type: ATNewsItem
...
Hope it helps someone.
Used for the migration of **Plone-2.5.3** content in a **Python-2.4.4** environment.
Some template tags/filter for working with query strings in templates.
Examples:
{% load qstring %}
{% qstring %} # Prints current request's query string
{% qstring as current_qstring %} # Same but goes to context
{{ current_qstring|qstring_del:"key1" }} # Deletes all key1 values
{{ current_qstring|qstring_del:"key1&key2" }} # Deletes all key1 and key2values
{{ current_qstring|qstring_set:"key1=1&key2=2" }} # Deletes all old key1 and key2 values and adds the new values.
Formats a number in the local currency format. E.g., if `foo` is equal to `49277`, then
> ` {{ foo|currency }}`
would print
> `$49,277`
If your locale is the U.S. You can use this filter in your templates as described in the [Django documentation](http://www.djangoproject.com/documentation/templates_python/)
Template filter to format a start and end time in to a range. Uses Django's ["P" format](http://www.djangoproject.com/documentation/templates/#now) and assumes start and end time are on the same day or night before/morning after.
`{{ start_time|time_range:end_time }}`
Examples:
7-8 p.m.
8 p.m. - midnight
noon - 4 p.m.
9:45 a.m. - 5:15 p.m.
10:30 p.m. - 1:30 a.m.
Have you had a rather huge database, say 50-100+ tables? Why not compress the tables you don't want to see and expand the ones that you do want to see? This template should do the trick. It uses cookies to remember which tabs you have open and which ones you have closed. This should work on .91 to current.
How to install - just CP code and save as index.html toss in your media folder under /path_to_media/template_folder/admin/index.html. next download mootools and toss this into /path_to_media/js_folder/mootools.js
(alternatively you could be lazy and cp mootools into the script tag of this template)
A quick and dirty fix but it sure saves time trying to find the tables you are looking for.
This is a little improvement to the [idea](http://www.djangosnippets.org/snippets/540/) from sheats a few days ago.
I like it over the previous solutions because it doesn't involve doing anything other than running `./manage.py shell` inside your project directory. You don't have to create any files anywhere or remember to call anything, and `ipython` still works fine outside of a Django project.
Throw this code in `~/.ipython/ipy_user_conf.py` (`ipythonrc` has apparently been deprecated).
Add the attribute "rel='lightbox'" to all Links, if the target is an image.
`<a href="/path/to/image.jpg">Image</a>`
becomes
`<a rel="lightbox" href="/path/to/image.jpg">Image</a>`
Works for JPG, GIF and PNG Files.
This tag is meant to override the current implementation of '{% spaceless %}' tag and remove spaces at the beginning of a line too. I.e. a template like this:
<div>
<div>useless space up front</div>
</div>
will become this
`<div>`
`<div>useless space up front</div>`
`</div>`
All the other behaviour of spaceless stays the same!
Put this in your app/name/templatetags/tags.py
And if you want it to override the default "spaceless"-tag to the following
from django.template import add_to_builtins
add_to_builtins('app.name.templatetags.tags')
This is a customized version of the default `for` template tag which takes an optional `{% else %}` clause that will be displayed if the given array is empty.
from django.template import *
>>> t1 = Template("""
{% load mytags %}
{% for athlete in athlete_list %}
{{ athlete }}
{% else %}
No athlete in list!
{% endfor %}
""")
>>> c1 = Context(
{'athlete_list':
['me', 'myself', 'I']
})
>>> t1.render(c1)
u'me myself I '
>>> c2 = Context({})
>>> t1.render(c2)
u'No athlete in list!'
If you want to automatically override the builtin `for` template-tag add it to the builtins:
from django.template import add_to_builtins
add_to_builtins('python.path.to.mytags')
Tags like `url` and `trans` provide no way to get the result as a context variable. But how would you get a computed URL into a `blocktrans`?
This snippet solves the general problem. Just put the template code whose output you want to capture within `captureas` tags. For example:
{% captureas login_url %}{% url login %}{% endcaptureas %}
{% blocktrans %}
<a href="{{login_url}}">login</a>
{%endblocktrans%}
Disclaimer: I'm not the world's greatest programmer, so there may be better ways to do this, but it works for me (feel free to offer your improvements, though!).
Basically, this will pad an integer with leading zeros and return a string representation. User it like this:
{% forloop.counter|leading_zeros:"5" %}
...where "5" is the number of desired digits. In this case, if it was the 12th time through the forloop, the filter would return "00012".
Why do this? Either for alignment, such as in tables, or for aesthetics -- for an example, see [Shaun Inman's comment section](http://shauninman.com/archive/2007/11/16/mobilesafari_view_source).
This is a very basic -- yet fully functional -- framework for producing a loosely coupled plugin architecture. Full details of its use can be found [on my blog](http://gulopine.gamemusic.org/2008/jan/10/simple-plugin-framework/), but the basics are listed below.
## Defining a mount point for plugins
class ActionProvider:
__metaclass__ = PluginMount
## Implementing plugins
class Insert(ActionProvider):
def perform(self):
# Do stuff here
class Update(ActionProvider):
def perform(self):
# Do stuff here
## Utilizing plugins
for action in ActionProvider.plugins:
action.perform()
Yes, it really is that simple.
In the process of adapting to the new autoescaping thing, I've occasionally run into the sad situation where my development Django instance needs autoescape template tags in order to work, but when that code goes into production, I'm on a pre-autoescape Django revision. Hilarious hijinx ensue.
This snippet will attempt to load the new safe and force_safe filters and the autoescape template tag - failing the imports, it'll safely do nothing. The effect is that if you write templates for post-autoescape, but you still need them to work in pre-autoescape, this'll prevent the new filters and tags from causing errors in your older Django instances.
It's a pain to import all the Django models you want to use in the Python shell every time you start it. Here's how you can get IPython to autoload all your Django models for you every time you start the shell using ./manage.py shell.
Put the code in a .py file in the root of your project. Then tell IPython to load the script in ~/.ipython/ipythonrc in the "Python files to load and execute" section.
Sometimes you want to create a temporal variable to store something or do anything you want with it, problem is that django template system doesn't provide this kind of feature. This template tag is just for that.
Syntax::
{% assign [name] [value] %}
This will create a context variable named [name] with a value of [value]
[name] can be any identifier and [value] can be anything. If [value] is a callable, it will be called first and the returning result will be assigned to [name]. [value] can even be filtered.
Example::
{% assign count 0 %}
{% assign str "an string" %}
{% assign number 10 %}
{% assign list entry.get_related %}
{% assign other_str "another"|capfirst %}
{% ifequal count 0 %}
...
{% endifequal %}
{% ifequal str "an string" %}
...
{% endifequal %}
{% if list %}
{% for item in list %}
...
{% endfor %}
{% endif %}