Ejemplo n.º 1
0
    def delete_subtitle(self, filename):
        from os import remove
        from helpers import endpoint_404

        query = {
            "@graph.ma:hasRelatedResource": {
                "$elemMatch": {
                    "@id": filename
                }
            }
        }

        bundle = self.model.find_one(query)

        if bundle is None:
            return endpoint_404()

        if not self.acl_write_check(bundle):
            return action_401()

        l = bundle.get("@graph").get("ma:hasRelatedResource")
        l[:] = [d for d in l if d.get('@id') != filename]
        bundle.save()

        remove(config.SUBTITLE_DIRECTORY + filename)

        return mongo_jsonify(bundle)
Ejemplo n.º 2
0
    def update_subtitle(self, filename, new_file):
        from helpers import endpoint_404

        query = {
          "@graph.ma:hasRelatedResource":{"$elemMatch": {"@id":filename}}
        }

        bundle = self.model.find_one(query)

        if bundle is None:
            return endpoint_404() 
        
        if not self.acl_write_check(bundle):
          return action_401()
        
        new_file.save(config.SUBTITLE_DIRECTORY + filename)
        
        return mongo_jsonify(bundle)
Ejemplo n.º 3
0
    def delete_subtitle(self, filename):
        from os import remove
        from helpers import endpoint_404

        query = {
          "@graph.ma:hasRelatedResource":{"$elemMatch": {"@id":filename}}
        }

        bundle = self.model.find_one(query)

        if bundle is None:
            return endpoint_404() 
        
        if not self.acl_write_check(bundle):
            return action_401()

        l = bundle.get("@graph").get("ma:hasRelatedResource")
        l[:] = [d for d in l if d.get('@id') != filename]
        bundle.save()
        
        remove(config.SUBTITLE_DIRECTORY + filename)

        return mongo_jsonify(bundle)
Ejemplo n.º 4
0
def Collection(collection,id=None):
	if collection in resource_lookup:
		coll=resource_lookup[collection](request)
		return coll.dispatch(id)
	else:
		return endpoint_404()