Changeset 16214 for main/waeup.kofa/trunk/src
- Timestamp:
- 26 Aug 2020, 15:39:36 (4 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/applicants
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser.py
r16207 r16214 1775 1775 grok.require('waeup.manageApplication') 1776 1776 1777 class RefereesRemindPage(UtilityView, grok.View): 1778 """A display view for referee reports. 1779 """ 1780 grok.context(IApplicant) 1781 grok.name('remind_referees') 1782 grok.require('waeup.manageApplication') 1783 1784 mandate_days = 31 1785 1786 def remindReferees(self): 1787 site = grok.getSite() 1788 kofa_utils = getUtility(IKofaUtils) 1789 ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') 1790 failed = '' 1791 emails_sent = 0 1792 for referee in self.context.referees: 1793 if not referee.email_sent: 1794 continue 1795 # Check if referee has already created a report 1796 report_exists = False 1797 for report in self.context.refereereports: 1798 if report.name == referee.name: 1799 report_exists = True 1800 if report_exists: 1801 continue 1802 # If not, create new mandate 1803 mandate = RefereeReportMandate(days=self.mandate_days) 1804 mandate.params['name'] = referee.name 1805 mandate.params['email'] = referee.email 1806 mandate.params[ 1807 'redirect_path'] = '/applicants/%s/%s/addrefereereport' % ( 1808 self.context.__parent__.code, 1809 self.context.application_number) 1810 mandate.params['redirect_path2'] = '' 1811 mandate.params['applicant_id'] = self.context.applicant_id 1812 site['mandates'].addMandate(mandate) 1813 # Send invitation email 1814 args = {'mandate_id':mandate.mandate_id} 1815 mandate_url = self.url(site) + '/mandate?%s' % urlencode(args) 1816 url_info = u'Report link: %s' % mandate_url 1817 success = kofa_utils.inviteReferee(referee, self.context, url_info) 1818 if success: 1819 emails_sent += 1 1820 self.context.writeLogMessage( 1821 self, 'email sent: %s' % referee.email) 1822 referee.email_sent = True 1823 else: 1824 failed += '%s ' % referee.email 1825 return failed, emails_sent 1826 1827 def update(self): 1828 if self.context.state != 'submitted': 1829 self.flash( 1830 _('Not allowed!'), type='danger') 1831 return self.redirect(self.url(self.context)) 1832 failed, emails_sent = self.remindReferees() 1833 msg = _('${a} referee(s) have been reminded by email.', 1834 mapping = {'a': emails_sent}) 1835 self.flash(msg) 1836 return self.redirect(self.url(self.context)) 1837 1838 def render(self): 1839 return 1840 1777 1841 class RefereeReportDisplayFormPage(KofaDisplayFormPage): 1778 1842 """A display view for referee reports. … … 1846 1910 args = {'mandate_id':mandate.mandate_id} 1847 1911 # Check if report exists. 1848 # If so, redirect to the pdf file. 1912 # (1) If mandate has been used to create a report, 1913 # redirect to the pdf file. 1849 1914 if mandate.params.get('redirect_path2'): 1850 1915 self.redirect( … … 1853 1918 '?%s' % urlencode(args)) 1854 1919 return 1920 # (2) Report exists but was created with another mandate. 1921 for report in self.context.refereereports: 1922 if report.name == mandate.params.get('name'): 1923 self.flash(_('You have already created a ' 1924 'report with another mandate.'), 1925 type='warning') 1926 self.redirect(self.application_url()) 1927 return 1855 1928 # Prefill form with mandate params 1856 1929 self.form_fields.get( … … 1885 1958 notify(grok.ObjectModifiedEvent(self.mandates[self.mandate_id])) 1886 1959 args = {'mandate_id':self.mandate_id} 1887 self.redirect(self.url(report, 'referee_report.pdf') 1888 + '?%s' % urlencode(args)) 1960 self.flash(_('Your report has been successfully submitted. ' 1961 'Please use the report link in the email again to download ' 1962 'a pdf slip of your report.')) 1963 #self.redirect(self.url(report, 'referee_report.pdf') 1964 # + '?%s' % urlencode(args)) 1965 self.redirect(self.application_url()) 1889 1966 return 1890 1967 -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py
r16190 r16214 1746 1746 self.browser.getControl(name="form.email").value = 'bb@bb.bb' 1747 1747 self.browser.getControl("Submit").click() 1748 # Referee wil be redirected to a pdf file 1748 # Referee will be redirected to the frontpage 1749 self.assertEqual(self.browser.url, 'http://localhost/app') 1750 self.assertTrue('Your report has been successfully submitted. ' 1751 'Please use the report link in the email again ' 1752 'to download a pdf slip of your report.' 1753 in self.browser.contents) 1754 # If they use the mandate again, they will be redirected to a pdf file 1755 self.browser.open('http://localhost/app/mandate?mandate_id=%s' 1756 % mandate.mandate_id) 1749 1757 self.assertEqual(self.browser.headers['Status'], '200 Ok') 1750 1758 self.assertEqual(self.browser.headers['Content-Type'], … … 1762 1770 self.assertEqual(self.browser.headers['Content-Type'], 1763 1771 'application/pdf') 1772 # Referees can't use another mandate for adding a new report 1773 mandate2 = RefereeReportMandate() 1774 mandate2.params['name'] = u'John Referee' 1775 mandate2.params['email'] = 'aa@aa.aa' 1776 mandate2.params['applicant_id'] = self.applicant.applicant_id 1777 mandate2.params['redirect_path'] = '/applicants/%s/%s/addrefereereport' % ( 1778 container_name_1, self.applicant.application_number) 1779 mandate2.params['redirect_path2'] = '' 1780 self.app['mandates'].addMandate(mandate2) 1781 self.browser.open('http://localhost/app/mandate?mandate_id=%s' 1782 % mandate2.mandate_id) 1783 self.assertTrue('You have already created a report with another mandate' 1784 in self.browser.contents) 1764 1785 # Managers can view the report 1765 1786 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') … … 1778 1799 print "Sample PDF referee_report_slip.pdf written to %s" % path 1779 1800 # Mandate is not deleted ... 1780 self.assertEqual(len(self.app['mandates'].keys()), 1)1801 self.assertEqual(len(self.app['mandates'].keys()), 2) 1781 1802 # ... but redirect_path2 attribute has been set 1782 1803 redirect_path2 = '/applicants/%s/%s/%s/referee_report.pdf' % ( … … 1785 1806 report.r_id) 1786 1807 self.assertEqual( 1787 self.app['mandates'] .values()[0].params['redirect_path2'],1808 self.app['mandates'][mandate.mandate_id].params['redirect_path2'], 1788 1809 redirect_path2) 1789 1810 # Managers can delete referee reports … … 1831 1852 self.browser.getControl(name="confirm_passport").value = True 1832 1853 self.browser.getControl("Finally Submit").click() 1833 mandate_id_0 = self.app['mandates'].keys()[0]1834 mandate_id_1 = self.app['mandates'].keys()[1]1835 1854 if self.app['mandates'].values()[0].params['name'] == 'Linda Tree': 1836 1855 mandate_id_0 = self.app['mandates'].keys()[0] … … 1920 1939 'invitation emails were sent.' in self.browser.contents) 1921 1940 return 1941 1942 def test_remind_referees(self): 1943 self.applicant.lastname = u'Mitchell' 1944 IWorkflowState(self.applicant).setState('submitted') 1945 # Add two referees 1946 referee1 = RefereeEntry() 1947 referee2 = RefereeEntry() 1948 referee1.name = u'Linda Tree' 1949 referee1.email = 'linda@forest.de' 1950 referee2.name = u'Otis Stone' 1951 referee2.email = 'otis@stones.de' 1952 referee1.email_sent = True 1953 referee2.email_sent = True 1954 self.applicant.referees = [referee1, referee2] 1955 # Managers can remind referees 1956 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 1957 self.browser.open(self.manage_path) 1958 self.browser.getLink("Remind referees").click() 1959 self.assertTrue('2 referee(s) have been reminded by email.' 1960 in self.browser.contents) 1961 logfile = os.path.join( 1962 self.app['datacenter'].storage, 'logs', 'applicants.log') 1963 logcontent = open(logfile).read() 1964 self.assertTrue( 1965 'zope.mgr - applicants.browser.RefereesRemindPage - %s - ' 1966 'email sent: otis@stones.de' % self.applicant.applicant_id 1967 in logcontent) 1968 if self.app['mandates'].values()[0].params['name'] == 'Linda Tree': 1969 mandate_id_0 = self.app['mandates'].keys()[0] 1970 mandate_id_1 = self.app['mandates'].keys()[1] 1971 else: 1972 mandate_id_0 = self.app['mandates'].keys()[1] 1973 mandate_id_1 = self.app['mandates'].keys()[0] 1974 self.assertMatches( 1975 'Sending email from no-reply@waeup.org to linda@forest.de:' 1976 '\nMessage:' 1977 '\nmsg: MIME-Version: 1.0\nmsg: Content-Type: text/plain; charset="us-ascii"' 1978 '\nmsg: Content-Transfer-Encoding: 7bit' 1979 '\nmsg: From: Administrator <no-reply@waeup.org>' 1980 '\nmsg: To: Linda Tree <linda@forest.de>' 1981 '\nmsg: Reply-To: Administrator <contact@waeup.org>' 1982 '\nmsg: Subject: Request for referee report from Sample University' 1983 '\nmsg: ' 1984 '\nmsg: Dear Linda Tree,' 1985 '\nmsg: ' 1986 '\nmsg: The candidate with Id app%s_372052 and name Joan Mitchell applied to' 1987 '\nmsg: the Sample University to study Unnamed Certificate for the %s/%s session.' 1988 '\nmsg: The candidate has listed you as referee. You are thus required to kindly use' 1989 '\nmsg: the link below to provide your referral remarks on or before' 1990 '\nmsg: 2016-08-12 08:32:41.619671+00:00.' 1991 '\nmsg: ' 1992 '\nmsg: Report link: http://localhost/app/mandate?mandate_id=%s' 1993 '\nmsg: ' 1994 '\nmsg: Thank You' 1995 '\nmsg: ' 1996 '\nmsg: The Secretary' 1997 '\nmsg: Post Graduate School' 1998 '\nmsg: Sample University' 1999 '\nmsg: ' 2000 '\nSending email from no-reply@waeup.org to otis@stones.de:' 2001 '\nMessage:' 2002 '\nmsg: MIME-Version: 1.0' 2003 '\nmsg: Content-Type: text/plain; charset="us-ascii"' 2004 '\nmsg: Content-Transfer-Encoding: 7bit' 2005 '\nmsg: From: Administrator <no-reply@waeup.org>' 2006 '\nmsg: To: Otis Stone <otis@stones.de>' 2007 '\nmsg: Reply-To: Administrator <contact@waeup.org>' 2008 '\nmsg: Subject: Request for referee report from Sample University' 2009 '\nmsg: ' 2010 '\nmsg: Dear Otis Stone,' 2011 '\nmsg: ' 2012 '\nmsg: The candidate with Id app%s_<6-DIGITS> and name Joan Mitchell applied to' 2013 '\nmsg: the Sample University to study Unnamed Certificate for the %s/%s session.' 2014 '\nmsg: The candidate has listed you as referee. You are thus required to kindly use' 2015 '\nmsg: the link below to provide your referral remarks on or before' 2016 '\nmsg: <YYYY-MM-DD hh:mm:ss>.<6-DIGITS>+00:00.' 2017 '\nmsg: ' 2018 '\nmsg: Report link: http://localhost/app/mandate?mandate_id=%s' 2019 '\nmsg: ' 2020 '\nmsg: Thank You' 2021 '\nmsg: ' 2022 '\nmsg: The Secretary' 2023 '\nmsg: Post Graduate School' 2024 '\nmsg: Sample University' 2025 '\nmsg: ' 2026 % (session_1, session_1, session_2, mandate_id_0, 2027 session_1, session_1, session_2, mandate_id_1,), 2028 self.get_fake_smtp_output() 2029 ) 2030 # If a report exists, only one email is being sent to Otis Stone. 2031 report = createObject(u'waeup.ApplicantRefereeReport') 2032 report.r_id = 'any_id' 2033 report.name = u'Linda Tree' 2034 self.applicant[report.r_id] = report 2035 self.browser.open(self.manage_path) 2036 self.browser.getLink("Remind referees").click() 2037 self.assertTrue('1 referee(s) have been reminded by email.' 2038 in self.browser.contents) 2039 return -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/viewlets.py
r16059 r16214 271 271 return self.view.url(self.view.context, self.target) 272 272 273 class RemindRefereesActionButton(ManageActionButton): 274 grok.order(5) 275 grok.context(IApplicant) 276 grok.require('waeup.manageApplication') 277 icon = 'actionicon_alarm.png' 278 text = _('Remind referees') 279 target ='remind_referees' 280 281 @property 282 def onclick(self): 283 return "return window.confirm(%s);" % _( 284 "'Those referees, who have not yet submitted their report, will be reminded by email. Are you sure?'") 285 286 @property 287 def target_url(self): 288 """Get a URL to the target... 289 """ 290 if self.context.state != 'submitted': 291 return 292 if not self.context.referees: 293 return 294 return self.view.url(self.view.context, self.target) 295 273 296 class PaymentReceiptActionButton(ManageActionButton): 274 297 grok.order(9) # This button should always be the last one.
Note: See TracChangeset for help on using the changeset viewer.