def get_love(sender_username=None, recipient_username=None, limit=None): """Get all love from a particular sender or to a particular recipient. :param sender_username: If present, only return love sent from a particular user. :param recipient_username: If present, only return love sent to a particular user. :param limit: If present, only return this many items. """ sender_username = logic.alias.name_for_alias(sender_username) recipient_username = logic.alias.name_for_alias(recipient_username) if not (sender_username or recipient_username): raise TaintedLove( 'Not gonna give you all the love in the world. Sorry.') if sender_username == recipient_username: raise TaintedLove('Who sends love to themselves? Honestly?') love_query = ( Love.query().filter(Love.secret == False) # noqa .order(-Love.timestamp)) if sender_username: sender_key = Employee.get_key_for_username(sender_username) love_query = love_query.filter(Love.sender_key == sender_key) if recipient_username: recipient_key = Employee.get_key_for_username(recipient_username) love_query = love_query.filter(Love.recipient_key == recipient_key) if limit: return love_query.fetch_async(limit) else: return love_query.fetch_async()
def add_recipient(hash_key, recipient): loveLink = LoveLink.query(LoveLink.hash_key == hash_key).get() if (loveLink is None): raise NoSuchLoveLink("Couldn't Love Link with id {}".format(hash_key)) # check that user exists, get_key_for_username throws an exception if not recipient_username = logic.alias.name_for_alias(recipient) Employee.get_key_for_username(recipient_username) loveLink.recipient_list += ', ' + recipient loveLink.put()
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 save_alias(alias, username): alias = Alias( name=alias, owner_key=Employee.get_key_for_username(username), ) alias.put() return alias
def create_alias_with_employee_username( name='jda', username='******', ): alias = Alias( name=name, owner_key=Employee.get_key_for_username(username), ) alias.put() return alias
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 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), )