當前位置: 首頁>>代碼示例>>Python>>正文


Python ExistDB.describeDocument方法代碼示例

本文整理匯總了Python中eulexistdb.db.ExistDB.describeDocument方法的典型用法代碼示例。如果您正苦於以下問題:Python ExistDB.describeDocument方法的具體用法?Python ExistDB.describeDocument怎麽用?Python ExistDB.describeDocument使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在eulexistdb.db.ExistDB的用法示例。


在下文中一共展示了ExistDB.describeDocument方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: publish

# 需要導入模塊: from eulexistdb.db import ExistDB [as 別名]
# 或者: from eulexistdb.db.ExistDB import describeDocument [as 別名]
def publish(request):
    """
    Admin publication form.  Allows publishing an EAD file by updating or adding
    it to the configured eXist database so it will be immediately visible on
    the public site.  Files can only be published if they pass an EAD sanity check,
    implemented in :meth:`~findingaids.fa_admin.utils.check_ead`.

    On POST, sanity-check the EAD file specified in request from the configured
    and (if it passes all checks), publish it to make it immediately visible on
    the site.  If publish is successful, redirects the user to main admin page
    with a success message that links to the published document on the site.
    If the sanity-check fails, displays a page with any problems found.
    """
    # formerly supported publish from filename, but now only supports
    # publish from preview
    if 'preview_id' not in request.POST:
        messages.error(request, "No preview document specified for publication")
        return HttpResponseSeeOtherRedirect(reverse('fa-admin:index'))

    id = request.POST['preview_id']

    # retrieve info about the document from preview collection
    try:
        # because of the way existdb.query.queryset constructs returns with 'also' fields,
        # it is simpler and better to retrieve document name separately
        ead = get_findingaid(id, preview=True)
        ead_docname = get_findingaid(id, preview=True, only=['document_name'])
        filename = ead_docname.document_name
    except (ExistDBException, Http404):     # not found in exist OR permission denied
        messages.error(request,
            '''Publish failed. Could not retrieve <b>%s</b> from preview collection.
            Please reload and try again.''' % id)

        # if ead could not be retrieved from preview mode, skip processing
        return HttpResponseSeeOtherRedirect(reverse('fa-admin:index'))

    # determine archive this ead is associated with
    archive = None
    if not ead.repository:
        messages.error(request,
            '''Publish failed. Could not determine which archive <b>%s</b> belongs to.
            Please update subarea, reload, and try again.''' % id)
    else:
        archive_name = ead.repository[0]
        # NOTE: EAD supports multiple subarea tags, but in practice we only
        # use one, so it should be safe to assume the first should be used for permissions
        try:
            archive = Archive.objects.get(name=archive_name)
        except ObjectDoesNotExist:
            messages.error(request,
            '''Publish failed. Could not find archive <b>%s</b>.''' % archive_name)

    # bail out if archive could not be identified
    if archive is None:
        return HttpResponseSeeOtherRedirect(reverse('fa-admin:index'))

    # check that user is allowed to publish this document
    if not archive_access(request.user, archive.slug):
        messages.error(request,
            '''You do not have permission to publish <b>%s</b> materials.''' \
            % archive.label)
        return HttpResponseSeeOtherRedirect(reverse('fa-admin:index'))

    errors = []
    try:
        # NOTE: *not* using serialized xml here, because it may introduce
        # whitespace errors not present in the original file.
        ok, response, dbpath, fullpath = _prepublication_check(request, filename, archive)
        if ok is not True:
            # publication check failed - do not publish
            return response

        # only load to exist if there are no errors found
        db = ExistDB()
        # get information to determine if an existing file is being replaced
        replaced = db.describeDocument(dbpath)

        try:
            # move the document from preview collection to configured public collection
            success = db.moveDocument(settings.EXISTDB_PREVIEW_COLLECTION,
                    settings.EXISTDB_ROOT_COLLECTION, filename)
            # FindingAid instance ead already set above
        except ExistDBException, e:
            # special-case error message
            errors.append("Failed to move document %s from preview collection to main collection." \
                            % filename)
            # re-raise and let outer exception handling take care of it
            raise e

    except ExistDBException as err:
        errors.append(err.message())
        success = False

    if success:
        # request the cache to reload the PDF - queue asynchronous task
        result = reload_cached_pdf.delay(ead.eadid.value)
        task = TaskResult(label='PDF reload', object_id=ead.eadid.value,
            url=reverse('fa:findingaid', kwargs={'id': ead.eadid.value}),
            task_id=result.task_id)
        task.save()
