Changeset 2354 for WAeUP_SRP/base
- Timestamp:
- 12 Oct 2007, 11:21:52 (17 years ago)
- Location:
- WAeUP_SRP/base
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/base/WAeUPTool.py
r2351 r2354 696 696 response = self.REQUEST.RESPONSE 697 697 #import pdb;pdb.set_trace() 698 registry = getToolByName(self, 'mimetypes_registry') 699 mimetype = str(registry.lookupExtension(path.lower()) or 700 registry.lookupExtension('file.bin')) 698 701 if os.path.exists(picture_path): 699 response.setHeader('Content-type', 'image/jpeg')702 response.setHeader('Content-type',mimetype) 700 703 return open(picture_path).read() 701 704 picture_path = os.path.join(i_home,'import',path) -
WAeUP_SRP/base/Widgets.py
r2353 r2354 6 6 from Globals import InitializeClass 7 7 from ZPublisher.HTTPRequest import FileUpload 8 from OFS.Image import cookId, File, Image 8 9 ##from Products.CPSSchemas.Widget import CPSWidgetType 9 10 from Products.CMFCore.utils import getToolByName … … 1796 1797 show_image = False 1797 1798 1799 def getStorageImageInfo(self,field_id): 1800 info = {} 1801 if self.id_field == "": 1802 student_id = self.getStudentId() 1803 else: 1804 student_id = datastructure[self.id_field] 1805 student_path = os.path.join(self.storage_path, 1806 student_id) 1807 image_name = '' 1808 content_url = '' 1809 current_filename = '' 1810 for name in os.listdir(student_path): 1811 if name.startswith(field_id): 1812 image_name = name 1813 break 1814 if image_name: 1815 info['image_name'] = image_name 1816 info['content_url'] = os.path.join(self.portal_url(), 1817 "viewimage", 1818 self.path, 1819 student_id, 1820 image_name, 1821 ) 1822 info['current_filename'] = os.path.join(student_id, 1823 image_name) 1824 info['file_path'] = os.path.join(self.storage_path, 1825 info['current_filename']) 1826 return info 1827 1798 1828 def getImageInfo(self, datastructure): ###( 1799 1829 """Get the file info from the datastructure.""" 1800 #import pdb; pdb.set_trace()1801 1830 widget_id = self.getWidgetId() 1802 1831 if datastructure.has_key(widget_id): … … 1804 1833 dm = datastructure.getDataModel() 1805 1834 field_id = self.fields[0] 1806 if self.id_field == "": 1807 student_id = self.getStudentId() 1808 else: 1809 student_id = datastructure[self.id_field] 1810 content_url = os.path.join(self.portal_url(), 1811 "viewimage", 1812 self.path, 1813 student_id, 1814 "%s_%s.jpg" % (self.getWidgetId(),student_id), 1815 ) 1816 image_title = "%s_%s.jpg" % (widget_id,student_id) 1817 current_filename = os.path.join(student_id, 1818 image_title) 1819 file_path = os.path.join(self.storage_path, 1820 current_filename) 1835 info = self.getStorageImageInfo(field_id) 1821 1836 else: 1822 1837 file_path = "XXX" 1823 image_title = ""1838 title = "" 1824 1839 # read the file from the filesystem 1825 if not os.path.exists(file_path): 1840 #import pdb; pdb.set_trace() 1841 #if not os.path.exists(file_path): 1842 if not info: 1843 title = "" 1826 1844 height = -1 1827 1845 width = -1 … … 1836 1854 width = '' 1837 1855 else: 1838 image = open(file_path) 1856 title = info['image_name'] 1857 current_filename = info['current_filename'] 1858 content_url = info['content_url'] 1859 image = open(info['file_path']) 1839 1860 from OFS.Image import getImageInfo as getImageInfoOFS 1840 1861 image.seek(0) … … 1869 1890 height = int(zoom * height) 1870 1891 #import pdb;pdb.set_trace() 1871 title = image_title1872 1892 image_info = { 1873 1893 'empty_file': empty_file, … … 1897 1917 ###) 1898 1918 1899 def checkFileName(self, filename, mimetype):1900 return '', {}1901 if mimetype and mimetype.startswith('image'):1902 return '', {}1903 return 'cpsschemas_err_image', {}1919 # def checkFileName(self, filename, mimetype): 1920 # return '', {} 1921 # if mimetype and mimetype.startswith('image'): 1922 # return '', {} 1923 # return 'cpsschemas_err_image', {} 1904 1924 1905 1925 def prepare(self, datastructure, **kw): ###( … … 1935 1955 mimetype = None 1936 1956 old_file = datamodel[field_id] 1937 # if old_file is not None:1938 # old_filename = old_file.title1939 # else:1940 # old_filename = ''1941 1957 choice = datastructure[widget_id+'_choice'] 1942 1958 fileupload = datastructure[widget_id] … … 1955 1971 return self.validateError('cpsschemas_err_required', {}, 1956 1972 datastructure) 1957 ext ='jpg' 1958 filename = "%s_%s.%s" % (self.getWidgetId(), 1959 student_id, 1960 ext) 1973 info= self.getStorageImageInfo(field_id) 1961 1974 # Remove the file in the filesystem 1962 student_path = os.path.join(self.storage_path,student_id) 1963 full_path = os.path.join(student_path, filename) 1964 if os.path.exists(full_path): 1965 os.remove(full_path) 1975 if info: 1976 os.remove(info['file_path']) 1966 1977 datamodel[field_id] = None 1967 1978 elif choice == 'keep': … … 1999 2010 # Find filename 2000 2011 if is_upload and store: 2001 ext ='jpg' 2002 filename = "%s_%s.%s" % (self.getWidgetId(), 2003 student_id, 2004 ext) 2012 filename = cookId('', '', fileupload)[0].strip() 2013 base,ext = os.path.splitext(filename) 2014 filename = "%s_%s%s" % (field_id, 2015 student_id, 2016 ext) 2005 2017 datamodel[field_id] = filename 2006 2018 registry = getToolByName(self, 'mimetypes_registry') … … 2017 2029 os.mkdir(student_path) 2018 2030 full_path = os.path.join(student_path, filename) 2019 #import pdb;pdb.set_trace()2020 2031 pict = open(full_path,"w") 2021 2032 fileupload.seek(0) … … 2023 2034 pict.close() 2024 2035 return True 2025 2026 ###) 2036 ###) 2027 2037 2028 2038 def render(self, mode, datastructure, **kw): ###(
Note: See TracChangeset for help on using the changeset viewer.