view MPIWGProjects_removed.py @ 227:a328c112e372

moved obsoleted getAllProjectsAndTagsAsCSV to MPIWGThesaurus.
author casties
date Wed, 30 Oct 2013 17:44:42 +0100
parents 975a8d88e315
children
line wrap: on
line source

#
# removed methods
#


class MPIWGProjects_notused:

    def decode(self, str):
        """return unicode object"""
        return unicodify(str)

    def isCheckField(self, fieldname):
        """return chechfield"""
        return (fieldname in checkFields)
 
    def sortedByPlace(self, metatype):
        """find metatype and sort by place"""
        def sort(x, y):
            return cmp(getattr(x[1], 'place', 0), getattr(y[1], 'place', 0))

        logging.debug("MPIWGProjects begin: sorted by place: " + metatype)
        founds = self.ZopeFind(self, obj_metatypes=[metatype]);
        
        founds.sort(sort)
        logging.debug("MPIWGProjects end: sorted by place: " + metatype)
        return founds
    

    def harvest_page(self, context=None, mode="normal"):
        """seite fuer harvesting fuer die Projektsuche"""
       
        if not context:
            context = self
            
        if self.isActiveProject() and self.isCurrentVersion():
             templates = self.en.getHarvestCache()
            
             ext = getattr(self, "harvest_main", None)
             if ext:
                 rendered = getattr(self, ext.getId())()
                 templates[self.absolute_url()] = rendered
                 transaction.commit()
                 return rendered
                 

             pt = PageTemplateFile(os.path.join(package_home(globals()), 'zpt', 'harvest_main')).__of__(context)    
             
             rendered = pt()
             templates[self.absolute_url()] = rendered
             transaction.commit()
             return rendered
                 
 
      
    def index_html_old(self, request=True, context=None):
        """show homepage"""
    
        bound_names = {}
         
        if not context:
            context = self
        if request:
            if self.REQUEST.has_key('date') and self.REQUEST.SESSION.get('MPI_redirected', None) == None:
                self.REQUEST.SESSION['MPI_redirected'] = 1
                self.REQUEST.RESPONSE.redirect(self.checkDate(self.REQUEST['date']) + "?date=" + self.REQUEST['date'])
            else:
                self.REQUEST.SESSION['MPI_redirected'] = None
        
        # ext=self.ZopeFind(self.aq_parent,obj_ids=["project_main"])
      
   
        request2 = getattr(self, 'REQUEST', None)
        
        if request2 is not None:
            response = request2.response
            if not response.headers.has_key('content-type'):
                response.setHeader('content-type', 'text/html')

        security = getSecurityManager()
        bound_names['user'] = security.getUser()
      
        # Retrieve the value from the cache.
        keyset = None
        if self.ZCacheable_isCachingEnabled():
            
            # Prepare a cache key.
            keyset = {'here': self, 'params':request2['QUERY_STRING']}
                      
            result = self.ZCacheable_get(keywords=keyset)
           
            if result is not None:
                # Got a cached value.
                return result
        
        pt = getTemplate(self, "project_main")
         # Execute the template in a new security context.
        security.addContext(self)

        try:
            # logging.debug("index_html pt=%s"%repr(pt))
            result = pt.pt_render(extra_context=bound_names)
            # logging.debug("index_html result=%s"%repr(result))
            if keyset is not None:
                # Store the result in the cache.
                self.ZCacheable_set(result, keywords=keyset)
               
            return result
        finally:
            security.removeContext(self)
       

      
    def index_html_old2(self, request=True, context=None):
        """show homepage"""
        if not context:
            context = self
        if request:
            if self.REQUEST.has_key('date') and self.REQUEST.SESSION.get('MPI_redirected', None) == None:
                self.REQUEST.SESSION['MPI_redirected'] = 1
                self.REQUEST.RESPONSE.redirect(self.checkDate(self.REQUEST['date']) + "?date=" + self.REQUEST['date'])
            else:
                self.REQUEST.SESSION['MPI_redirected'] = None
        
        # ext=self.ZopeFind(self.aq_parent,obj_ids=["project_main"])
      
        ext = getattr(self, "project_main", None)
        if ext:
            return getattr(self, ext.getId())()
        
        pt = PageTemplateFile(os.path.join(package_home(globals()), 'zpt', 'project_main')).__of__(context)    

        return pt()

    
    def no_project(self):
        """warnung: project noch nicht existent"""
        pt = PageTemplateFile(os.path.join(package_home(globals()), 'zpt', 'no_project')).__of__(self)
        return pt()
    
  
    def showImagesOfPage(self, imageUrl=None):
        """show Images of project"""
        self.getContent('WEB_project_description', filter='yes')  # get the content and store image infos into session
        pt = PageTemplateFile(os.path.join(package_home(globals()), 'zpt', 'projectImageView.zpt')).__of__(self)
        return pt()
        
    
    def show_html(self):
        """simple index"""
        # return "HI"
        pt = PageTemplateFile(os.path.join(package_home(globals()), 'zpt', 'MPIWGProject_index.zpt')).__of__(self)
        return pt()

    def getLabel_old(self):
        """returns label (or title) of this project"""
        l = self.getContent('xdata_07')
        if l:
            return l
        l = self.getContent('WEB_title')
        if l:
            return l
        return self.title

    def getPersonKeyList(self):
        """gibt die key Liste der beteiligten Personen zurueck (utf8 codiert)"""
        # logging.error("getPersonKeyList:%s"%getattr(self,'responsibleScientistsList',[]))
        try:
            return [utf8ify(x[1]) for x in getattr(self, 'responsibleScientistsList', [])]
        except:
            return[]
        
       
    def myCapitalize(self, txt):
        """kapitalisiere auch Namen mit -"""
        splitted = [x.capitalize() for x in txt.split("-")]
        return "-".join(splitted)
    
    def getNamesOrdered(self, list):
        """Sortiert die Liste nach der Reihenfolge in xdata_01"""
        
        nameList = self.getContent('xdata_01')
        if nameList.find(";") > -1:  # rate Trenner ist ;
            names = nameList.split(";")  
        else:
            names = nameList.split(",")
            
        self._v_names = []
        for name in names:
            self._v_names.append(name.rstrip().lstrip())
            
            
        def sort(x, y):
            try:
                return cmp(self._v_names.index(x[0]), self._v_names.index(y[0]))
            except:
                return 0
            
        list.sort(sort)
        
        return list
        
    def getWebProject_description(self):
        """get description"""
        debug = self.REQUEST.cookies.get("MP_debug_code", None)
        
        if debug and debug == "western":
            return """
            <html>
            <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
            </head>
            <body>%s</body>
            </html>
            """ % self.WEB_project_description[0]
        
        return """
            <html>
            <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
            </head>
            <body>%s</body>
            </html>
            """ % self.getContent('WEB_project_description')
        
        
        
    def isChecked(self, wert, list):
        """check if wert is in ; seperated list"""

        # felder sind manchmnal als liste mit einem element definiert
        if type(list) is StringType or UnicodeType: 
            splitted = list.split(";")
        else:
            splitted = list[0].split(";")

        splitted = [y.rstrip().lstrip() for y in splitted]
        
        for x in splitted:
            x = re.sub(r"[^A-z ]", "", x)
            if (not x == u'') and x in wert:
                return 1
        return 0


    def getRootProject(self):
        """returns the root (=top level) project of the current project"""
        ct = self.getContexts(parents=self.getContent('xdata_05'))
        if len(ct) > 0:
            return ct[-1][0]
        else:
            return self        


    def getContent(self, field, filter=None):
        """Inhalt des Feldes"""
        # logging.debug("getContent field=%s filter=%s"%(field,filter))
        
        if field == "short_title":
                text = self.getContent("xdata_07")
                if text == "":
                        text = self.getContent("WEB_title")
                return text

        text = u''

        f = getattr(self, field)
        if isinstance(f, list):
            # compat with old lists
            for x in f:
                try:
                    text += x
                except:
                    text = x
        else:
            text = f

        try:
            if text[len(text) - 1] == ";":
                text = text[0:len(text) - 1]
                
        except:
            pass
        
        if text == '':  # # wozu die folgenden Zeilen??
            text2 = text
        else:
            text2 = re.sub(r';([^\s])', '; \g<1>', text)
       
        if field == "WEB_project_description":  # #Jedenfalls darf letzteres nicht gemacht werden, falls normaler text
            text2 = text
            
        # teste ob ergebnis leer und header dann nehme title
        
        if (text2 == '') and (field == 'WEB_project_header'):
            return self.getContent('WEB_title')

        if filter:
            splitted = text2.split("""<p class="picture">""")
            if len(splitted) > 1:
                tmp = splitted[1].split("</p>")
                # return repr(splitted[1])
                try:
                        self.imageURL = tmp[0].split("\"")[1].encode('utf-8')
                except:
                    try:
                        self.imageURL = tmp[0].split("src=")[1].split(" ")[0].encode('utf-8')
                    except:
                        self.imageURL = ""

                split2 = "</p>".join(tmp[1:])

                text3 = splitted[0] + split2

                splitted = text3.split("""<p class="picturetitle">""")
                if len(splitted) > 1:
                    tmp = splitted[1].split("</p>")
                    self.imagecap = tmp[0].encode('utf-8')
                
                    split4 = "".join(tmp[1:])

                    text5 = splitted[0] + split4
                else:
                    # keine caption
                    text5 = text3
            else:
                # kein bild
                text5 = text2
        else:
            text5 = text2

        # teste ob WEB_project_description und keine fuehrenden p tags
        if (len(text5) > 4) and (not text5[0:3] == '<p>') and (field == 'WEB_project_description'):
            text5 = "<p>" + text5 + "</p>"


        # filter image
        
        text5 = text5.lstrip().rstrip()  # loescher leerzeichen und einzelndes br
        if (text5 == "<br>") or (text5 == "<br/>"):
            text5 = ""

        # logging.debug("getcontent: field=%s filter=%s -> %s"%(field,filter,repr(text5)))
        return unicodify(text5)
        # return utf8ify(text5) # return as utf-8 byte string



    def getImageUrls(self, mode="not_cached"):
        """get the image urls"""
        
        if (getattr(self, 'link', '') == ''):
            return []  # es gibt keinen link
        
        server = xmlrpclib.ServerProxy(self.link)
        
        
        if(mode == "cached"):
            if (hasattr(self, "_v_imageUrls")):
                logging.debug("getImageURL cached")
                return self._v_imageUrls
       
        try:
            urls = server.getImageUrls()
            ret = []
            for url in urls:
                url = os.path.join(self.link, url)
                ret.append(url)
           
        except:
            self._v_imageUrls = []
            return []
        self._v_imageUrls = ret[0:]
        return ret