def create_or_update_outofbandworker(request, worker_pk=None): """Create an OutOfBandWorker""" if request.method == 'POST': if worker_pk is None: new_obj = OutOfBandWorkerNodeForm(request.POST, request.FILES) else: worker_node = OutOfBandWorkerNode.objects.get(pk=worker_pk) new_obj = OutOfBandWorkerNodeForm(request.POST, request.FILES, instance=worker_node) if new_obj.is_valid(): worker = new_obj.save() if worker_pk is not None: json = simplejson.dumps("Worker successfully updated.") else: worker.active = worker.is_celeryd_running() context = { 'worker': {'worker': worker, 'workerForm': new_obj }} tpl = "celerymanagementapp/configure_outofbandworker_instance.html" html = render_to_response(tpl, context, context_instance=RequestContext(request)) success = { 'success': 'Worker successfully created.', 'html': urlquote(html.content), 'pk': worker.pk } json = simplejson.dumps(success) else: errors = [] for field in new_obj: errors.append({ 'field' : field.html_name, 'error' : field.errors }) failed = { 'failure' : errors, 'id': worker_pk } json = simplejson.dumps(failed) return HttpResponse("<textarea>" + json + "</textarea>")
def create_or_update_outofbandworker(request, worker_pk=None): if request.method == "POST": if worker_pk is None: out_of_band_worker_node_form = OutOfBandWorkerNodeForm(request.POST, request.FILES) else: worker = OutOfBandWorkerNode() out_of_band_worker_node_form = OutOfBandWorkerNodeForm(request.POST, request.FILES, instance=worker) if out_of_band_worker_node_form.is_valid(): if worker_pk is not None: json = simplejson.dumps("Worker successfully updated.") else: worker = out_of_band_worker_node_form.save(commit=False) worker.pk = 120 worker.active = True context = { 'worker': {'worker': worker, 'workerForm': out_of_band_worker_node_form }} html = render_to_response("celerymanagementapp/configure_outofbandworker_instance.html", context, context_instance=RequestContext(request)) success = { 'success': 'Worker successfully created.', 'html': urlquote(html.content), 'pk': worker.pk } json = simplejson.dumps(success) else: errors = [] for field in out_of_band_worker_node_form: errors.append({ 'field' : field.html_name, 'error' : field.errors }) failed = { 'failure' : errors, 'id': worker_pk } json = simplejson.dumps(failed) return HttpResponse("<textarea>" + json + "</textarea>")
def challenge(self): """ `challenge`: In cases where `is_authenticated` returns False, the result of this method will be returned. This will usually be a `HttpResponse` object with some kind of challenge headers and 401 code on it. """ path = urlquote(self.request.get_full_path()) tup = (self.login_url, self.redirect_field_name, path) return HttpResponseRedirect('%s?%s=%s' % tup)
def challenge(self): """ `challenge`: In cases where `is_authenticated` returns False, the result of this method will be returned. This will usually be a `HttpResponse` object with some kind of challenge headers and 401 code on it. """ path = urlquote(self.request.get_full_path()) tup = (self.login_url, self.redirect_field_name, path) return HttpResponseRedirect('%s?%s=%s' %tup)
def breadcrumbs(request): crumb_tmpl = '<a href="%s" class="%s">%s</a>' # '/video/a/b/c/' -> ['video', 'a', 'b', 'c'] crumbs = request.path.strip('/').split('/') # Drop video. # TODO(rnk): This encodes a dependency on the URL mapping. Oh well. crumbs = crumbs[crumbs.index('video') + 1:] html_parts = [] for (i, crumb) in enumerate(crumbs): # Aye, caramba! href = urlquote('/'.join(['', 'video'] + crumbs[:i + 1] + [''])) css_class = "crumb" if i + 1 == len(crumbs): css_class += " crumb-active" crumb = escape(crumb) html_parts.append(crumb_tmpl % (href, css_class, crumb)) return mark_safe(' » '.join(html_parts))
def breadcrumbs(request): crumb_tmpl = '<a href="%s" class="%s">%s</a>' # '/video/a/b/c/' -> ['video', 'a', 'b', 'c'] crumbs = request.path.strip("/").split("/") # Drop video. # TODO(rnk): This encodes a dependency on the URL mapping. Oh well. crumbs = crumbs[crumbs.index("video") + 1 :] html_parts = [] for (i, crumb) in enumerate(crumbs): # Aye, caramba! href = urlquote("/".join(["", "video"] + crumbs[: i + 1] + [""])) css_class = "crumb" if i + 1 == len(crumbs): css_class += " crumb-active" crumb = escape(crumb) html_parts.append(crumb_tmpl % (href, css_class, crumb)) return mark_safe(" » ".join(html_parts))
def __init__(self, name, format='json'): var_key = 'var_' + name try: self.data = cache.get(var_key) if self.data == None: url = 'http://ws.audioscrobbler.com/2.0/?method=artist.gettoptracks&artist=%s&api_key=%s&format=%s' % (urlquote(name), API_KEY, format) logging.debug(url) self.data = urlopen(url).read() cache.set(var_country, self.data, 3600) except Exception: pass
def _get_thumbnail_tag(model_instance, field, attrs): thumb = _get_thumbnail(model_instance, field, attrs) url = urlquote(unicode(thumb)) tag = '<img src="%s" width="%s" height="%s" alt="" />' % ( url, thumb.width(), thumb.height()) return mark_safe(tag)
def view_members(self, request, id_): mlist = get_object_or_404(db.List, pk=int(id_)) return HttpResponseRedirect( "../../../listmember/?mlist_name=%s" % (urlquote(mlist.name)))