This code publishes an iCal file that can be subscribed to in Google Calendar. They change the way they interpret iCal data occasionally, so this may break, I'll try to keep it up to date.
There is some crazy string replace stuff going on there, I haven't yet convinced vObject to format things properly.
Feedback welcome.
*Note: this works for my existing feeds, but if I add a new feed to GCal, the timezones are incorrect, I'm working on that.
It's often useful to dynamically create filter criteria, and Q objects are useful for that, but sometimes you need to make a combined Q composed of various alternates. This bit of code eases the awkwardness of creating the first Q so that there's a combiner, plus the odd case of no criteria.
The canonical notion of urls ending in slashes dates from a web where urls were used to access documents and files this is no longer the case so keeping your urls witouth trailing slashes makes them prettier. The problem is that many people/blogs/spiders/browsers could end up with a url with slashes which can be problematic for you SEO, or confuse users.
This script is for sites with no trailing slash dicipline in their urls, and to prevent everybody getting a horrible 404 for a simple slash you just got to remove it and issue a permanent redirect (301) and you'll get your pretty urls your cake and eat it too.
I must stress, you will have to edit all your public urls removing the slashes like so:
url(r'^login$', login,}
If you forget, to edit them and visit the url, your browser will remember the redirect and you'll have to clean the browsing history to fix it.
Template filter that truncates the text when it exceeds a certain number of characters.
It deletes the last word only if partial.
Adds '...' at the end of the text, only if truncated.
Examples (text == 'Lorem ipsum dolor sit amet', len(text) == 26)
{{ text|truncatewords_by_chars:30 }}
'Lorem ipsum dolor sit amet'
{{ text|truncatewords_by_chars:25 }}
'Lorem ipsum dolor sit...'
{{ text|truncatewords_by_chars:21 }}
'Lorem ipsum dolor sit...'
{{ text|truncatewords_by_chars:20 }}
'Lorem ipsum dolor...'
By Davide Muzzarelli
Template filter that divides a list into an exact number of columns.
The number of columns is guaranteed.
Example (list == [1,2,3,4,5,6,7,8,9,10]):
{% for column in list|columns:3 %}
<ul>
{% for item in column %}
<li>{{ item }}</li>
{% endfor %}
</ul>
{% endfor %}
Result:
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
<ul>
<li>5</li>
<li>6</li>
<li>7</li>
</ul>
<ul>
<li>8</li>
<li>9</li>
<li>10</li>
</ul>
By Davide Muzzarelli
1. Define a subclass extends forms.ModelForm
2. Add the __init__ method
3. Define your ModelForm extends this class
4. Define the CSS for "large","xlarge" and "xxlarge",or define yourself.
Dead simple snippet. Paste it in some models (i use project_specific/models.py), and you don't need to run update_index anymore. When a model is deleted from the database: it is deleted from the index. When a model is saved (created or modified): it is updated in the index.
Define validator `multiple_email_validator` that splits value by commas and calls `validate_email` validator for each element found.
Then define MultipleEmailField with this default validator and augmented max_length.
Then ... use it!
1) Simply create a "management/commands" folder in one of your INSTALLED_APPS folders. Then add a "reboot.py" file in your "management/commands"
2) In settings.py, you can OPTIONALLY add:
PROJECT_NAME = 'Blah'
PROJECT_DOMAIN = 'blah.com'
These two settings will be used to create a "Site" object as well as a superuser. If you choose not to use these settings, the reboot command simply reverts to using your DATABASES[default] username as superuser.
3) Execute the command via "python manage.py reboot"
Enjoy.
Template filter to mark-up individual form fields.
Usage :
In template - {% load form_custom %}
then for a form field - {{ form.field|form_row:"default" }}
for default wrapper
or - {{ form.field|form_row:"lbl_cls=some_class_name&reqd=no" }}
to pass option args seperated by &
Optional args are :-
wrapper_cls - override default field wrapper div class name
error_cls - override default field error div class name
lbl_cls - override default label_tag div class name
label - yes/no default is yes - output label_tag
reqd - yes/no default is yes - marks up required fields as bold with label ending with *
See code for all default args.
This snippet is greatly inspired by [@jlorich](http://djangosnippets.org/users/jlorich/)'s useful [#2436](http://djangosnippets.org/snippets/2436/).
The main difference is that I wanted to choose the names of my URL params instead of being forced into naming them "value1", "value2", etc. When reversing the URL you have to remember that the kwargs aren't friendly. By using the same names in the `filters` list, you don't have to change the way your otherwise write the URL pattern. Also it's clear throughout how you'll be filtering the QuerySet.
The other change I made was "erroring early". This avoids running the QuerySet all over again inside `object_detail()` just to have it raise an exception we could have caught the first time.
Counter tag. Can be used to output and increment a counter.
For usage, see docstring in the code.
This is the first complete tag that I've implemented, I hope that there are no bugs and that it's thread safe.
You're looking at the most-bookmarked snippets on the site; if you'd like to help useful snippets show up here, sign up for an account and you'll get your own bookmarks list.