def mbox(request, patch_id): patch = get_object_or_404(Patch, id=patch_id) response = HttpResponse(content_type="text/plain") # NOTE(stephenfin) http://stackoverflow.com/a/28584090/613428 if six.PY3: response.write(patch_to_mbox(patch).as_bytes(True).decode()) else: response.write(patch_to_mbox(patch).as_string(True)) response['Content-Disposition'] = 'attachment; filename=' + \ patch.filename().replace(';', '').replace('\n', '') return response
def mbox(request, patch_id): patch = get_object_or_404(Patch, id=patch_id) response = HttpResponse(content_type="text/plain") # NOTE(stephenfin) http://stackoverflow.com/a/28584090/613428 if six.PY3: response.write(patch_to_mbox(patch).as_bytes(True).decode()) else: response.write(patch_to_mbox(patch).as_string(True)) response['Content-Disposition'] = 'attachment; filename=' + \ patch.filename.replace(';', '').replace('\n', '') return response
def mbox(request, patch_id): patch = get_object_or_404(Patch, id=patch_id) response = HttpResponse(mimetype="text/plain") response.write(patch_to_mbox(patch).as_string(True)) response['Content-Disposition'] = 'attachment; filename=' + \ patch.filename().replace(';', '').replace('\n', '') return response
def patch_get_mbox(patch_id): """Return mbox string for the given patch ID.""" try: patch = Patch.objects.filter(id = patch_id)[0] return patch_to_mbox(patch).as_string() except: return ""
def mbox(request, patch_id): patch = get_object_or_404(Patch, id=patch_id) response = HttpResponse(content_type="text/plain") response.write(patch_to_mbox(patch).as_string(True)) response['Content-Disposition'] = 'attachment; filename=' + \ patch.filename().replace(';', '').replace('\n', '') return response
def series_mbox(request, revision): options = {"patch-link": request.GET.get("link", None), "request": request} patches = revision.ordered_patches() data = "\n".join([patch_to_mbox(x, options).as_string(True) for x in patches]) response = HttpResponse(content_type="text/plain") response.write(data) response["Content-Disposition"] = "attachment; filename=" + revision.series.filename() return response
def series_mbox(revision): patches = revision.ordered_patches() data = '\n'.join([patch_to_mbox(x).as_string(True) for x in patches]) response = HttpResponse(content_type="text/plain") response.write(data) response['Content-Disposition'] = 'attachment; filename=' + \ revision.series.filename() return response
def series_mbox(request, revision): options = { 'patch-link': request.GET.get('link', None), 'request': request, } patches = revision.ordered_patches() data = '\n'.join([patch_to_mbox(x, options).as_string(True) for x in patches]) response = HttpResponse(content_type="text/plain") response.write(data) response['Content-Disposition'] = 'attachment; filename=' + \ revision.series.filename() return response
def mbox(request, username, bundlename): bundle = get_object_or_404(Bundle, owner__username=username, name=bundlename) if not (request.user == bundle.owner or bundle.public): return HttpResponseNotFound() mbox = '\n'.join([patch_to_mbox(p).as_string(True) for p in bundle.ordered_patches()]) response = HttpResponse(content_type='text/plain') response['Content-Disposition'] = \ 'attachment; filename=bundle-%d-%s.mbox' % (bundle.id, bundle.name) response.write(mbox) return response
def mbox(request, username, bundlename): bundle = get_object_or_404(Bundle, owner__username = username, name = bundlename) if not (request.user == bundle.owner or bundle.public): return HttpResponseNotFound() mbox = '\n'.join([patch_to_mbox(p).as_string(True) for p in bundle.ordered_patches()]) response = HttpResponse(content_type='text/plain') response['Content-Disposition'] = \ 'attachment; filename=bundle-%d-%s.mbox' % (bundle.id, bundle.name) response.write(mbox) return response
def patch_get_mbox(patch_id): """Get a patch by its ID in mbox format. Retrieve a patch matching a given patch ID, if any exists, and return in mbox format. Args: patch_id (int): The ID of the patch to retrieve. Returns: The serialized patch matching the ID, if any, in mbox format, else an empty string. """ try: patch = Patch.objects.filter(id=patch_id)[0] return patch_to_mbox(patch).as_string(True) except Patch.DoesNotExist: return ''