Changeset 2114 for WAeUP_SRP/trunk
- Timestamp:
- 18 Aug 2007, 07:36:29 (17 years ago)
- Location:
- WAeUP_SRP/trunk
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/trunk/WAeUPTool.py
r2094 r2114 684 684 ###) 685 685 686 security.declarePublic('showFsPicture') ###( 687 def showFsPicture(self,path): 688 """return a picture from the filesystem""" 689 picture_path = "%s/var/%s" % (i_home,path) 690 if os.path.exists(picture_path): 691 return open(picture_path).read() 692 693 ###) 694 686 695 security.declareProtected(ModifyPortalContent,'deleteAllCourses') ###( 687 696 def deleteAllCourses(self,department="All"): -
WAeUP_SRP/trunk/Widgets.py
r2110 r2114 1496 1496 def getImageInfo(self, datastructure): ###( 1497 1497 """Get the file info from the datastructure.""" 1498 import pdb; pdb.set_trace()1498 #import pdb; pdb.set_trace() 1499 1499 widget_id = self.getWidgetId() 1500 1500 fileupload = datastructure[widget_id] 1501 1501 dm = datastructure.getDataModel() 1502 1502 field_id = self.fields[0] 1503 if fileupload: 1504 empty_file = False 1505 session_file = isinstance(fileupload, PersistableFileUpload) 1506 current_filename = generateFileName(fileupload.filename) 1507 fileupload.seek(0, 2) # end of file 1508 size = fileupload.tell() 1509 fileupload.seek(0) 1510 file = dm[field_id] # last stored file 1511 if file is not None: 1512 last_modified = str(file._p_mtime or '') 1513 else: 1514 last_modified = '' 1515 else: 1503 # if isinstance(fileupload, PersistableFileUpload): 1504 # empty_file = False 1505 # session_file = isinstance(fileupload, PersistableFileUpload) 1506 # current_filename = generateFileName(fileupload.filename) 1507 # fileupload.seek(0, 2) # end of file 1508 # size = fileupload.tell() 1509 # fileupload.seek(0) 1510 # last_modified = '' 1511 # else: 1512 # empty_file = True 1513 # session_file = False 1514 # current_filename = '' 1515 # size = 0 1516 # last_modified = '' 1517 # get the adapter 1518 # for adapter in dm._adapters: 1519 # if adapter.getSchema().has_key(field_id): 1520 # break # Note: 'adapter' is still the right one 1521 # else: 1522 # raise ValueError('No schema for field %r' % field_id) 1523 1524 content_url = "/uniben/viewimage?path=%s/%s_%s.jpg" %\ 1525 (self.path, 1526 datastructure[self.id_field], 1527 self.getWidgetId(), 1528 ) 1529 # registry = getToolByName(self, 'mimetypes_registry') 1530 # mimetype = (registry.lookupExtension(current_filename.lower()) or 1531 # registry.lookupExtension('file.bin')) 1532 1533 # image_info = { 1534 # 'empty_file': empty_file, 1535 # 'session_file': session_file, 1536 # 'current_filename': current_filename, 1537 # 'size': size, 1538 # 'last_modified': last_modified, 1539 # 'content_url': content_url, 1540 # 'mimetype': mimetype, 1541 # } 1542 # if image_info['empty_file']: 1543 # tag = '' 1544 # height = 0 1545 # width = 0 1546 # else: 1547 current_filename = "%s_%s.jpg" % (datastructure[self.id_field], 1548 field_id,) 1549 file_path = "/%s/%s" % (self.storage_path, 1550 current_filename) 1551 1552 # read the file from the filesystem 1553 if not os.path.exists(file_path): 1516 1554 empty_file = True 1517 1555 session_file = False … … 1519 1557 size = 0 1520 1558 last_modified = '' 1521 1522 # get the adapter 1523 for adapter in dm._adapters: 1524 if adapter.getSchema().has_key(field_id): 1525 break # Note: 'adapter' is still the right one 1526 else: 1527 raise ValueError('No schema for field %r' % field_id) 1528 1529 content_url = None 1530 registry = getToolByName(self, 'mimetypes_registry') 1531 mimetype = (registry.lookupExtension(current_filename.lower()) or 1532 registry.lookupExtension('file.bin')) 1533 1534 image_info = { 1535 'empty_file': empty_file, 1536 'session_file': session_file, 1537 'current_filename': current_filename, 1538 'size': size, 1539 'last_modified': last_modified, 1540 'content_url': content_url, 1541 'mimetype': mimetype, 1542 } 1543 if image_info['empty_file']: 1544 tag = '' 1545 height = 0 1546 width = 0 1547 else: 1548 file_path = "/%s/%s_%s.jpg" % (self.storage_path, 1549 datamodel[self.id_field], 1550 self.field_id,) 1551 # read the file from the filesystem 1552 if not os.path.exists(file_path): 1553 image = None 1554 else: 1555 image = open(file_path).read() 1559 else: 1560 image = open(file_path) 1556 1561 from OFS.Image import getImageInfo 1557 1562 image.seek(0) 1558 1563 data = image.read(24) 1559 ct, width, height = getImageInfo(data) 1564 size = len(data) 1565 empty_file = size == 0 1566 session_file = False 1567 last_modified = '' 1568 image.close() 1569 mimetype, width, height = getImageInfo(data) 1560 1570 if width < 0: 1561 1571 width = None 1562 1572 if height < 0: 1563 1573 height = None 1564 1574 1565 1575 if (self.allow_resize 1566 1576 and height is not None … … 1577 1587 width = int(zoom * width) 1578 1588 height = int(zoom * height) 1579 1580 title = image_info['current_filename'] 1581 alt = title or '' 1582 if height is None or width is None: 1583 tag = renderHtmlTag('img', src=image_info['content_url'], 1584 alt=alt, title=title) 1585 else: 1586 tag = renderHtmlTag('img', src=image_info['content_url'], 1587 width=str(width), height=str(height), 1588 alt=alt, title=title) 1589 image_info = { 1590 'empty_file': empty_file, 1591 'session_file': session_file, 1592 'current_filename': current_filename, 1593 'size': size, 1594 'last_modified': last_modified, 1595 'content_url': content_url, 1596 'mimetype': mimetype, 1597 } 1598 title = image_info['current_filename'] 1599 alt = title or '' 1600 height = int(self.display_height) 1601 width = int(self.display_width) 1602 if height is None or width is None: 1603 tag = renderHtmlTag('img', src=image_info['content_url'], 1604 alt=alt, title=title) 1605 else: 1606 tag = renderHtmlTag('img', src=image_info['content_url'], 1607 width=str(width), height=str(height), 1608 alt=alt, title=title) 1589 1609 1590 1610 image_info['height'] = height … … 1594 1614 ###) 1595 1615 1616 # def getFileName(self, fileupload, datastructure, choice, old_filename=''): 1617 # #filename = datastructure[self.getWidgetId()+'_filename'].strip() 1618 # ext ='jpg' 1619 # filename = "%s_%s.%s" % (datastructure[self.id_field], 1620 # self.getWidgetId(), 1621 # ext) 1622 # if choice == 'change' and filename == old_filename: 1623 # # if upload with input field unchanged, use fileupload filename 1624 # filename = cookId('', '', fileupload)[0].strip() 1625 # #filename = cleanFileName(filename or 'file.bin') 1626 # return filename 1627 1628 def checkFileName(self, filename, mimetype): 1629 return '', {} 1630 if mimetype and mimetype.startswith('image'): 1631 return '', {} 1632 return 'cpsschemas_err_image', {} 1633 1596 1634 def prepare(self, datastructure, **kw): ###( 1597 1635 """Prepare datastructure from datamodel.""" … … 1599 1637 widget_id = self.getWidgetId() 1600 1638 file_name = datamodel[self.fields[0]] 1601 if not file_name:1602 file = None1603 else:1604 import pdb; pdb.set_trace()1605 1639 datastructure[widget_id] = file_name 1606 datastructure[widget_id + '_choice'] = '' 1607 if file is not None: 1608 title = file.title 1609 else: 1610 title = '' 1640 datastructure[widget_id + '_choice'] = 'change' 1641 title = 'Passport Foto' 1611 1642 datastructure[widget_id + '_filename'] = title 1612 1643 ###) 1613 1644 1614 def validate(self, datastructure, **kw): 1645 def validate(self, datastructure, **kw): ###( 1615 1646 """Update datamodel from user data in datastructure. 1616 1647 """ 1648 #import pdb; pdb.set_trace() 1617 1649 datamodel = datastructure.getDataModel() 1618 1650 field_id = self.fields[0] 1619 1651 widget_id = self.getWidgetId() 1620 choice = datastructure[widget_id+'_choice']1621 1652 store = False 1622 1653 fileupload = None 1623 1654 mimetype = None 1624 1655 old_file = datamodel[field_id] 1625 if old_file is not None: 1626 old_filename = old_file.title 1627 else: 1628 old_filename = '' 1629 1656 # if old_file is not None: 1657 # old_filename = old_file.title 1658 # else: 1659 # old_filename = '' 1660 choice = datastructure[widget_id+'_choice'] 1661 fileupload = datastructure[widget_id] 1662 is_upload = isinstance(fileupload, FileUpload) 1663 if not is_upload: 1664 return True 1630 1665 if choice == 'delete': 1631 1666 if self.is_required: … … 1639 1674 # actually want to store it. 1640 1675 store = True 1641 else: 1642 # Nothing to change, don't pollute datastructure 1643 # with something costly already stored, which therefore 1644 # doesn't need to be kept in the session. 1645 self.unprepare(datastructure) 1646 elif choice == 'change': 1647 fileupload = datastructure[widget_id] 1676 # else: 1677 # # Nothing to change, don't pollute datastructure 1678 # # with something costly already stored, which therefore 1679 # # doesn't need to be kept in the session. 1680 # self.unprepare(datastructure) 1681 elif choice == 'change' and is_upload: 1648 1682 if not fileupload: 1649 1683 return self.validateError('cpsschemas_err_file_empty', {}, … … 1667 1701 1668 1702 # Find filename 1669 if fileupload is not None: 1670 filename = self.getFileName(fileupload, datastructure, choice, 1671 old_filename) 1672 if filename != old_filename: 1673 registry = getToolByName(self, 'mimetypes_registry') 1674 mimetype = registry.lookupExtension(filename.lower()) 1675 if mimetype is not None: 1676 mimetype = str(mimetype) # normalize 1677 err, err_mapping = self.checkFileName(filename, mimetype) 1678 if err: 1679 return self.validateError(err, err_mapping, datastructure) 1680 elif datamodel[field_id] is not None: 1681 # FIXME: not correct in the case of change=='resize' (CPSPhotoWidget) 1682 filename = datamodel[field_id].title 1683 1684 import pdb;pdb.set_trace() 1685 # Set/update data 1686 file_path = "/%s/%s_%s.jpg" % (storage_path, 1687 datamodel[self.id_field], 1688 self.field_id,) 1703 if is_upload: 1704 ext ='jpg' 1705 filename = "%s_%s.%s" % (datastructure[self.id_field], 1706 self.getWidgetId(), 1707 ext) 1708 registry = getToolByName(self, 'mimetypes_registry') 1709 mimetype = registry.lookupExtension(filename.lower()) 1710 if mimetype is not None: 1711 mimetype = str(mimetype) # normalize 1712 1689 1713 if store: 1714 # Set/update data 1715 file_path = "%s_%s.jpg" % (datamodel[self.id_field], 1716 field_id,) 1717 full_path = "%s/%s" % (self.storage_path, file_path) 1690 1718 file = self.makeFile(filename, fileupload, datastructure) 1691 1719 # Fixup mimetype … … 1693 1721 file.content_type = mimetype 1694 1722 # Store the file in the filesystem 1695 if not os.path.exists(storage_path): 1696 os.mkdir(storage_path) 1697 open(file_path,"w").write(file) 1698 datamodel[field_id] = file_path 1699 # elif datamodel[field_id] is not None: 1700 # # Change filename 1701 # if datamodel[field_id].title != filename: 1702 # datamodel[field_id].title = filename 1723 if not os.path.exists(self.storage_path): 1724 os.mkdir(self.storage_path) 1725 #import pdb;pdb.set_trace() 1726 pict = open(full_path,"w") 1727 fileupload.seek(0) 1728 pict.write(fileupload.read()) 1729 pict.close() 1703 1730 1704 1731 1705 1732 return True 1706 1733 1734 ###) 1735 1736 def render(self, mode, datastructure, **kw): ###( 1737 render_method = 'widget_passport_render' 1738 meth = getattr(self, render_method, None) 1739 if meth is None: 1740 raise RuntimeError("Unknown Render Method %s for widget type %s" 1741 % (render_method, self.getId())) 1742 img_info = self.getImageInfo(datastructure) 1743 return meth(mode=mode, datastructure=datastructure, **img_info) 1744 ###) 1707 1745 1708 1746 InitializeClass(NoZodbImageWidget) -
WAeUP_SRP/trunk/skins/waeup_student/apply_pume.py
r2111 r2114 50 50 for field in context.applicants_catalog.schema(): 51 51 object[field] = getattr(brains[0],field,None) 52 if not object['passport']: 53 object['passport'] = '' 52 54 if object['status'] == "submitted": 53 55 submitted = True 54 #set_trace()55 56 if not create and pin != object['pin']: 56 57 return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) 57 58 if slip: 58 59 mode = "view_slip" 59 60 60 res,psm,ds = lt.renderLayout(layout_id= 'application', 61 61 schema_id= 'application', … … 91 91 pass 92 92 data = {} 93 dm = ds.getDataModel() 94 #set_trace() 93 95 for field in context.applicants_catalog.schema(): 94 if d s.has_key(field) and request.has_key("widget__%s" % field):95 data[field] = d s.get(field)96 if dm.has_key("%s" % field): 97 data[field] = dm.get(field) 96 98 data['reg_no'] = reg_no 97 98 99 if apply_pume: 99 100 100 if submitted: 101 101 mode = "view" … … 143 143 ) 144 144 elif edit: 145 #set_trace() 145 146 if submitted: 146 147 mode = "view" -
WAeUP_SRP/trunk/skins/waeup_student/apply_pume_form.pt
r2109 r2114 12 12 <h3 tal:condition="python:mode=='view'">Your PUME Application Record</h3> 13 13 <br /> 14 <img tal:condition="python:0" src="/uniben/viewimage?path=images/72921580DJ_passport.jpg" alt="" title="image/jpeg" /> 14 15 <form action="" id="editForm" method="post" 15 16 enctype="multipart/form-data" class="workflow"
Note: See TracChangeset for help on using the changeset viewer.