#.........這裏部分代碼省略.........
開發者ID:emory-libraries,項目名稱:findingaids,代碼行數:103,代碼來源:views.py

示例2: Command

# 需要導入模塊: from eulexistdb.db import ExistDB [as 別名]
# 或者: from eulexistdb.db.ExistDB import describeDocument [as 別名]
class Command(BaseCommand):    
    help = """Tasks for managing eXist-db index configuration file.

Available subcommands:
  load-index      - load index configuration file to eXist
  show-index      - show the contents of index configuration file currently in eXist
  index-info      - show information about index configuration file in eXist (owner, date modified, etc.)
  remove-index    - remove index configuration from eXist
  reindex         - reindex the configured eXist collection with the loaded index
  """

    arg_list = ['load-index', 'show-index', 'index-info', 'remove-index', 'reindex']

    args = ' | '. join(arg_list)

    # FIXME/TODO: possibly convert into a django LabelCommand 
    
    def handle(self, *args, **options):
        if not len(args) or args[0] == 'help':
            print self.help
            return

        cmd = args[0]
        if cmd not in self.arg_list:
            print "Command '%s' not recognized" % cmd
            print self.help
            return

        # check for required settings (used in all modes)
        if not hasattr(settings, 'EXISTDB_ROOT_COLLECTION') or not settings.EXISTDB_ROOT_COLLECTION:
            raise CommandError("EXISTDB_ROOT_COLLECTION setting is missing")
            return
        if not hasattr(settings, 'EXISTDB_INDEX_CONFIGFILE') or not settings.EXISTDB_INDEX_CONFIGFILE:
            raise CommandError("EXISTDB_INDEX_CONFIGFILE setting is missing")
            return

        collection = settings.EXISTDB_ROOT_COLLECTION
        index = settings.EXISTDB_INDEX_CONFIGFILE

        try:
            # Explicitly request no timeout (even if one is configured
            # in django settings), since some tasks (such as
            # reindexing) could take a while.
            self.db = ExistDB(timeout=None)

            # check there is already an index config
            hasindex = self.db.hasCollectionIndex(collection)

            # for all commands but load, nothing to do if config collection does not exist
            if not hasindex and cmd != 'load-index':
                raise CommandError("Collection %s has no index configuration" % collection)

            if cmd == 'load-index':
                # load collection index to eXist

                # no easy way to check if index is different, but give some info to user to help indicate
                if hasindex:
                    index_desc = self.db.describeDocument(self.db._collectionIndexPath(collection))
                    print "Collection already has an index configuration; last modified %s\n" % index_desc['modified']
                else:
                    print "This appears to be a new index configuration\n"

                message =  "eXist index configuration \n collection:\t%s\n index file:\t%s" % (collection, index)

                success = self.db.loadCollectionIndex(collection, open(index))
                if success:
                    print "Succesfully updated %s" % message
                    print """
If your collection already contains data and the index configuration
is new or has changed, you should reindex the collection.
            """
                else:
                    raise CommandError("Failed to update %s" % message)

            elif cmd == 'show-index':
                # show the contents of the the collection index config file in exist
                print self.db.getDoc(self.db._collectionIndexPath(collection))

            elif cmd == 'index-info':
                # show information about the collection index config file in exist
                index_desc = self.db.describeDocument(self.db._collectionIndexPath(collection))
                for field, val in index_desc.items():
                    print "%s:\t%s" % (field, val)

            elif cmd == 'remove-index':
                # remove any collection index in eXist
                if self.db.removeCollectionIndex(collection):
                    print "Removed collection index configuration for %s" % collection
                else:
                    raise CommandError("Failed to remove collection index configuration for %s" % collection)


            elif cmd == 'reindex':
                # reindex the collection
                if not self.db.hasCollection(collection):
                    raise CommandError("Collection %s does not exist" % collection)

                print "Reindexing collection %s" % collection
                print "-- If you have a large collection, this may take a while."
                start_time = time.time()
