def send_loves(recipients, message, sender_username=None, secret=False): if get_toggle_state(LOVE_SENDING_ENABLED) is False: raise TaintedLove( 'Sorry, sending love is temporarily disabled. Please try again in a few minutes.' ) recipient_keys, unique_recipients = validate_love_recipients(recipients) if sender_username is None: sender_username = Employee.get_current_employee().username sender_username = logic.alias.name_for_alias(sender_username) sender_key = Employee.query( Employee.username == sender_username, Employee.terminated == False, ).get(keys_only=True) # noqa if sender_key is None: raise TaintedLove( u'Sorry, {} is not a valid user.'.format(sender_username)) # Only raise an error if the only recipient is the sender. if sender_username in unique_recipients: unique_recipients.remove(sender_username) if len(unique_recipients) == 0: raise TaintedLove(u'You can love yourself, but not on {}!'.format( config.APP_NAME)) for recipient_key in recipient_keys: _send_love(recipient_key, message, sender_key, secret) return unique_recipients
def love_link(link_id): try: loveLink = logic.love_link.get_love_link(link_id) recipients_str = loveLink.recipient_list message = loveLink.message recipients = sanitize_recipients(recipients_str) loved = [ Employee.get_key_for_username(recipient).get() for recipient in recipients ] return render_template( 'love_link.html', current_time=datetime.utcnow(), current_user=Employee.get_current_employee(), recipients=recipients_str, message=message, loved=loved, link_id=link_id, ) except NoSuchLoveLink: flash('Sorry, that link ({}) is no longer valid.'.format(link_id), 'error') return redirect(url_for('home'))
def home(): recipients = request.args.get('recipients', request.args.get('recipient')) message = request.args.get('message') return render_template( 'home.html', current_time=datetime.utcnow(), current_user=Employee.get_current_employee(), recipients=recipients, message=message, )
def create_from_dict(cls, d, persist=True): new_subscription = cls() new_subscription.owner_key = Employee.get_current_employee().key new_subscription.request_url = d['request_url'] new_subscription.active = d['active'] new_subscription.event = d['event'] new_subscription.secret = d['secret'] if persist is True: new_subscription.put() return new_subscription
def me(): current_employee = Employee.get_current_employee() sent_love = logic.love.recent_sent_love(current_employee.key, limit=20) received_love = logic.love.recent_received_love(current_employee.key, limit=20) return render_template('me.html', current_time=datetime.utcnow(), current_user=current_employee, sent_loves=sent_love.get_result(), received_loves=received_love.get_result())
def home(): link_id = request.args.get('link_id', None) recipients = request.args.get('recipients', request.args.get('recipient')) message = request.args.get('message') return render_template('home.html', current_time=datetime.utcnow(), current_user=Employee.get_current_employee(), recipients=recipients, message=message, url='{0}l/{1}'.format(config.APP_BASE_URL, link_id) if link_id else None)
def me_or_explore(user): current_employee = Employee.get_current_employee() username = logic.alias.name_for_alias(user.lower().strip()) try: user_key = Employee.get_key_for_username(username) except NoSuchEmployee: abort(404) if current_employee.key == user_key: return redirect(url_for('me')) else: return redirect(url_for('explore', user=username))
def send_loves(recipients, message, sender_username=None, secret=False): if get_toggle_state(LOVE_SENDING_ENABLED) is False: raise TaintedLove( 'Sorry, sending love is temporarily disabled. Please try again in a few minutes.' ) if sender_username is None: sender_username = Employee.get_current_employee().username sender_username = logic.alias.name_for_alias(sender_username) sender_key = Employee.query( Employee.username == sender_username, Employee.terminated == False, ).get(keys_only=True) # noqa if sender_key is None: raise TaintedLove( u'Sorry, {} is not a valid user.'.format(sender_username)) unique_recipients = set( [logic.alias.name_for_alias(name) for name in recipients]) if len(recipients) != len(unique_recipients): raise TaintedLove( u'Sorry, you are trying to send love to a user multiple times.') # Only raise an error if the only recipient is the sender. if sender_username in unique_recipients: unique_recipients.remove(sender_username) if len(unique_recipients) == 0: raise TaintedLove(u'You can love yourself, but not on {}!'.format( config.APP_NAME)) # validate all recipients before carrying out any Love transactions recipient_keys = [] for recipient_username in unique_recipients: recipient_key = Employee.query(Employee.username == recipient_username, Employee.terminated == False).get( keys_only=True) # noqa if recipient_key is None: raise TaintedLove( u'Sorry, {} is not a valid user.'.format(recipient_username)) else: recipient_keys += [recipient_key] for recipient_key in recipient_keys: _send_love(recipient_key, message, sender_key, secret) return unique_recipients
def sent(): link_id = request.args.get('link_id', None) recipients_str = request.args.get('recipients', None) message = request.args.get('message', None) if not link_id or not recipients_str or not message: return redirect(url_for('home')) recipients = sanitize_recipients(recipients_str) loved = [ Employee.get_key_for_username(recipient).get() for recipient in recipients ] return render_template( 'sent.html', current_time=datetime.utcnow(), current_user=Employee.get_current_employee(), message=message, loved=loved, url='{0}l/{1}'.format(config.APP_BASE_URL, link_id), )