Changeset 2342


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

rename No Zodb Image Widget to Application Image Widget

Location:
WAeUP_SRP
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/base/WAeUPTool.py

    r2335 r2342  
    695695        picture_path = os.path.join(i_home,path)
    696696        response = self.REQUEST.RESPONSE
     697        #import pdb;pdb.set_trace()
    697698        if os.path.exists(picture_path):
    698699            response.setHeader('Content-type','image/jpeg')
  • 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"
  • WAeUP_SRP/base/skins/cps_custom/widget_image_render.pt

    r2332 r2342  
    11<tal:block define="mode options/mode;
    2   id here/getWidgetId;
    3   fields here/fields;
    4   current_filename options/current_filename;
    5   empty_file options/empty_file;
    6   session_file options/session_file;
    7   mimetype options/mimetype;
    8   size options/size;
    9   content_url options/content_url;
    10   last_modified options/last_modified;
    11   content_url_nocache string:${content_url}?nocache=${last_modified};
    12   image_width options/width;
    13   image_height options/height;
    14   image_tag options/image_tag;
    15   ">
    16 <span tal:condition="python:0">
    17   <img tal:condition="python: mode == 'view' and not empty_file"
    18     tal:replace="structure image_tag" />
    19 </span>
    20 <span tal:condition="python: mode == 'view' and not empty_file">
    21   <a href="" target="_new"
    22      tal:attributes="href content_url"
    23      tal:content="current_filename" >
    24   </a>
    25 </span>
    26 
     2           id here/getWidgetId;
     3           fields here/fields;
     4           current_filename options/current_filename;
     5           empty_file options/empty_file;
     6           session_file options/session_file;
     7           mimetype options/mimetype;
     8           size options/size;
     9           content_url options/content_url;
     10           last_modified options/last_modified;
     11           content_url_nocache string:${content_url}?nocache=${last_modified};
     12           image_width options/width;
     13           image_height options/height;
     14           image_tag options/image_tag;
     15           show_image options/show_image|nothing;"
     16           >
     17  <span tal:condition="python: mode == 'view' and not empty_file" tal:omit-tag="">
     18    <img tal:condition="python: show_image"
     19         tal:replace="structure image_tag" />
     20    <span tal:condition="python: not show_image" tal:omit-tag="">
     21      <a href="" target="_new"
     22         tal:attributes="href content_url"
     23         tal:content="current_filename" >
     24      </a>
     25    </span>
     26  </span>
    2727  <tal:block condition="python: mode == 'edit'">
    2828
  • WAeUP_SRP/uniben/profiles/default/layouts/application_manage.xml

    r2327 r2342  
    324324    <property name="css_class_expr">string:row</property>
    325325  </widget>
    326   <widget name="passport" meta_type="No Zodb Image Widget">
     326  <widget name="passport" meta_type="Application Image Widget">
    327327    <property name="title">Passport Photograph</property>
    328328    <property name="fields">
  • WAeUP_SRP/uniben/profiles/default/layouts/application_pce.xml

    r2321 r2342  
    324324    <property name="css_class_expr">string:row</property>
    325325  </widget>
    326   <widget name="passport" meta_type="No Zodb Image Widget">
     326  <widget name="passport" meta_type="Application Image Widget">
    327327    <property name="title">Passport Photograph</property>
    328328    <property name="fields">
  • WAeUP_SRP/uniben/profiles/default/layouts/application_pde.xml

    r2341 r2342  
    388388    <property name="css_class_expr">string:row</property>
    389389  </widget>
    390   <widget name="passport" meta_type="No Zodb Image Widget">
     390  <widget name="passport" meta_type="Application Image Widget">
    391391    <property name="title">Passport Photograph</property>
    392392    <property name="fields">
  • WAeUP_SRP/uniben/profiles/default/layouts/application_prence.xml

    r2330 r2342  
    360360    <property name="css_class_expr">string:row</property>
    361361  </widget>
    362   <widget name="passport" meta_type="No Zodb Image Widget">
     362  <widget name="passport" meta_type="Application Image Widget">
    363363    <property name="title">Passport Photograph</property>
    364364    <property name="fields">
  • WAeUP_SRP/uniben/profiles/default/layouts/application_pume.xml

    r2321 r2342  
    326326    <property name="css_class_expr">string:row</property>
    327327  </widget>
    328   <widget name="passport" meta_type="No Zodb Image Widget">
     328  <widget name="passport" meta_type="Application Image Widget">
    329329    <property name="title">Passport Photograph</property>
    330330    <property name="fields">
  • WAeUP_SRP/uniben/profiles/default/layouts/student_application.xml

    r2338 r2342  
    274274  <property name="display_width">150</property>
    275275  <property name="display_height">200</property>
    276  </widget>
     276  <property name="show_image">True</property>
     277  </widget>
    277278 <table>
    278279  <row>
  • WAeUP_SRP/uniben/profiles/default/layouts/student_application_fe.xml

    r2338 r2342  
    263263  <property name="display_height">200</property>
    264264  <property name="allow_resize">True</property>
     265  <property name="show_image">True</property>
    265266 </widget>
    266267 <table>
Note: See TracChangeset for help on using the changeset viewer.