#.........這裏部分代碼省略.........
開發者ID:0xffea,項目名稱:eulexistdb,代碼行數:103,代碼來源:existdb.py

示例3: Command

# 需要導入模塊: from eulexistdb.db import ExistDB [as 別名]
# 或者: from eulexistdb.db.ExistDB import describeDocument [as 別名]
class Command(BaseCommand):
    help = """Tasks for managing eXist-db index configuration file.

Available subcommands:
  load-index      - load index configuration file to eXist
  show-index      - show the contents of index configuration file currently in eXist
  index-info      - show information about index configuration file in eXist (owner, date modified, etc.)
  remove-index    - remove index configuration from eXist
  reindex         - reindex the configured eXist collection with the loaded index
  """

    arg_list = ['load-index', 'show-index', 'index-info', 'remove-index', 'reindex']

    args = ' | '. join(arg_list)

    def get_password_option(option, opt, value, parser):
        setattr(parser.values, option.dest, getpass())


    option_list = BaseCommand.option_list + (
        make_option('--username', '-u',
            dest='username',
            action='store',
            help='''Username to use when connecting to eXist (overrides any in local settings)'''),
        make_option('--password', '-p',
            dest='password',
            action='callback', callback=get_password_option,
            help='''Prompt for password (required when --username is specified)'''),
        )


    # FIXME/TODO: possibly convert into a django LabelCommand

    def handle(self, *args, **options):
        if not len(args) or args[0] == 'help':
            print self.help
            return

        cmd = args[0]
        if cmd not in self.arg_list:
            print "Command '%s' not recognized" % cmd
            print self.help
            return

        # check for required settings (used in all modes)
        if not hasattr(settings, 'EXISTDB_ROOT_COLLECTION') or not settings.EXISTDB_ROOT_COLLECTION:
            raise CommandError("EXISTDB_ROOT_COLLECTION setting is missing")
            return
        if not hasattr(settings, 'EXISTDB_INDEX_CONFIGFILE') or not settings.EXISTDB_INDEX_CONFIGFILE:
            raise CommandError("EXISTDB_INDEX_CONFIGFILE setting is missing")
            return

        collection = settings.EXISTDB_ROOT_COLLECTION
        index = settings.EXISTDB_INDEX_CONFIGFILE

        credentials = {}
        if options.get('username') is not None:
            credentials['EXISTDB_SERVER_USER'] = options.get('username')
        if options.get('password') is not None:
            credentials['EXISTDB_SERVER_PASSWORD'] = options.get('password')

        try:
            # Explicitly request no timeout (even if one is configured
            # in django settings), since some tasks (such as
            # reindexing) could take a while.

            if credentials:
                # NOTE: override_settings is a test utility, but this is currently
                # the simplest way to specify credentials, since by default existdb
                #
                with override_settings(**credentials):
                    self.db = ExistDB(timeout=None)
            else:
                self.db = ExistDB(timeout=None)

            # check there is already an index config
            hasindex = self.db.hasCollectionIndex(collection)

            # for all commands but load, nothing to do if config collection does not exist
            if not hasindex and cmd != 'load-index':
                raise CommandError("Collection %s has no index configuration" % collection)

            if cmd == 'load-index':
                # load collection index to eXist

                # no easy way to check if index is different, but give some info to user to help indicate
                if hasindex:
                    index_desc = self.db.describeDocument(self.db._collectionIndexPath(collection))
                    print "Collection already has an index configuration; last modified %s\n" % index_desc['modified']
                else:
                    print "This appears to be a new index configuration\n"

                message = "eXist index configuration \n collection:\t%s\n index file:\t%s" % (collection, index)

                success = self.db.loadCollectionIndex(collection, open(index))
                if success:
                    print "Succesfully updated %s" % message
                    print """
If your collection already contains data and the index configuration
is new or has changed, you should reindex the collection.
#.........這裏部分代碼省略.........
開發者ID:mangalam-research,項目名稱:eulexistdb,代碼行數:103,代碼來源:existdb.py

示例4: publish

# 需要導入模塊: from eulexistdb.db import ExistDB [as 別名]
# 或者: from eulexistdb.db.ExistDB import describeDocument [as 別名]
def publish(request):
    """
    Admin publication form.  Allows publishing an EAD file by updating or adding
    it to the configured eXist database so it will be immediately visible on
    the public site.  Files can only be published if they pass an EAD sanity check,
    implemented in :meth:`~findingaids.fa_admin.utils.check_ead`.

    On POST, sanity-check the EAD file specified in request from the configured
    and (if it passes all checks), publish it to make it immediately visible on
    the site.  If publish is successful, redirects the user to main admin page
    with a success message that links to the published document on the site.
    If the sanity-check fails, displays a page with any problems found.
    """
    # formerly supported publish from filename, but now only supports
    # publish from preview
    if 'preview_id' not in request.POST:
        messages.error(request, "No preview document specified for publication")
        return HttpResponseSeeOtherRedirect(reverse('fa-admin:index'))

    id = request.POST['preview_id']

    # retrieve info about the document from preview collection
    try:
        # because of the way eulcore.existdb.queryset constructs returns with 'also' fields,
        # it is simpler and better to retrieve document name separately
        ead = get_findingaid(id, preview=True)
        ead_docname = get_findingaid(id, preview=True, only=['document_name'])
        filename = ead_docname.document_name
    except Http404:     # not found in exist
        messages.error(request,
            '''Publish failed. Could not retrieve <b>%s</b> from preview collection.
            Please reload and try again.''' % id)

        # if ead could not be retrieved from preview mode, skip processing
        return HttpResponseSeeOtherRedirect(reverse('fa-admin:index'))

    # determine archive this ead is associated with

    xml = ead.serialize()
    archive = None
    if not ead.repository:
        messages.error(request,
            '''Publish failed. Could not determine which archive <b>%s</b> belongs to.
            Please update subarea, reload, and try again.''' % id)
    else:
        archive_name = ead.repository[0]
        # NOTE: EAD supports multiple subarea tags, but in practice we only
        # use one, so it should be safe to assume the first should be used for permissions
        try:
            archive = Archive.objects.get(name=archive_name)
        except ObjectDoesNotExist:
            messages.error(request,
            '''Publish failed. Could not find archive <b>%s</b>.''' % archive_name)

    # bail out if archive could not be identified
    if archive is None:
        return HttpResponseSeeOtherRedirect(reverse('fa-admin:index'))

    # check that user is allowed to publish this document
    if not archive_access(request.user, archive.slug):
        messages.error(request,
            '''You do not have permission to publish <b>%s</b> materials.''' \
            % archive.label)
        return HttpResponseSeeOtherRedirect(reverse('fa-admin:index'))


    errors = []
    try:
        ok, response, dbpath, fullpath = _prepublication_check(request, filename, archive, xml=xml)
        if ok is not True:
            # publication check failed - do not publish
            return response

        # only load to exist if there are no errors found
        db = ExistDB()
        # get information to determine if an existing file is being replaced
        replaced = db.describeDocument(dbpath)

        try:
            # move the document from preview collection to configured public collection
            success = db.moveDocument(settings.EXISTDB_PREVIEW_COLLECTION,
                    settings.EXISTDB_ROOT_COLLECTION, filename)
            # FindingAid instance ead already set above
        except ExistDBException, e:
            # special-case error message
            errors.append("Failed to move document %s from preview collection to main collection." \
                            % filename)
            # re-raise and let outer exception handling take care of it
            raise e

    except ExistDBException, e:
        errors.append(e.message())
        success = False
開發者ID:mprefer,項目名稱:findingaids,代碼行數:95,代碼來源:views.py


注:本文中的eulexistdb.db.ExistDB.describeDocument方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。