- Timestamp:
- 21 Sep 2012, 08:19:35 (12 years ago)
- Location:
- main/waeup.kofa/branches/uli-zc-async
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/branches/uli-zc-async
- Property svn:mergeinfo changed
/main/waeup.kofa/branches/uli-async-update removed /main/waeup.kofa/branches/uli-autoinclude-less removed /main/waeup.kofa/trunk removed
- Property svn:mergeinfo changed
-
main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/browser/pages.py
r9209 r9211 18 18 """ Viewing components for Kofa objects. 19 19 """ 20 import copy 20 21 import csv 21 22 import grok … … 23 24 import re 24 25 import sys 25 from urllib import urlencode 26 import time 27 import re 26 28 from zope import schema 27 29 from zope.authentication.interfaces import ( … … 32 34 getUtilitiesFor, 33 35 ) 36 #from zope.component.interfaces import Invalid 34 37 from zope.event import notify 35 from zope.securitypolicy.interfaces import IPrincipalRoleManager 38 from zope.securitypolicy.interfaces import ( 39 IPrincipalRoleManager, IPrincipalRoleMap) 36 40 from zope.session.interfaces import ISession 37 from zope.password.interfaces import IPasswordManager38 41 from waeup.kofa.browser.layout import ( 39 42 KofaPage, KofaForm, KofaEditFormPage, KofaAddFormPage, … … 46 49 from waeup.kofa.browser.layout import jsaction, action, UtilityView 47 50 from waeup.kofa.browser.resources import ( 48 warning, tabs, datatable)51 warning, datepicker, tabs, datatable, page_reloader, page_not_reloader) 49 52 from waeup.kofa.interfaces import MessageFactory as _ 50 53 from waeup.kofa.interfaces import( … … 61 64 from waeup.kofa.university.vocabularies import course_levels 62 65 from waeup.kofa.authentication import LocalRoleSetEvent 66 #from waeup.kofa.widgets.restwidget import ReSTDisplayWidget 63 67 from waeup.kofa.widgets.htmlwidget import HTMLDisplayWidget 64 from waeup.kofa. utils.helpers import get_user_account65 from waeup.kofa. mandates.mandate import PasswordMandate68 from waeup.kofa.authentication import get_principal_role_manager 69 from waeup.kofa.utils.helpers import get_user_account, msave 66 70 67 71 grok.context(IKofaObject) … … 152 156 return 153 157 154 # Save function used for save methods in pages155 def msave(view, **data):156 changed_fields = view.applyData(view.context, **data)157 # Turn list of lists into single list158 if changed_fields:159 changed_fields = reduce(lambda x,y: x+y, changed_fields.values())160 fields_string = ' + '.join(changed_fields)161 view.flash(_('Form has been saved.'))162 ob_class = view.__implemented__.__name__.replace('waeup.kofa.','')163 if fields_string:164 grok.getSite().logger.info('%s - %s - saved: %s' % (ob_class, view.context.__name__, fields_string))165 return166 167 158 # 168 159 # Login/logout and language switch pages... … … 201 192 self.redirect(self.camefrom) 202 193 return 203 # Display appropriate flash message if credentials are correct 204 # but student has been deactivated. 205 login = self.request.form['form.login'] 206 if len(login) == 8 and grok.getSite()['students'].has_key(login): 207 student = grok.getSite()['students'][ 208 self.request.form['form.login']] 209 password = self.request.form['form.password'] 210 passwordmanager = getUtility(IPasswordManager, 'SSHA') 211 if passwordmanager.checkPassword(student.password, password): 212 self.flash(_('Your account has been deactivated.')) 213 return 214 self.flash(_('You entered invalid credentials.')) 194 self.flash(_('You entered wrong credentials.')) 215 195 216 196 … … 392 372 def entries(self): 393 373 return () 374 375 class ReindexPage(UtilityView, grok.View): 376 """ Reindex view. 377 378 Reindexes a catalog. For managers only. 379 """ 380 grok.context(IUniversity) 381 grok.name('reindex') 382 grok.require('waeup.managePortal') 383 384 def update(self,ctlg=None): 385 if ctlg is None: 386 self.flash('No catalog name provided.') 387 return 388 cat = queryUtility(ICatalog, name='%s_catalog' % ctlg) 389 if cat is None: 390 self.flash('%s_catalog does not exist' % ctlg) 391 return 392 self.context.logger.info( 393 'Catalog `%s_catalog` re-indexing started.' % ctlg) 394 cat.updateIndexes() 395 no_of_entries = cat.values()[0].documentCount() 396 self.flash('%d %s re-indexed.' % (no_of_entries,ctlg)) 397 self.context.logger.info( 398 'Re-indexing of %d objects finished.' % no_of_entries) 399 return 400 401 def render(self): 402 self.redirect(self.url(self.context, '@@index')) 403 return 394 404 395 405 # … … 791 801 def delFiles(self, **data): 792 802 form = self.request.form 803 logger = self.context.logger 793 804 if form.has_key('val_id'): 794 805 child_id = form['val_id'] … … 815 826 return 816 827 817 class DatacenterFinishedPage(KofaEditFormPage):818 grok.context(IDataCenter)819 grok.name('processed')820 grok.require('waeup.manageDataCenter')821 label = _(u'Processed Files')822 pnav = 0823 824 def update(self):825 datatable.need()826 return super(DatacenterFinishedPage, self).update()827 828 828 class DatacenterUploadPage(KofaPage): 829 829 grok.context(IDataCenter) 830 830 grok.name('upload') 831 831 grok.require('waeup.manageDataCenter') 832 label = _(u'Upload portal data as CSVfile')832 label = _(u'Upload file') 833 833 pnav = 0 834 834 upload_button =_(u'Upload') … … 849 849 self.flash(_("Only csv files are allowed.")) 850 850 return 851 normalized_filename = self.getNormalizedFileName(filename) 852 finished_file = os.path.join( 853 self.context.storage, 'finished', normalized_filename) 854 unfinished_file = os.path.join( 855 self.context.storage, 'unfinished', normalized_filename) 856 if os.path.exists(finished_file) or os.path.exists(unfinished_file): 857 self.flash(_("File with same name was uploaded earlier.")) 858 return 859 target = os.path.join(self.context.storage, normalized_filename) 851 target = os.path.join(self.context.storage, 852 self.getNormalizedFileName(filename)) 860 853 open(target, 'wb').write(uploadfile.read()) 861 854 os.chmod(target, 0664) … … 888 881 return '%s_%s%s' % (base, filtered_username, ext.lower()) 889 882 890 def getImporters(self):891 importers = getAllUtilitiesRegisteredFor(IBatchProcessor)892 importer_props = []893 for x in importers:894 iface_fields = schema.getFields(x.iface)895 available_fields = []896 for key in iface_fields.keys():897 iface_fields[key] = (iface_fields[key].__class__.__name__,898 iface_fields[key].required)899 for value in x.available_fields:900 available_fields.append(901 dict(f_name=value,902 f_type=iface_fields.get(value, (None, False))[0],903 f_required=iface_fields.get(value, (None, False))[1]904 )905 )906 available_fields = sorted(available_fields, key=lambda k: k['f_name'])907 importer_props.append(908 dict(title=x.name, name=x.util_name, fields=available_fields))909 return sorted(importer_props, key=lambda k: k['title'])910 911 883 class FileDownloadView(UtilityView, grok.View): 912 884 grok.context(IDataCenter) … … 925 897 'Content-Type', 'text/csv; charset=UTF-8') 926 898 self.response.setHeader( 927 'Content-Disposition:', 'attachment; filename="%s ' %928 self.filename.replace(' finished/',''))899 'Content-Disposition:', 'attachment; filename="%s.csv' % 900 self.filename.replace('.csv','')) 929 901 fullpath = os.path.join(self.context.storage, self.filename) 930 902 return open(fullpath, 'rb').read() 931 932 class SkeletonDownloadView(UtilityView, grok.View):933 grok.context(IDataCenter)934 grok.name('skeleton')935 grok.require('waeup.manageDataCenter')936 937 def update(self, processorname=None):938 self.processorname = self.request.form['name']939 self.filename = ('%s_000.csv' %940 self.processorname.replace('processor','import'))941 return942 943 def render(self):944 #ob_class = self.__implemented__.__name__.replace('waeup.kofa.','')945 #self.context.logger.info(946 # '%s - skeleton downloaded: %s' % (ob_class, self.filename))947 self.response.setHeader(948 'Content-Type', 'text/csv; charset=UTF-8')949 self.response.setHeader(950 'Content-Disposition:', 'attachment; filename="%s' % self.filename)951 processor = getUtility(IBatchProcessor, name=self.processorname)952 csv_data = processor.get_csv_skeleton()953 return csv_data954 903 955 904 class DatacenterImportStep1(KofaPage): … … 965 914 966 915 def getFiles(self): 967 files = self.context.get PendingFiles(sort='date')916 files = self.context.getFiles(sort='date') 968 917 for file in files: 969 918 name = file.name … … 1189 1138 return False 1190 1139 1140 @property 1141 def nextstep(self): 1142 return self.url(self.context, '@@import4') 1143 1191 1144 def update(self, headerfield=None, back2=None, cancel=None, proceed=None): 1192 1145 datatable.need() … … 1409 1362 string representing the exporter title used when triggering 1410 1363 the export job. 1364 1365 Calling this method also installs a JavaScript page reloader 1366 that reloads the page after some time (1.5 secs), if there is 1367 a running export that is not completed yet. 1368 1369 The method caches results. 1411 1370 """ 1412 1371 if self._running_exports is None: … … 1416 1375 def _getRunningExports(self): 1417 1376 result = self.context.get_export_jobs_status(self.user_id) 1377 uncompleted = [x for x in result if x[0] != 'completed'] 1378 #if len(uncompleted): 1379 # page_reloader.need() 1380 #else: 1381 # page_not_reloader.need() 1418 1382 return result 1419 1383 … … 1462 1426 return 1463 1427 result = open(path, 'rb').read() 1464 acronym = grok.getSite()['configuration'].acronym.replace(' ','')1465 filename = "%s_%s" % (acronym, os.path.basename(path))1466 1428 self.response.setHeader( 1467 1429 'Content-Type', 'text/csv; charset=UTF-8') 1468 self.response.setHeader(1469 'Content-Disposition', 'attachment; filename="%s' % filename)1470 1430 # remove job and running_exports entry from context 1471 1431 self.context.delete_export_entry( … … 2027 1987 grok.template('certificatemanagepage') 2028 1988 taboneactions = [_('Save'),_('Cancel')] 2029 tabtwoactions = [_('Add c ertificate course'),2030 _('Remove selected c ertificate courses'),_('Cancel')]1989 tabtwoactions = [_('Add course referrer'), 1990 _('Remove selected course referrers'),_('Cancel')] 2031 1991 tabthreeactions1 = [_('Remove selected local roles')] 2032 1992 tabthreeactions2 = [_('Add local role')] … … 2051 2011 return msave(self, **data) 2052 2012 2053 @jsaction(_('Remove selected c ertificate courses'))2013 @jsaction(_('Remove selected course referrers')) 2054 2014 def delCertificateCourses(self, **data): 2055 2015 delSubobjects(self, redirect='@@manage', tab='2') 2056 2016 return 2057 2017 2058 @action(_('Add c ertificate course'), validator=NullValidator)2018 @action(_('Add course referrer'), validator=NullValidator) 2059 2019 def addCertificateCourse(self, **data): 2060 2020 self.redirect(self.url(self.context, 'addcertificatecourse')) … … 2093 2053 form_fields = grok.AutoFields(ICertificateCourseAdd) 2094 2054 pnav = 1 2095 label = _('Add c ertificate course')2096 2097 @action(_('Add c ertificate course'))2055 label = _('Add course referrer') 2056 2057 @action(_('Add course referrer')) 2098 2058 def addCertcourse(self, **data): 2099 2059 try: 2100 self.context.addC ertCourse(**data)2060 self.context.addCourseRef(**data) 2101 2061 except KeyError: 2102 self.status = self.flash(_('The chosen c ertificate courseis already '2062 self.status = self.flash(_('The chosen course referrer is already ' 2103 2063 'part of this certificate.')) 2104 2064 return 2105 2065 self.status = self.flash( 2106 _(" certificate course${a}_${b} added.",2066 _("Course referrer ${a}_${b} added.", 2107 2067 mapping = {'a': data['course'].code, 'b': data['level']})) 2108 2068 code = "%s_%s" % (data['course'].code, data['level']) … … 2145 2105 grok.require('waeup.manageAcademics') 2146 2106 form_fields = grok.AutoFields(ICertificateCourse) 2147 label = _('Edit c ertificate course')2107 label = _('Edit course referrer') 2148 2108 pnav = 1 2149 2109 … … 2158 2118 old_level = self.context.level 2159 2119 data['course'] = self.context.course 2160 parent.addC ertCourse(**data)2161 parent.delC ertCourse(data['course'].code, level=old_level)2120 parent.addCourseRef(**data) 2121 parent.delCourseRef(data['course'].code, level=old_level) 2162 2122 self.flash(_('Form has been saved.')) 2163 2123 old_code = "%s_%s" % (data['course'].code, old_level) … … 2218 2178 return None 2219 2179 2220 @action(_(' Send login credentials to email address'), style='primary')2180 @action(_('Get login credentials'), style='primary') 2221 2181 def request(self, **data): 2222 2182 if not self.captcha_result.is_valid: … … 2233 2193 # Change password 2234 2194 kofa_utils = getUtility(IKofaUtils) 2235 password = kofa_utils.genPassword() 2236 mandate = PasswordMandate() 2237 mandate.params['password'] = password 2238 mandate.params['user'] = user 2239 site = grok.getSite() 2240 site['mandates'].addMandate(mandate) 2241 # Send email with credentials 2242 args = {'mandate_id':mandate.mandate_id} 2243 mandate_url = self.url(site) + '/mandate?%s' % urlencode(args) 2244 url_info = u'Confirmation link: %s' % mandate_url 2245 msg = _('You have successfully requested a password for the') 2195 pwd = kofa_utils.genPassword() 2196 IUserAccount(user).setPassword(pwd) 2197 # Send email with new redentials 2198 msg = _('You have successfully changed your password for the') 2199 login_url = self.url(grok.getSite(), 'login') 2246 2200 success = kofa_utils.sendCredentials( 2247 IUserAccount(user),p assword,url_info,msg)2201 IUserAccount(user),pwd,login_url,msg) 2248 2202 if success: 2249 2203 self.flash(_('An email with your user name and password ' +
Note: See TracChangeset for help on using the changeset viewer.