def get(self, request, id_rule): """RulesDetailHandler READ method for GET requests @param request: is a django request object @param id_rule: is an id (PK) of a document type rule we are trying to return """ operator = PluginsOperator() try: mapping = operator.get_plugin_mapping_by_docrule_id(id_rule) except DmsException: log.error('RulesDetailHandler.read DmsException: Rule not found. 404') if settings.DEBUG: raise else: return Response(status=status.HTTP_400_BAD_REQUEST) # Removing mapping key that is not json serializable. resp_data = dict( active=mapping.active, doccode_id=mapping.doccode_id, id=mapping.id, doccode=mapping.doccode.title, before_retrieval_plugins=[plugin.name for plugin in mapping.before_retrieval_plugins.all()], storage_plugins=[plugin.name for plugin in mapping.storage_plugins.all()], database_storage_plugins=[plugin.name for plugin in mapping.database_storage_plugins.all()], before_removal_plugins=[plugin.name for plugin in mapping.before_removal_plugins.all()], before_storage_plugins=[plugin.name for plugin in mapping.before_storage_plugins.all()], ) log.info('RulesDetailHandler.read request fulfilled for rule %s' % id_rule) return Response(json.dumps(resp_data), status=status.HTTP_200_OK)
def read(self, request, id_rule): try: operator = PluginsOperator() mapping = operator.get_plugin_mapping_by_id(id_rule) start = 0 finish = None try: start = int(request.GET.get('start', 0)) finish = request.GET.get('finish', None) order = request.GET.get('order', None) searchword = request.GET.get('q', None) tag = request.GET.get('tag', None) filter_date = request.GET.get('created_date', None) if finish: finish = int(finish) except ValueError, e: log.error('FileListHandler.read ValueError %s' % e) if settings.DEBUG: raise else: pass file_list = operator.get_file_list(mapping, start, finish, order, searchword, tags=[tag], filter_date = filter_date) for item in file_list: ui_url = reverse('ui_document', kwargs={'document_name': item['name']}) thumb_url = reverse('api_thumbnail', kwargs={'code': item['name']}) item.update({ 'ui_url': ui_url, 'thumb_url': thumb_url, 'rule': mapping.get_name(), }) log.info('FileListHandler.read request fulfilled for start %s, finish %s, order %s, searchword %s, tag %s, filter_date %s.' % (start, finish, order, searchword, tag, filter_date)) return file_list
def update(self, document_name, options): """ Process update plugins. This is needed to update document properties like tags without re-storing document itself. Has ability to: - update document indexes - update document revision (upload new file to existing code) - update document tags TODO: continue this... @param options: should be dict with certain keys and values set that represent call requirements. keys and their meaning: - 'new_type' to change Document type. Should be of DocumentTypeRule model instance selected with desired type OR unicode PK of that model """ log.debug("UPDATE Document %s, options: %s" % (document_name, options)) new_name = self.option_in_options("new_name", options) new_type = self.option_in_options("new_type", options) new_file_revision = self.option_in_options("update_file", options) user = self.option_in_options("user", options) # Sequence to make a new name for file. # TODO: this deletes all old revisions, instead of real rename of all files... # Must become a plugins sequence task. if new_name: extension = self.option_in_options("extension", options) renaming_doc = self.read(document_name, options={"extension": extension, "user": user}) if new_name != renaming_doc.get_filename(): ufile = UploadedFile(renaming_doc.get_file_obj(), new_name, content_type=renaming_doc.get_mimetype()) document = self.create(ufile, {"user": user}) if not self.errors: self.delete(renaming_doc.get_filename(), options={"extension": extension, "user": user}) return document operator = PluginsOperator() doc = self.init_Document_with_data(options, document_name=document_name) if new_type is not None: # HACK: Read the data and remove thumbnails in one call old_document = self.read(document_name, {"user": user, "only_metadata": True, "remove_thumbnails": True}) # Retrieving file revisions and storing into self for plugins modifications. fr_data = old_document.get_file_revisions_data() for rev_id in fr_data.iterkeys(): temp_doc = self.read(document_name, {"user": user, "revision": rev_id}) doc.file_revisions[rev_id] = temp_doc.get_file_obj() # Storing new file revision of an object. It requires content setup from uploaded file. if new_file_revision: if "content_type" in new_file_revision.__dict__.iterkeys(): doc.set_mimetype(new_file_revision.content_type) else: error = "Error updating file revision for file: %s" % new_file_revision log.error(error) self.errors.append(error) doc = operator.process_pluginpoint(pluginpoints.BeforeUpdatePluginPoint, document=doc) doc = operator.process_pluginpoint(pluginpoints.UpdatePluginPoint, document=doc) doc = operator.process_pluginpoint(pluginpoints.DatabaseUpdatePluginPoint, document=doc) self.check_errors_in_operator(operator) return doc
def plugins(request, template_name='browser/plugins.html', extra_context=None): """ List of available plugins """ operator = PluginsOperator() plug = operator.get_plugin_list() extra_context = extra_context or {} extra_context['plugin_list'] = plug return render(request, template_name, extra_context)
def files_document(request, id_rule): mapping = get_object_or_404(models.DoccodePluginMapping, pk=id_rule) operator = PluginsOperator() file_list = operator.get_file_list(mapping) extra_context = { 'mapping': mapping, 'document_list': file_list, } return render(request, 'browser/files.html', extra_context)
def get(self, request): operator = PluginsOperator() try: plugin_list = operator.get_plugin_list() except Exception, e: # FIXME log.error('PluginsHandler.read Exception %s' % e) if settings.DEBUG: raise else: return Response(status=status.HTTP_400_BAD_REQUEST)
def read(self, request): operator = PluginsOperator() try: plugin_list = operator.get_plugin_list() except Exception, e: # FIXME log.error('PluginsHandler.read Exception %s' % e) if settings.DEBUG: raise else: return rc.BAD_REQUEST
def read(self, request, id_rule): operator = PluginsOperator() try: mapping = operator.get_plugin_mapping_by_id(id_rule) except Exception, e: # FIXME log.error('RulesDetailHandler.read Exception %s' % e) if settings.DEBUG: raise else: return rc.BAD_REQUEST
def plugins(request, template_name='browser/plugins.html', extra_context={}): """ List of available plugins """ operator = PluginsOperator() plugins = operator.get_plugin_list() extra_context['plugin_list'] = plugins return direct_to_template(request, template_name, extra_context=extra_context)
def delete(self, document_name, options): """Deletes Document() or it's parts from DMS.""" log.debug("DELETEE Document %s, options: %s" % (document_name, options)) operator = PluginsOperator() doc = self.init_Document_with_data(options, document_name=document_name) if self.option_in_options("delete_revision", options): doc = self.read(document_name, options) doc = operator.process_pluginpoint(pluginpoints.BeforeRemovalPluginPoint, document=doc) self.check_errors_in_operator(operator) return doc
def update(self, document_name, options): """ Process update plugins. This is needed to update document properties like tags without re-storing document itself. Has ability to: - update document indexes - update document revision (upload new file to existing code) - update document tags TODO: continue this... @param options: should be dict with certain keys and values set that represent call requirements. keys and their meaning: - 'new_type' to change Document type. Should be of DocumentTypeRule model instance selected with desired type OR unicode PK of that model """ log.debug('UPDATE Document %s, options: %s' % (document_name, options)) new_name = self.option_in_options('new_name', options) new_file_revision = self.option_in_options('update_file', options) user = self.option_in_options('user', options) # Sequence to make a new name for file. # TODO: this deletes all old revisions, instead of real rename of all files... # Must become a plugins sequence task. if new_name: extension = self.option_in_options('extension', options) renaming_doc = self.read(document_name, options={'extension': extension, 'user': user}) if new_name != renaming_doc.get_filename(): ufile = UploadedFile(renaming_doc.get_file_obj(), new_name, content_type=renaming_doc.get_mimetype()) document = self.create(ufile, {'user': user}) if not self.errors: self.delete(renaming_doc.get_filename(), options={'extension': extension, 'user': user}) return document operator = PluginsOperator() doc = self.init_Document_with_data(options, document_name=document_name) # Storing new file revision of an object. It requires content setup from uploaded file. if new_file_revision: if 'content_type' in new_file_revision.__dict__.iterkeys(): doc.set_mimetype(new_file_revision.content_type) else: error = 'Error updating file revision for file: %s' % new_file_revision log.error(error) self.errors.append(error) doc = operator.process_pluginpoint(pluginpoints.BeforeUpdatePluginPoint, document=doc) doc = operator.process_pluginpoint(pluginpoints.UpdatePluginPoint, document=doc) doc = operator.process_pluginpoint(pluginpoints.DatabaseUpdatePluginPoint, document=doc) self.check_errors_in_operator(operator) return doc
def read(self, request, id_rule): """RulesDetailHandler READ method for GET requests @param request: is a django request object @param id_rule: is an id (PK) of a document type rule we are trying to return """ operator = PluginsOperator() try: mapping = operator.get_plugin_mapping_by_docrule_id(id_rule) except Exception, e: # FIXME log.error('RulesDetailHandler.read Exception %s' % e) if settings.DEBUG: raise else: return rc.BAD_REQUEST
def read(self, request, id_rule): # FIXME: Requirement for this whole API hook is wrong. # Tags should be got with document metadata. Not with a separate reequest. try: operator = PluginsOperator() mapping = operator.get_plugin_mapping_by_id(id_rule) docrule = mapping.get_docrule() tags = TagsPlugin().get_all_tags(docrule=docrule) log.info('TagsHandler.read request fulfilled for rule %s' % id_rule) return map(lambda x: x.name, tags) except Exception, e: # FIXME log.error('TagsHandler.read Exception %s' % e) if settings.DEBUG: raise else: return rc.BAD_REQUEST
def get(self, request, id_rule): # FIXME: Requirement for this whole API hook is wrong. # Tags should be got with document metadata. Not with a separate reequest. try: operator = PluginsOperator() mapping = operator.get_plugin_mapping_by_docrule_id(id_rule) docrule = mapping.get_docrule() tags = TagsPlugin().get_all_tags(docrule=docrule) log.info('TagsHandler.read request fulfilled for rule %s' % id_rule) return Response(json.dumps(tags), status=status.HTTP_200_OK) except Exception, e: # FIXME log.error('TagsHandler.read Exception %s' % e) if settings.DEBUG: raise else: return Response(status=status.HTTP_400_BAD_REQUEST)
def get(self, request, id_rule): operator = PluginsOperator() try: mapping = operator.get_plugin_mapping_by_docrule_id(id_rule) except DmsException: return Response(status=status.HTTP_404_NOT_FOUND) start = int(request.GET.get('start', 0)) finish = request.GET.get('finish', None) order = request.GET.get('order', None) searchword = request.GET.get('q', None) tag = request.GET.get('tag', None) filter_date = request.GET.get('created_date', None) if finish: finish = int(finish) file_list = operator.get_file_list(mapping, start, finish, order, searchword, tags=[tag], filter_date=filter_date) for item in file_list: document_name = item['name'] code, suggested_format = os.path.splitext(document_name) if not suggested_format: api_url = reverse('api_file', kwargs={ 'code': code, }) else: suggested_format = suggested_format[ 1:] # Remove . from file ext api_url = reverse('api_file', kwargs={ 'code': code, 'suggested_format': suggested_format, }) thumb_url = reverse('api_thumbnail', kwargs={'code': item['name']}) item.update({ 'ui_url': api_url, 'thumb_url': thumb_url, 'rule': mapping.get_name(), }) log.info("""FileListHandler.read request fulfilled for: start %s, finish %s, order %s, searchword %s, tag %s, filter_date %s.""" % (start, finish, order, searchword, tag, filter_date)) return Response(file_list, status=status.HTTP_200_OK)
def get(self, request, id_rule): """RulesDetailHandler READ method for GET requests @param request: is a django request object @param id_rule: is an id (PK) of a document type rule we are trying to return """ operator = PluginsOperator() try: mapping = operator.get_plugin_mapping_by_docrule_id(id_rule) except DmsException: log.error( 'RulesDetailHandler.read DmsException: Rule not found. 404') if settings.DEBUG: raise else: return Response(status=status.HTTP_400_BAD_REQUEST) # Removing mapping key that is not json serializable. resp_data = dict( active=mapping.active, doccode_id=mapping.doccode_id, id=mapping.id, doccode=mapping.doccode.title, before_retrieval_plugins=[ plugin.name for plugin in mapping.before_retrieval_plugins.all() ], storage_plugins=[ plugin.name for plugin in mapping.storage_plugins.all() ], database_storage_plugins=[ plugin.name for plugin in mapping.database_storage_plugins.all() ], before_removal_plugins=[ plugin.name for plugin in mapping.before_removal_plugins.all() ], before_storage_plugins=[ plugin.name for plugin in mapping.before_storage_plugins.all() ], ) log.info('RulesDetailHandler.read request fulfilled for rule %s' % id_rule) return Response(json.dumps(resp_data), status=status.HTTP_200_OK)
def get(self, request, id_rule): operator = PluginsOperator() try: mapping = operator.get_plugin_mapping_by_docrule_id(id_rule) except DmsException: return Response(status=status.HTTP_404_NOT_FOUND) start = int(request.GET.get('start', 0)) finish = request.GET.get('finish', None) order = request.GET.get('order', None) searchword = request.GET.get('q', None) tag = request.GET.get('tag', None) filter_date = request.GET.get('created_date', None) if finish: finish = int(finish) file_list = operator.get_file_list( mapping, start, finish, order, searchword, tags=[tag], filter_date=filter_date ) for item in file_list: document_name = item['name'] code, suggested_format = os.path.splitext(document_name) if not suggested_format: api_url = reverse('api_file', kwargs={'code': code, }) else: suggested_format = suggested_format[1:] # Remove . from file ext api_url = reverse('api_file', kwargs={'code': code, 'suggested_format': suggested_format, }) thumb_url = reverse('api_thumbnail', kwargs={'code': item['name']}) item.update({ 'ui_url': api_url, 'thumb_url': thumb_url, 'rule': mapping.get_name(), }) log.info( """FileListHandler.read request fulfilled for: start %s, finish %s, order %s, searchword %s, tag %s, filter_date %s.""" % (start, finish, order, searchword, tag, filter_date) ) return Response(file_list, status=status.HTTP_200_OK)