def get(self, family_key): family = data.Family.get(family_key) if not family: raise Exception('no family') # what happens if there are cards that have never been checked? Don't worry for now. checked_cards = data.CheckedCard.all().filter('card IN ', list(family.card_set)) template_values = self.load_summary(family, checked_cards) if not template_values['should_notify']: logging.debug('no reason to notify') return subject = utils.build_notification_subject( template_values['info'], template_values['items_due'], template_values['holds_ready']) if subject: bccs = [] if template_values['error']: bccs = ['*****@*****.**'] send_email([a.email() for a in family.principals], subject, bccs=bccs, html=self.jinja.render_template('email.html', **template_values))
def get(self, family_key): family = data.Family.get(family_key) if not family: raise Exception('no family') # what happens if there are cards that have never been checked? Don't worry for now. checked_cards = data.CheckedCard.all().filter('card IN ', list(family.card_set)) template_values = self.load_summary(family, checked_cards) if not template_values['should_notify']: logging.debug('no reason to notify') return subject = utils.build_notification_subject(template_values['info'], template_values['items_due'], template_values['holds_ready']) if subject: bccs = [] if template_values['error']: bccs = ['*****@*****.**'] send_email([a.email() for a in family.principals], subject, bccs=bccs, html=self.jinja.render_template('email.html', **template_values))
def post(self): (user, family) = self.get_family() if not family: self.redirect('/account') new_principal = users.User(self.request.get('email')) if new_principal not in family.principals: if data.Family.all().filter('principals = ', new_principal).count(): logging.info('%s is a member of a different family', new_principal.email()) self.template_values.update({ 'title': 'User Belongs to Another Family', 'message': new_principal.email() + ' is already responsible for another family', }) self.render('info.html') return else: send_email([new_principal.email()], 'LibraryHippo: you are now a responsible person for the ' + family.name + ' family', body=user.email() + ' has made you a responsible person for the ' + family.name + ' family.\nLearn more by visiting LibraryHippo at http://libraryhippo.com') family.principals.append(new_principal) family.put() else: logging.debug(new_principal.email() + ' is already in ' + family.name) self.redirect('/account')
def post(self): (user, family) = self.get_family() removed_a_principal = False for principal_email in self.request.arguments(): principal = users.User(principal_email) if principal in family.principals: send_email([principal_email], 'LibraryHippo: you are no longer a responsible person for the ' + family.name + ' family', body=user.email() + ' has removed you from being a responsible person for the ' + family.name + 'family at LibraryHippo (http://libraryhippo.com)') logging.info('removing principal %s ', principal) family.principals.remove(principal) removed_a_principal = True else: logging.error('request to remove principal %s from family %s failed', principal, family.to_xml()) if len(family.principals) == 0: logging.info('no more principals - removing family %s', family.to_xml()) cards = [c for c in family.card_set] db.delete(cards + [family]) else: if removed_a_principal: family.put() logging.info('saved family %s', family.to_xml()) self.redirect('/account')
def post(self): (user, family) = self.get_family() removed_a_principal = False for principal_email in self.request.arguments(): principal = users.User(principal_email) if principal in family.principals: send_email( [principal_email], 'LibraryHippo: you are no longer a responsible person for the ' + family.name + ' family', body=user.email() + ' has removed you from being a responsible person for the ' + family.name + 'family at LibraryHippo (http://libraryhippo.com)') logging.info('removing principal %s ', principal) family.principals.remove(principal) removed_a_principal = True else: logging.error( 'request to remove principal %s from family %s failed', principal, family.to_xml()) if len(family.principals) == 0: logging.info('no more principals - removing family %s', family.to_xml()) cards = [c for c in family.card_set] db.delete(cards + [family]) else: if removed_a_principal: family.put() logging.info('saved family %s', family.to_xml()) self.redirect('/account')
def post(self): (user, family) = self.get_family() if not family: self.redirect('/account') new_principal = users.User(self.request.get('email')) if new_principal not in family.principals: if data.Family.all().filter('principals = ', new_principal).count(): logging.info('%s is a member of a different family', new_principal.email()) self.template_values.update({ 'title': 'User Belongs to Another Family', 'message': new_principal.email() + ' is already responsible for another family', }) self.render('info.html') return else: send_email([new_principal.email()], 'LibraryHippo: you are now a responsible person for the ' + family.name + ' family', body=user.email() + ' has made you a responsible person for the ' + family.name + ' family.\nLearn more by visiting LibraryHippo at https://www.libraryhippo.com') family.principals.append(new_principal) family.put() else: logging.debug(new_principal.email() + ' is already in ' + family.name) self.redirect('/account')
def get(self, family_key): for_family = data.Family.get(family_key) if not for_family: raise Exception('no family') template_values = make_test_summary(for_family) send_email([a.email() for a in for_family.principals], 'LibraryHippo status for ' + for_family.name + ' Family', html=self.jinja.render_template('email.html', **template_values))
def post(self): (user, family) = self.get_family() if not family: family = data.Family() send_email(['*****@*****.**'], 'New family ' + self.request.get('name') + ' registered', body=('registered to ' + str(user))) family.name = self.request.get('name') if not family.principals: family.principals = [user] family.put() self.redirect('/account')
def handle_exception(self, exception, debug_mode): error_uid = uuid.uuid4() logging.critical('Error ' + str(error_uid) + ' caught. Unable to proceed.', exc_info=True) message_body = str(self.request) for attr in ('user', 'family'): if hasattr(self.request, attr): message_body += '\n' + attr + ': ' + str(getattr(self.request, attr)) send_email(['*****@*****.**'], 'LibraryHippo Error ' + str(error_uid), body=message_body) self.template_values['error_uid'] = error_uid self.render('error.html') self.response.set_status(500)