Ignore:
Timestamp:
10 Oct 2007, 15:43:43 (17 years ago)
Author:
joachim
Message:

rename No Zodb Image Widget to Application Image Widget

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/base/Widgets.py

    r2336 r2342  
    13351335    reference = ''
    13361336
     1337    def prepare(self, datastructure, **kw): ###(
     1338        """Prepare datastructure from datamodel."""
     1339        datamodel = datastructure.getDataModel()
     1340        v = datamodel[self.fields[0]]
     1341        widget_id = self.getWidgetId()
     1342        if v and type(v) is StringType:
     1343            try:
     1344                p,b,n = v.split('-')
     1345                v = ScratchCardPin(p,b,n)
     1346            except ValueError:
     1347                v = ScratchCardPin(v,'','')
     1348        if v:
     1349            p = '%s' % v.p
     1350            b = '%s' % v.b
     1351            n = '%s' % v.n
     1352        else:
     1353            p = self.prefix
     1354            if p.startswith('@'):
     1355                p = getattr(self,self.prefix[1:])()
     1356            b = n = ''
     1357            v = ScratchCardPin(p,b,n)
     1358        datastructure[widget_id] = v
     1359        datastructure[widget_id+'_p'] = p
     1360        datastructure[widget_id+'_b'] = b
     1361        datastructure[widget_id+'_n'] = n
     1362        screening_type = datamodel.get('screening_type',None)
     1363        if screening_type is None:
     1364            screening_type = self.REQUEST.form.get('screening_type','unknown')
     1365        datastructure["screening_type"] = screening_type
     1366    ###)
     1367
    13371368    def validate(self, datastructure, **kw): ###(
    13381369        """Validate datastructure and update datamodel."""
     
    13961427                break
    13971428            if ok >= 1:
    1398                 screening_type = self.REQUEST.form.get('screening_type','unknown')
     1429                #screening_type = self.REQUEST.form.get('screening_type','unknown')
     1430                screening_type = datastructure['screening_type']
    13991431                if self.isStudent():
    14001432                    err = "This is only for Pume application."
     
    15041536###)
    15051537
    1506 class NoZodbImageWidget(CPSImageWidget): ###(
     1538class ApplicationImageWidget(CPSImageWidget): ###(
    15071539    """Image widget with filesystem storage."""
    1508     meta_type = 'No Zodb Image Widget'
     1540    meta_type = 'Application Image Widget'
    15091541    _properties = CPSImageWidget._properties +\
    15101542    (
     
    15201552    def getImageInfo(self, datastructure): ###(
    15211553        """Get the file info from the datastructure."""
    1522         #import pdb; pdb.set_trace()
    15231554        widget_id = self.getWidgetId()
    15241555        if  datastructure.has_key(widget_id):
     
    15261557            dm = datastructure.getDataModel()
    15271558            field_id = self.fields[0]
    1528             content_url = "/viewimage?path=%s/%s_%s.jpg" %\
    1529                                     (self.path,
    1530                                     datastructure[self.id_field],
    1531                                     self.getWidgetId(),
    1532                                     )
     1559            screening_type = datastructure.get('screening_type')
    15331560            current_filename = "%s_%s.jpg" % (datastructure[self.id_field],
    15341561                                            field_id,)
    1535             file_path = "/%s/%s" % (self.storage_path,
    1536                                         current_filename)
     1562            base_path = os.path.join(screening_type,current_filename)
     1563            content_url = os.path.join('viewimage',self.path,base_path)
     1564            file_path = os.path.join(self.storage_path,base_path)
     1565            #import pdb; pdb.set_trace()
    15371566        else:
    15381567            file_path = "XXX"
     
    16101639    ###)
    16111640
    1612 
    16131641    def checkFileName(self, filename, mimetype):
    16141642        return '', {}
     
    16251653        if self.allow_resize:
    16261654            datastructure[self.getWidgetId() + '_resize'] = ''
     1655        screening_type = datamodel.get('screening_type',None)
     1656        if not screening_type:
     1657            screening_type = self.REQUEST.form.get('screening_type','pume')
     1658        datastructure["screening_type"] = screening_type
    16271659        datastructure[widget_id] = file_name
    16281660        datastructure[widget_id + '_choice'] = 'change'
     
    16341666        """Update datamodel from user data in datastructure.
    16351667        """
    1636         logger = logging.getLogger('Widgets.NoZodbImageWidget.validate')
     1668        logger = logging.getLogger('Widgets.ApplicationImageWidget.validate')
    16371669        datamodel = datastructure.getDataModel()
    16381670        field_id = self.fields[0]
     
    16941726        if is_upload and store:
    16951727            ext ='jpg'
     1728            screening_type = datastructure.get('screening_type')
    16961729            filename = "%s_%s.%s" % (datastructure[self.id_field],
    1697                                  self.getWidgetId(),
    1698                                  ext)
     1730                                     self.getWidgetId(),
     1731                                     ext)
    16991732            datamodel[field_id] = filename
    17001733            registry = getToolByName(self, 'mimetypes_registry')
     
    17021735            if mimetype is not None:
    17031736                mimetype = str(mimetype) # normalize
    1704             # Set/update data
    1705             # file_path = "%s_%s.jpg" % (datamodel[self.id_field],
    1706             #                            field_id,)
    1707             full_path = "%s/%s" % (self.storage_path, filename)
    1708             #import pdb; pdb.set_trace()
    17091737            file = self.makeFile(filename, fileupload, datastructure)
    17101738            # Fixup mimetype
     
    17121740                file.content_type = mimetype
    17131741            # Store the file in the filesystem
    1714             if not os.path.exists(self.storage_path):
    1715                 os.mkdir(self.storage_path)
    17161742            #import pdb;pdb.set_trace()
     1743            base_path = os.path.join(self.storage_path, screening_type)
     1744            if not os.path.exists(base_path):
     1745                os.mkdir(base_path)
     1746            full_path = os.path.join(base_path, file_name)
    17171747            pict = open(full_path,"w")
    17181748            fileupload.seek(0)
     
    17351765    ###)
    17361766
    1737 InitializeClass(NoZodbImageWidget)
    1738 
    1739 widgetRegistry.register(NoZodbImageWidget)
     1767InitializeClass(ApplicationImageWidget)
     1768
     1769widgetRegistry.register(ApplicationImageWidget)
    17401770###)
    17411771
     
    17491779     {'id': 'id_field', 'type': 'string', 'mode': 'w',
    17501780      'label': 'Field to build the id'},
     1781     {'id': 'show_image', 'type': 'boolean', 'mode': 'w',
     1782      'label': 'Show Image'},
    17511783    )
    17521784    path = "images"
    17531785    storage_path = "%s/%s" % (i_home,path)
    17541786    id_field = ""
    1755 
     1787    show_image = False
     1788   
    17561789    def getImageInfo(self, datastructure): ###(
    17571790        """Get the file info from the datastructure."""
     
    18511884        image_info['width'] = width
    18521885        image_info['image_tag'] = tag
     1886        image_info['show_image'] = self.show_image
    18531887        return image_info
    18541888    ###)
     
    19852019        render_method = 'widget_image_render'
    19862020        meth = getattr(self, render_method, None)
     2021        #import pdb;pdb.set_trace()
    19872022        if meth is None:
    19882023            raise RuntimeError("Unknown Render Method %s for widget type %s"
Note: See TracChangeset for help on using the changeset viewer.