if denom:
x = total / denom
else:
x = 0try:
x = total / denom| def monitor_progress(things, every=1000, message="Processing `{current}` of `{total}`"): | |
| print "Beginning processing" | |
| total = len(things) | |
| for idx, thing in enumerate(things): | |
| if not idx % every: | |
| print message.format(current=idx, total=total) | |
| yield thing | |
| print "Finished processing" |
if denom:
x = total / denom
else:
x = 0try:
x = total / denom| from django.db import models | |
| class Owner(models.Model): | |
| pass | |
| class Thing(models.Model): | |
| owner = models.ForeignKey(Owner, related_name='things') |
| @celery.task | |
| def first(): | |
| # generates an iterable | |
| return 1, 2, 3 | |
| @celery.task | |
| def second(thing): | |
| """ | |
| Takes a single item from the iterable from `first`, does some computation, |
| from urlparse import urljoin | |
| from django.contrib.auth.tokens import default_token_generator | |
| from django.utils.http import int_to_base36 | |
| from django.contrib.sites.models import Site | |
| from django.core.urlresolvers import reverse | |
| from emailtools import MarkdownEmail | |
| import requests | |
| import csv | |
| from dateutil import parser | |
| from BeautifulSoup import BeautifulSoup | |
| CACHE = {} | |
| """ | |
| https://us.pycon.org/2013/schedule/presentation/35/ | |
| https://us.pycon.org/2013/schedule/presentation/68/ |
| class ClearableFileInput(widgets.ClearableFileInput): | |
| """ | |
| Changes the default file widget to be easier to target with CSS | |
| """ | |
| template_with_initial = u'<div class="fileField"><span class="currently">%(initial_text)s:</span> %(initial)s %(clear_template)s<span class="change">%(input_text)s:</span> %(input)s</div>' | |
| template_with_clear = u'<div class="clear">%(clear)s <label for="%(clear_checkbox_id)s">%(clear_checkbox_label)s</label></div>' | |
| initial_template = u'<a href="{{url}}">{{name}}</a>' | |
| def render(self, name, value, attrs=None): |
Pattern for email sending.
www.| from django.utils.http import is_safe_url | |
| from django.core.urlresolvers import reverse | |
| from django.utils.safestring import mark_safe | |
| class WithNextUrlMixin(object): | |
| """ | |
| This view will use whatever value was submitted as `next` as the success | |
| url, as long as the url resolves correctly. | |
| """ |
| class BaseViewMixin(object): | |
| def dispatch(self, request, *args, **kwargs): | |
| # Set earlier to ensure that other class methods which expect | |
| # these values to be present can be called in `init` | |
| self.request = request | |
| self.args = args | |
| self.kwargs = kwargs | |
| # Run the complete request, returning a response, but allowing | |
| # `init` to either raise exceptions, or hijack the response if |