예제 #1
0
 def get(self):
     SETTING_NAMES = ('recaptcha_public',
                     'recaptcha_private',
                     'disabled_contributions'
                     )
     data = {
         "SERVER_NAME" : self.request.environ["SERVER_NAME"]
     }
     
     if self.request.get('save'):
         for name in SETTING_NAMES:
             Setting.save(name, self.request.get(name) or '')
     
     for name in SETTING_NAMES:
         data[name] = Setting.get(name, '')
         
     # We are using the template module to output the page.
 
     path = os.path.join(os.path.dirname(__file__), '../views' ,'admin/settings.html')
     self.response.out.write(
     
         # The render method takes the path to a html template,
         # and a dictionary of key/value pairs that will be
         # embedded in the page.
         
         template.render( path, data))
예제 #2
0
 def get(self):
     
     result = dict()
     
     disabled_contributions = Setting.get("disabled_contributions", False)
     
     if disabled_contributions:
         result["error"] = disabled_contributions
     
     else:
             
         name = uuid.uuid4().hex
         title = self.request.get('title')
         link = self.request.get('link')
         have = self.request.get('have')
         dont = self.request.get('dont')
         missing = self.request.get('missing')
         match_isbn = self.request.get('match_isbn')
         
         logging.debug("LibraryTestContributionHandler: %s" % (title,))
 
         existingLib = Library.find(title)
         
         if existingLib:
             result["existing"] = existingLib.toDict()
             logging.debug("Found Existing")
         else:
             logging.debug("Does not exist")
         
         try:
             lib = Library(name = name,
                     title = title,
                     link = link,
                     have = have,
                     dont = dont)
                     
             if match_isbn != '':
                 lib.match_isbn = True
             else:
                 lib.missing = missing
                 
             result["haveUrl"] = lib.siteUrl(have)
             result["dontUrl"] = lib.siteUrl(dont)
             result["library"] = lib.toDict()
             if not isbn.isValid(have):
                 raise Exception("Existing Book ISBN '%s' is not a valid!" % (have,))
             if not isbn.isValid(dont):
                 raise Exception("Missing Book ISBN '%s' is not a valid!" % (dont,))
             lib.validateLink()
             result["have"] = lib.process(have)
             result["dont"] = lib.process(dont)
             
         except Exception, ex:
             result["error"] = "%s" % (ex,)
예제 #3
0
    def get(self):
    
        # We are using the template module to output the page.
        disabled_contributions = Setting.get("disabled_contributions", False)
        data = {
            "admin_user": users.is_current_user_admin(),
            "disabled_contributions" : disabled_contributions,
            }
        debug = ''
        error = None
        preview = False

        if not disabled_contributions:

            try:
            
                for field in ["title", "link", "have", "dont"]:
                    data[field] = self.request.get(field)
                
                if not data["title"] and not data["link"]:
                    data["title"] = "DC - Library of Congress"
                    data["link"] = "http://www.loc.gov/search/?q=#{ISBN}&fa=digitized:false"
                    data["missing"] = "We did not find any matches for this search."
                    data["have"] = "0321337220"
                    data["dont"] = "0373691122"
                
                else:
                
                    if self.request.get("missing"):
                        data["missing"] = self.request.get("missing")
                    else:
                        data["match_isbn"] = True
                
                data["name"] = uuid.uuid4().hex
                data["is_community"] = True

                preview = self.request.get('preview')
                save = self.request.get('save')
            
                if save:
        
                    preview = True
        
                    challenge = self.request.get('recaptcha_challenge_field')
                    response  = self.request.get('recaptcha_response_field')
                    remoteip  = self.request.environ['REMOTE_ADDR']
                    
                    cResponse = captcha.submit(
                                 challenge,
                                 response,
                                 Setting.get("recaptcha_private", ''),
                                 remoteip)
                    if not cResponse.is_valid:
                        raise Exception("reCaptcha verification failed (" + cResponse.error_code + ")")
        
                    existingLib = Library.find(data["title"])
                                    
                    if existingLib:
                        raise Exception("Another library with this title already exists!")
                        
                    if not isbn.isValid(data["have"]):
                        raise Exception("Existing Book: '%s' is not a valid ISBN!" % (data["have"]))
                    if not isbn.isValid(data["dont"]):
                        raise Exception("Missing Book: '%s' is not a valid ISBN!" % (data["dont"]))
        
                    lib = Library.create(data)
                        
                    problems = lib.validate()
                    if problems:
                        raise Exception("Library didn't validate: " + problems)
                        
                    lib.remote_ip = remoteip
                    
                    lib.put()
                    
                    data["success"] = "Library '%s' was successfuly saved.\nThank you for your contribution." % (data["title"])
                
                if preview:
                    lib = Library.create(data)
                    data["haveUrl"] = lib.siteUrl(data["have"])
                    data["dontUrl"] = lib.siteUrl(data["dont"])
                else:
                    data["library_count"] = Library.count_all()
        
            except Exception, ex:
                error = "%s" % (ex,)