Changeset 2335
- Timestamp:
- 9 Oct 2007, 17:34:04 (17 years ago)
- Location:
- WAeUP_SRP
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/base/WAeUPTool.py
r2320 r2335 693 693 def showFsPicture(self,path): 694 694 """return a picture from the filesystem""" 695 picture_path = "%s/import/%s" % (i_home,path) 695 picture_path = os.path.join(i_home,path) 696 response = self.REQUEST.RESPONSE 697 if os.path.exists(picture_path): 698 response.setHeader('Content-type','image/jpeg') 699 return open(picture_path).read() 700 picture_path = os.path.join(i_home,'import',path) 696 701 if os.path.exists(picture_path): 697 702 return open(picture_path).read() 703 698 704 699 705 ###) -
WAeUP_SRP/base/Widgets.py
r2324 r2335 1740 1740 ###) 1741 1741 1742 class FileImageWidget(CPSImageWidget): ###( 1743 """Image widget with filesystem storage.""" 1744 meta_type = 'File Image Widget' 1745 _properties = CPSImageWidget._properties +\ 1746 ( 1747 {'id': 'path', 'type': 'string', 'mode': 'w', 1748 'label': 'Relative Path'}, 1749 {'id': 'id_field', 'type': 'string', 'mode': 'w', 1750 'label': 'Field to build the id'}, 1751 ) 1752 path = "images" 1753 storage_path = "%s/%s" % (i_home,path) 1754 id_field = "" 1755 1756 def getImageInfo(self, datastructure): ###( 1757 """Get the file info from the datastructure.""" 1758 #import pdb; pdb.set_trace() 1759 widget_id = self.getWidgetId() 1760 if datastructure.has_key(widget_id): 1761 fileupload = datastructure[widget_id] 1762 dm = datastructure.getDataModel() 1763 field_id = self.fields[0] 1764 if self.id_field == "": 1765 student_id = self.getStudentId() 1766 else: 1767 student_id = datastructure[self.id_field] 1768 content_url = os.path.join(self.portal_url(), 1769 "viewimage", 1770 self.path, 1771 student_id, 1772 "%s_%s.jpg" % (self.getWidgetId(),student_id), 1773 ) 1774 image_title = "%s_%s.jpg" % (widget_id,student_id) 1775 current_filename = os.path.join(student_id, 1776 image_title) 1777 file_path = os.path.join(self.storage_path, 1778 current_filename) 1779 else: 1780 file_path = "XXX" 1781 image_title = "" 1782 # read the file from the filesystem 1783 if not os.path.exists(file_path): 1784 height = -1 1785 width = -1 1786 empty_file = True 1787 session_file = False 1788 current_filename = '' 1789 content_url = '' 1790 size = 0 1791 mimetype = '' 1792 last_modified = '' 1793 height = '' 1794 width = '' 1795 else: 1796 image = open(file_path) 1797 from OFS.Image import getImageInfo as getImageInfoOFS 1798 image.seek(0) 1799 data = image.read(2000) 1800 size = len(data) 1801 empty_file = size == 0 1802 session_file = False 1803 last_modified = '' 1804 image.close() 1805 mimetype, width, height = getImageInfoOFS(data) 1806 registry = getToolByName(self, 'mimetypes_registry') 1807 mimetype = (registry.lookupExtension(current_filename.lower()) or 1808 registry.lookupExtension('file.bin')) 1809 if width < 0: 1810 width = None 1811 if height < 0: 1812 height = None 1813 1814 if (self.allow_resize 1815 and height is not None 1816 and width is not None): 1817 z_w = z_h = 1 1818 h = int(self.display_height) 1819 w = int(self.display_width) 1820 if w and h: 1821 if w < width: 1822 z_w = w / float(width) 1823 if h < height: 1824 z_h = h / float(height) 1825 zoom = min(z_w, z_h) 1826 width = int(zoom * width) 1827 height = int(zoom * height) 1828 #import pdb;pdb.set_trace() 1829 title = image_title 1830 image_info = { 1831 'empty_file': empty_file, 1832 'session_file': session_file, 1833 'current_filename': title, 1834 'size': size, 1835 'last_modified': last_modified, 1836 'content_url': content_url, 1837 'mimetype': mimetype, 1838 } 1839 alt = title or '' 1840 #height = int(self.display_height) 1841 #width = int(self.display_width) 1842 if height is None or width is None: 1843 tag = renderHtmlTag('img', src=image_info['content_url'], 1844 alt=alt, title=title) 1845 else: 1846 tag = renderHtmlTag('img', src=image_info['content_url'], 1847 width=str(width), height=str(height), 1848 alt=alt, title=title) 1849 1850 image_info['height'] = height 1851 image_info['width'] = width 1852 image_info['image_tag'] = tag 1853 return image_info 1854 ###) 1855 1856 def checkFileName(self, filename, mimetype): 1857 return '', {} 1858 if mimetype and mimetype.startswith('image'): 1859 return '', {} 1860 return 'cpsschemas_err_image', {} 1861 1862 def prepare(self, datastructure, **kw): ###( 1863 """Prepare datastructure from datamodel.""" 1864 datamodel = datastructure.getDataModel() 1865 widget_id = self.getWidgetId() 1866 file_name = datamodel[self.fields[0]] 1867 #import pdb; pdb.set_trace() 1868 if self.allow_resize: 1869 datastructure[self.getWidgetId() + '_resize'] = '' 1870 datastructure[widget_id] = file_name 1871 datastructure[widget_id + '_choice'] = 'change' 1872 title = 'Passport Foto' 1873 datastructure[widget_id + '_filename'] = title 1874 ###) 1875 1876 def validate(self, datastructure, **kw): ###( 1877 """Update datamodel from user data in datastructure. 1878 """ 1879 logger = logging.getLogger('Widgets.FileImageWidget.validate') 1880 datamodel = datastructure.getDataModel() 1881 field_id = self.fields[0] 1882 widget_id = self.getWidgetId() 1883 store = False 1884 fileupload = None 1885 mimetype = None 1886 old_file = datamodel[field_id] 1887 # if old_file is not None: 1888 # old_filename = old_file.title 1889 # else: 1890 # old_filename = '' 1891 choice = datastructure[widget_id+'_choice'] 1892 fileupload = datastructure[widget_id] 1893 is_upload = isinstance(fileupload, FileUpload) 1894 #import pdb; pdb.set_trace() 1895 if not is_upload and not datamodel[field_id]: 1896 if self.is_required: 1897 return self.validateError('Picture upload required', {}, 1898 datastructure) 1899 if self.id_field == "": 1900 student_id = self.getStudentId() 1901 else: 1902 student_id = datastructure[self.id_field] 1903 if choice == 'delete': 1904 if self.is_required: 1905 return self.validateError('cpsschemas_err_required', {}, 1906 datastructure) 1907 ext ='jpg' 1908 filename = "%s_%s.%s" % (self.getWidgetId(), 1909 student_id, 1910 ext) 1911 # Remove the file in the filesystem 1912 student_path = os.path.join(self.storage_path,student_id) 1913 full_path = os.path.join(student_path, filename) 1914 if os.path.exists(full_path): 1915 os.remove(full_path) 1916 datamodel[field_id] = None 1917 elif choice == 'keep': 1918 fileupload = datastructure[widget_id] 1919 if isinstance(fileupload, PersistableFileUpload): 1920 # Keeping something from the session means we 1921 # actually want to store it. 1922 store = True 1923 # else: 1924 # # Nothing to change, don't pollute datastructure 1925 # # with something costly already stored, which therefore 1926 # # doesn't need to be kept in the session. 1927 # self.unprepare(datastructure) 1928 elif choice == 'change' and is_upload: 1929 if not fileupload: 1930 return self.validateError('cpsschemas_err_file_empty', {}, 1931 datastructure) 1932 if not isinstance(fileupload, FileUpload): 1933 return self.validateError('cpsschemas_err_file', {}, 1934 datastructure) 1935 fileupload.seek(0, 2) # end of file 1936 size = fileupload.tell() 1937 if not size: 1938 return self.validateError('cpsschemas_err_file_empty', {}, 1939 datastructure) 1940 if self.size_max and size > self.size_max: 1941 max_size_str = self.getHumanReadableSize(self.size_max) 1942 err = 'This file is too big, the allowed max size is ${max_size}' 1943 logger.info('%s tried to upload picture with size %dk' %(datastructure['reg_no'],int(size)/1000) ) 1944 err_mapping = {'max_size': max_size_str} 1945 return self.validateError(err, err_mapping, datastructure) 1946 store = True 1947 1948 1949 # Find filename 1950 if is_upload and store: 1951 ext ='jpg' 1952 filename = "%s_%s.%s" % (self.getWidgetId(), 1953 student_id, 1954 ext) 1955 datamodel[field_id] = filename 1956 registry = getToolByName(self, 'mimetypes_registry') 1957 mimetype = registry.lookupExtension(filename.lower()) 1958 if mimetype is not None: 1959 mimetype = str(mimetype) # normalize 1960 #import pdb; pdb.set_trace() 1961 file = self.makeFile(filename, fileupload, datastructure) 1962 # Fixup mimetype 1963 if mimetype and file.content_type != mimetype: 1964 file.content_type = mimetype 1965 # Store the file in the filesystem 1966 student_path = os.path.join(self.storage_path,student_id) 1967 if not os.path.exists(student_path): 1968 os.mkdir(student_path) 1969 full_path = os.path.join(student_path, filename) 1970 #import pdb;pdb.set_trace() 1971 pict = open(full_path,"w") 1972 fileupload.seek(0) 1973 pict.write(fileupload.read()) 1974 pict.close() 1975 return True 1976 1977 ###) 1978 1979 def render(self, mode, datastructure, **kw): ###( 1980 render_method = 'widget_image_render' 1981 meth = getattr(self, render_method, None) 1982 if meth is None: 1983 raise RuntimeError("Unknown Render Method %s for widget type %s" 1984 % (render_method, self.getId())) 1985 img_info = self.getImageInfo(datastructure) 1986 return meth(mode=mode, datastructure=datastructure, **img_info) 1987 ###) 1988 1989 InitializeClass(FileImageWidget) 1990 1991 widgetRegistry.register(FileImageWidget) 1992 ###) 1742 1993 1743 1994 ########### -
WAeUP_SRP/base/skins/waeup_student/getApplicationInfo.py
r1871 r2335 12 12 return Info about the current Student 13 13 """ 14 import logging15 logger = logging.getLogger('Skins.getApplicationInfo')16 14 17 15 request = context.REQUEST … … 28 26 requested_id = context.getStudentId() 29 27 if requested_id and not context.isStaff() and member_id != requested_id: 28 import logging 29 logger = logging.getLogger('Skins.getApplicationInfo') 30 30 logger.info('%s tried to access application object of %s' % (member_id,requested_id)) 31 31 student_id = requested_id -
WAeUP_SRP/base/skins/waeup_utilities/viewimage.py
r2114 r2335 5 5 ##bind script=script 6 6 ##bind subpath=traverse_subpath 7 ##parameters=path 7 ##parameters=path=None 8 8 ##title= 9 9 ## … … 16 16 def set_trace(): 17 17 pass 18 if path is None and traverse_subpath: 19 path = "/".join(traverse_subpath) 18 20 return context.waeup_tool.showFsPicture(path) 19 21 #import logging -
WAeUP_SRP/uniben/profiles/default/layouts/student_clearance.xml
r1958 r2335 8 8 <property name="flexible_widgets"/> 9 9 <property name="validate_values_expr"></property> 10 <widget name="acc_inst" meta_type=" Image Widget">10 <widget name="acc_inst" meta_type="File Image Widget"> 11 11 <property name="title">Accepted by Institution</property> 12 12 <property name="fields"> … … 25 25 <property name="allow_resize">True</property> 26 26 </widget> 27 <widget name="acc_let" meta_type=" Image Widget">27 <widget name="acc_let" meta_type="File Image Widget"> 28 28 <property name="title">Acceptance Letter </property> 29 29 <property name="fields"> … … 42 42 <property name="allow_resize">True</property> 43 43 </widget> 44 <widget name="age_dec" meta_type=" Image Widget">44 <widget name="age_dec" meta_type="File Image Widget"> 45 45 <property name="title">Age Declaration</property> 46 46 <property name="fields"> … … 115 115 <property name="hidden_readonly_layout_modes"/> 116 116 </widget> 117 <widget name="alr_scan" meta_type=" Image Widget">117 <widget name="alr_scan" meta_type="File Image Widget"> 118 118 <property name="title">Scan of Advanced Level Result</property> 119 119 <property name="fields"> … … 132 132 <property name="allow_resize">True</property> 133 133 </widget> 134 <widget name="birth_certificate" meta_type=" Image Widget">134 <widget name="birth_certificate" meta_type="File Image Widget"> 135 135 <property name="title">Birth Certificate</property> 136 136 <property name="fields"> … … 165 165 <property name="time_setting">False</property> 166 166 </widget> 167 <widget name="cert" meta_type=" Image Widget">167 <widget name="cert" meta_type="File Image Widget"> 168 168 <property name="title">Certificate</property> 169 169 <property name="fields"> … … 196 196 <property name="prefix">CLR</property> 197 197 </widget> 198 <widget name="cred" meta_type=" Image Widget">198 <widget name="cred" meta_type="File Image Widget"> 199 199 <property name="title">Credential</property> 200 200 <property name="fields"> … … 280 280 <property name="time_setting">False</property> 281 281 </widget> 282 <widget name="evid" meta_type=" Image Widget">282 <widget name="evid" meta_type="File Image Widget"> 283 283 <property name="title">Evidence of Name</property> 284 284 <property name="fields"> … … 369 369 <property name="hidden_readonly_layout_modes"/> 370 370 </widget> 371 <widget name="fst_sit_scan" meta_type=" Image Widget">371 <widget name="fst_sit_scan" meta_type="File Image Widget"> 372 372 <property name="title">Scan of First Sitting Result</property> 373 373 <property name="fields"> … … 440 440 <property name="hidden_readonly_layout_modes"/> 441 441 </widget> 442 <widget name="hq_scan" meta_type=" Image Widget">442 <widget name="hq_scan" meta_type="File Image Widget"> 443 443 <property name="title">Scan of Higher Qualification Result</property> 444 444 <property name="fields"> … … 498 498 <property name="vocabulary">high_qual</property> 499 499 </widget> 500 <widget name="jamb_let" meta_type=" Image Widget">500 <widget name="jamb_let" meta_type="File Image Widget"> 501 501 <property name="title">JAMB Letter</property> 502 502 <property name="fields"> … … 515 515 <property name="allow_resize">True</property> 516 516 </widget> 517 <widget name="jamb_slip" meta_type=" Image Widget">517 <widget name="jamb_slip" meta_type="File Image Widget"> 518 518 <property name="title">JAMB Slip</property> 519 519 <property name="fields"> … … 546 546 <property name="vocabulary">local_gov_areas</property> 547 547 </widget> 548 <widget name="lga_ident" meta_type=" Image Widget">548 <widget name="lga_ident" meta_type="File Image Widget"> 549 549 <property name="title">LGA Identification</property> 550 550 <property name="fields"> … … 593 593 <property name="vocabulary">states</property> 594 594 </widget> 595 <widget name="ref_let" meta_type=" Image Widget">595 <widget name="ref_let" meta_type="File Image Widget"> 596 596 <property name="title">Referee Letter</property> 597 597 <property name="fields"> … … 610 610 <property name="allow_resize">True</property> 611 611 </widget> 612 <widget name="res_stat" meta_type=" Image Widget">612 <widget name="res_stat" meta_type="File Image Widget"> 613 613 <property name="title">Result Statement</property> 614 614 <property name="fields"> … … 684 684 <property name="hidden_readonly_layout_modes"/> 685 685 </widget> 686 <widget name="scd_sit_scan" meta_type=" Image Widget">686 <widget name="scd_sit_scan" meta_type="File Image Widget"> 687 687 <property name="title">Scan of Second Sitting Result</property> 688 688 <property name="fields"> … … 715 715 <property name="vocabulary">exam_types</property> 716 716 </widget> 717 <widget name="stat_dec" meta_type=" Image Widget">717 <widget name="stat_dec" meta_type="File Image Widget"> 718 718 <property name="title">Statutory Declaration of Good Conduct</property> 719 719 <property name="fields"> -
WAeUP_SRP/uniben/profiles/default/layouts/student_clearance_fe.xml
r1978 r2335 8 8 <property name="flexible_widgets"/> 9 9 <property name="validate_values_expr"></property> 10 <widget name="acc_inst" meta_type=" Image Widget">10 <widget name="acc_inst" meta_type="File Image Widget"> 11 11 <property name="title">Accepted by Institution</property> 12 12 <property name="fields"> … … 25 25 <property name="allow_resize">True</property> 26 26 </widget> 27 <widget name="acc_let" meta_type=" Image Widget">27 <widget name="acc_let" meta_type="File Image Widget"> 28 28 <property name="title">Acceptance Letter </property> 29 29 <property name="fields"> … … 42 42 <property name="allow_resize">True</property> 43 43 </widget> 44 <widget name="age_dec" meta_type=" Image Widget">44 <widget name="age_dec" meta_type="File Image Widget"> 45 45 <property name="title">Age Declaration</property> 46 46 <property name="fields"> … … 116 116 <property name="hidden_readonly_layout_modes"/> 117 117 </widget> 118 <widget name="alr_scan" meta_type=" Image Widget">118 <widget name="alr_scan" meta_type="File Image Widget"> 119 119 <property name="title">Scan of Advanced Level Result</property> 120 120 <property name="fields"> … … 133 133 <property name="allow_resize">True</property> 134 134 </widget> 135 <widget name="birth_certificate" meta_type=" Image Widget">135 <widget name="birth_certificate" meta_type="File Image Widget"> 136 136 <property name="title">Birth Certificate</property> 137 137 <property name="fields"> … … 166 166 <property name="time_setting">False</property> 167 167 </widget> 168 <widget name="cert" meta_type=" Image Widget">168 <widget name="cert" meta_type="File Image Widget"> 169 169 <property name="title">Certificate</property> 170 170 <property name="fields"> … … 197 197 <property name="prefix">CLR</property> 198 198 </widget> 199 <widget name="cred" meta_type=" Image Widget">199 <widget name="cred" meta_type="File Image Widget"> 200 200 <property name="title">Credential</property> 201 201 <property name="fields"> … … 281 281 <property name="time_setting">False</property> 282 282 </widget> 283 <widget name="evid" meta_type=" Image Widget">283 <widget name="evid" meta_type="File Image Widget"> 284 284 <property name="title">Evidence of Name</property> 285 285 <property name="fields"> … … 355 355 <property name="hidden_readonly_layout_modes"/> 356 356 </widget> 357 <widget name="fst_sit_scan" meta_type=" Image Widget">357 <widget name="fst_sit_scan" meta_type="File Image Widget"> 358 358 <property name="title">Scan of First Sitting Result</property> 359 359 <property name="fields"> … … 426 426 <property name="hidden_readonly_layout_modes"/> 427 427 </widget> 428 <widget name="hq_scan" meta_type=" Image Widget">428 <widget name="hq_scan" meta_type="File Image Widget"> 429 429 <property name="title">Scan of Higher Qualification Result</property> 430 430 <property name="fields"> … … 484 484 <property name="vocabulary">high_qual</property> 485 485 </widget> 486 <widget name="jamb_let" meta_type=" Image Widget">486 <widget name="jamb_let" meta_type="File Image Widget"> 487 487 <property name="title">JAMB Letter</property> 488 488 <property name="fields"> … … 501 501 <property name="allow_resize">True</property> 502 502 </widget> 503 <widget name="jamb_slip" meta_type=" Image Widget">503 <widget name="jamb_slip" meta_type="File Image Widget"> 504 504 <property name="title">JAMB Slip</property> 505 505 <property name="fields"> … … 533 533 <property name="vocabulary">local_gov_areas</property> 534 534 </widget> 535 <widget name="lga_ident" meta_type=" Image Widget">535 <widget name="lga_ident" meta_type="File Image Widget"> 536 536 <property name="title">LGA Identification</property> 537 537 <property name="fields"> … … 599 599 <property name="vocabulary">states</property> 600 600 </widget> 601 <widget name="ref_let" meta_type=" Image Widget">601 <widget name="ref_let" meta_type="File Image Widget"> 602 602 <property name="title">Referee Letter</property> 603 603 <property name="fields"> … … 616 616 <property name="allow_resize">True</property> 617 617 </widget> 618 <widget name="res_stat" meta_type=" Image Widget">618 <widget name="res_stat" meta_type="File Image Widget"> 619 619 <property name="title">Result Statement</property> 620 620 <property name="fields"> … … 690 690 <property name="hidden_readonly_layout_modes"/> 691 691 </widget> 692 <widget name="scd_sit_scan" meta_type=" Image Widget">692 <widget name="scd_sit_scan" meta_type="File Image Widget"> 693 693 <property name="title">Scan of Second Sitting Result</property> 694 694 <property name="fields"> … … 721 721 <property name="vocabulary">exam_types</property> 722 722 </widget> 723 <widget name="stat_dec" meta_type=" Image Widget">723 <widget name="stat_dec" meta_type="File Image Widget"> 724 724 <property name="title">Statutory Declaration of Good Conduct</property> 725 725 <property name="fields">
Note: See TracChangeset for help on using the changeset viewer.