def extractData(self):
        def getErrorView(widget,error):
            view = zope.component.getMultiAdapter( (error, 
                                                    self.request, 
                                                    widget, 
                                                    widget.field, 
                                                    widget.form, 
                                                    self.context), 
                                                   IErrorViewSnippet)
            view.update()
            widget.error = view
            return view

        data, errors = super(ContributeForm,self).extractData()
        isbn = data.get('isbn',None)
        print 'isbn: ', isbn
        if isbn:
            print "isbn appeared: ", isbn
            isbnWidget = self.widgets.get('isbn',None)
            valid = is_valid_isbn(isbn)
            if not valid:
                # validity error
                print "isbn is not valid"
                errors += (getErrorView(isbnWidget, zope.interface.Invalid(u'chyba v isbn')),)
                pass
            else:
                try:
                    appearedAtAleph = edeposit.amqp.aleph.aleph.getISBNCount(isbn)
                    if not appearedAtAleph:
                        errors += (getErrorView(isbnWidget, zope.interface.Invalid(u'isbn nemá v Alephu záznam. Použijte jíné.')),)
                except:
                    pass

        return (data,errors)
    def handleOK(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return
        try:
            valid = is_valid_isbn(data['isbn'])
        except:
            print sys.exc_info()
            raise ActionExecutionError(Invalid(u"Objevila se nějaká chyby při volání Aleph služby! (%s)" % (str(sys.exc_info()),)))

        if not valid:
            raise ActionExecutionError(Invalid(u"ISBN není validní!"))

        try:
            appearedAtAleph = getISBNCount(data['isbn'])
        except:
            print sys.exc_info()
            raise ActionExecutionError(Invalid(u"Objevila se nějaká chyby při volání Aleph služby! (%s)" % (str(sys.exc_info()),)))

        if appearedAtAleph:
            raise ActionExecutionError(Invalid(u"ISBN už v Alephu existuje!"))

        wft = api.portal.get_tool('portal_workflow')
        self.context.isbn = data['isbn']
        modified(self.context)
        wft.doActionFor(self.context, 'submitISBNGeneration')
        self.status = u"Hotovo!"
Пример #3
0
    def extractData(self):
        def getErrorView(widget,error):
            view = zope.component.getMultiAdapter( (error, 
                                                    self.request, 
                                                    widget, 
                                                    widget.field, 
                                                    widget.form, 
                                                    self.context), 
                                                   IErrorViewSnippet)
            view.update()
            widget.error = view
            return view

        data, errors = super(EPublicationAddForm,self).extractData()
        isbn = data.get('IOriginalFile.isbn',None)
        if isbn:
            isbnWidget = self.widgets.get('IOriginalFile.isbn',None)
            valid = is_valid_isbn(isbn)
            if not valid:
                # validity error
                print "isbn is not valid"
                errors += (getErrorView(isbnWidget, zope.interface.Invalid(u'Chyba v ISBN')),)
                pass
            else:
                try:
                    appearedAtAleph = getISBNCount(isbn)
                    if appearedAtAleph:
                        print "isbn already appeared in Aleph"
                        # duplicity error
                        errors += (getErrorView(isbnWidget, zope.interface.Invalid(u'ISBN je již použito. Použijte jiné, nebo nahlašte opravu.')),)
                except:
                    print "some exception with edeposit.amqp.aleph.aleph.getISBNCount"
                    pass
            pass
        return (data,errors)
Пример #4
0
    def handleOK(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        if not data["isbn"] and not data["generated_isbn"]:
            raise ActionExecutionError(Invalid(u"Je potřeba vyplnit ISBN, nebo zvolit jeho přiřazení."))

        try:
            valid = is_valid_isbn(data["isbn"] or "")
        except:
            print sys.exc_info()
            raise ActionExecutionError(
                Invalid(u"Objevila se nějaká chyby při volání Aleph služby! (%s)" % (str(sys.exc_info()),))
            )

        if data["isbn"] and not valid:
            raise ActionExecutionError(Invalid(u"ISBN není validní!"))

        try:
            appearedAtAleph = data["isbn"] and getISBNCount(data["isbn"])
        except:
            print sys.exc_info()
            raise ActionExecutionError(
                Invalid(u"Objevila se nějaká chyby při volání Aleph služby! (%s)" % (str(sys.exc_info()),))
            )

        if appearedAtAleph:
            raise ActionExecutionError(Invalid(u"ISBN už v Alephu existuje!"))

        context = (
            self.context.portal_type == "edeposit.content.originalfile"
            and aq_parent(aq_inner(self.context))
            or self.context
        )
        data["title"] = "%s (%s)" % (context.title, data["file"] and data["file"].filename or "")

        member = api.user.get_current()
        data["zpracovatel_zaznamu"] = member.fullname or member.id

        newOriginalFile = createContentInContainer(context, "edeposit.content.originalfile", **data)
        wft = api.portal.get_tool("portal_workflow")
        if newOriginalFile.file:
            wft.doActionFor(
                newOriginalFile,
                ((newOriginalFile.isbn) and "submitDeclarationToISBNValidation") or "submitDeclarationToAntivirus",
                comment="handled automatically",
            )
        modified(context)
        self.status = u"Hotovo!"
        self.request.response.redirect(newOriginalFile.absolute_url())
Пример #5
0
    def extractData(self):
        def getErrorView(widget,error):
            view = zope.component.getMultiAdapter( (error, 
                                                    self.request, 
                                                    widget, 
                                                    widget.field, 
                                                    widget.form, 
                                                    self.context), 
                                                   IErrorViewSnippet)
            view.update()
            widget.error = view
            return view

        data, errors = super(AddAtOnceForm,self).extractData()
        isbn = data.get('isbn',None)
        if isbn:
            isbnWidget = self.widgets.get('isbn',None)
            valid = is_valid_isbn(isbn)
            if not valid:
                # validity error
                errors += (getErrorView(isbnWidget, zope.interface.Invalid(u'Chyba v ISBN')),)
                pass
            else:
                try:
                    appearedAtAleph = getISBNCount(isbn)
                    if appearedAtAleph:
                        # duplicity error
                        errors += (getErrorView(isbnWidget, zope.interface.Invalid(u'ISBN je již použito. Použijte jiné, nebo nahlašte opravu.')),)
                except:
                    print "some exception with edeposit.amqp.aleph.aleph.getISBNCount"
                    pass
            pass

        if 'vsechny knihovny maji pristup' in data.get('libraries_accessing',""):
            librariesIDS = [ii.token for ii in availableLibraries(self.context)]
            data['libraries_that_can_access'] = set(librariesIDS)

        if 'vybrane knihovny maji pristup' in data.get('libraries_accessing',""):
            data['libraries_that_can_access'] = data.get('libraries_that_can_access',set()) \
                | set(['narodni-knihovna-ceske-republiky',])
            
        return (data,errors)
Пример #6
0
    def extractData(self):
        def getErrorView(widget,error):
            view = zope.component.getMultiAdapter( (error, 
                                                    self.request, 
                                                    widget, 
                                                    widget.field, 
                                                    widget.form, 
                                                    self.context), 
                                                   IErrorViewSnippet)
            view.update()
            widget.error = view
            return view

        data, errors = super(AddAtOnceForm,self).extractData()
        isbn = data.get('isbn',None)
        if isbn:
            isbnWidget = self.widgets.get('isbn',None)
            valid = is_valid_isbn(isbn)
            if not valid:
                # validity error
                errors += (getErrorView(isbnWidget, zope.interface.Invalid(u'Chyba v ISBN')),)

        return (data,errors)
Пример #7
0
    def extractData(self):
        print "LoadFromSimilarForm - extractData"
        def getErrorView(widget,error):
            view = zope.component.getMultiAdapter( (error, 
                                                    self.request, 
                                                    widget, 
                                                    widget.field, 
                                                    widget.form, 
                                                    self.context), 
                                                   IErrorViewSnippet)
            view.update()
            widget.error = view
            return view

        data, errors = super(LoadFromSimilarForm,self).extractData()
        isbn = self.getISBN(data)
        isbnWidget = self.widgets.get('load_isbn',None)
        if not isbn:
            errors += (getErrorView(isbnWidget, Invalid(u'Je potřeba zadat nějaké ISBN')),)

        if isbn:
            valid = is_valid_isbn(isbn)
            if not valid:
                # validity error
                errors += (getErrorView(isbnWidget, Invalid(u'Chyba v ISBN')),)
                pass
            else:
                try:
                    appearedAtAleph = getISBNCount(isbn)
                    if not appearedAtAleph:
                        errors += (getErrorView(isbnWidget, 
                                                Invalid(u'ISBN v Alephu neexistuje. Použijte jiné.')),)
                except:
                    print "some exception with edeposit.amqp.aleph.aleph.getISBNCount"
                    pass
            pass
        return (data,errors)