Example #1
0
def stored(request, directory=None):
    '''Stored is the endpoint which is redirected to when we've uploaded a
    new file into the Object Store via a Form Post. The underlying HPCloud
    bindings shouldn't take care of this since it's a front-end related
    thing.

    stored will take care of updating our local cache of metadata when
    we're adding files.
    '''
    if request.GET.get('status') == '201':
        filename_unclean = request.COOKIES.get("lastfile")
        if not filename_unclean:
            raise Http404
        # TODO: Unfuck this code.
        filename = ntpath.split(urllib.unquote(filename_unclean).decode("utf8"))[-1]
        mimetype = mimetypes.guess_type(filename)
        # Disgusting crap ends here ------
        StoredObject.get_or_create(
            container=settings.OBJECT_STORE_CONTAINER,
            name=directory+filename,
            content_type="" if not mimetype[0] else mimetype[0],
            url=generate_share_url(
                "%s/%s" % (settings.OBJECT_STORE_CONTAINER, directory+filename)
            )
        ).save()
        return HttpResponseRedirect("/success_upload/")
    else:
        return HttpResponseRedirect("/fail_upload/?=" + request.GET.get('message'))
Example #2
0
 def handle(self, *args, **options):
     '''implementation'''
     storedobjects = []
     for obj in get_object_list("/"):
         objdata = get_object_list(obj["name"])
         for subobj in objdata:
             storedobjects.append(
                 StoredObject(
                     container=obj["name"],
                     name=subobj["name"],
                     url=generate_share_url(obj["name"] + "/" + subobj["name"]),
                     content_type=subobj["content_type"]
                 )
             )
     StoredObject.objects.bulk_create(storedobjects)