def delete(blobId, release='draft'): try: try: thumbnail = None dbGrid = Db().getGridFs('blobs') filename = "%s.%s" % (blobId, release) thumbnail = dbGrid.get_last_version(filename) dbGrid.delete(thumbnail._id) thumbnail = thumbnail.__dict__['_file'] except CorruptGridFile as e: pass except NoFile: pass finally: if not thumbnail or not 'activity' in thumbnail: return True a = ActivityFactory.get(thumbnail['activity']) node = a.__dict__[release] if not 'blobs' in node: return True if not thumbnail['type'] in node['blobs']: return True node['blobs'][thumbnail['type']].remove(str(blobId)) ActivityFactory.update(a) except DbError: output.error('cannot access db', 503)
def insert(blobType, release, data, content_type, **args): try: blobId = ObjectId() dbGrid = Db().getGridFs('blobs') dbGrid.put( data, content_type=content_type, filename="%s.%s" % (blobId, release), type=blobType, blobId=str(blobId), release=release, **args ) if 'activity' in args: a = ActivityFactory.get(args['activity']) if not 'blobs' in a.__dict__[release]: a.__dict__[release]['blobs'] = {} if not blobType in a.__dict__[release]['blobs']: a.__dict__[release]['blobs'][blobType] = [] a.__dict__[release]['blobs'][blobType].append(str(blobId)) ActivityFactory.update(a) except DbError: output.error('cannot access db', 503) return blobId
def unreport(self, environ, params): try: a = ActivityFactory.get(params['rid']) if not a: output.error('not found', 404) a.isReported = False ActivityFactory.update(a) output.success(a.toObject(), 200) except Error: pass return Controller().getResponse(True)
def publish(self, environ, params): try: req = Controller().getRequest() a = ActivityFactory.get(params['rid']) if not a: output.error('not found', 404) a.publish() for (blobType, values) in a.published['blobs'].items(): for blobId in values: BlobFactory.publish(blobId) ActivityFactory.update(a) output.success(a.toObject(), 200) except Error: pass return Controller().getResponse(True)
def save(self, environ, params): try: req = Controller().getRequest() if not req.json: output.error('invalid json', 400) a = ActivityFactory.get(params['rid']) if not a: output.error('not found', 404) a.saveDraft(**req.json) ActivityFactory.update(a) output.success(a.toObject(), 200) except Error: pass return Controller().getResponse(True)