def get_self_info(): #self_info = rc.get('people/me').data admin = util.admin_access(current_user()) data = { 'admin': admin } return jsonify(data)
def get_niceties_to_edit(): is_rachel = util.admin_access(current_user()) nicety_text = util.encode_str(request.form.get("text")) nicety_author = request.form.get("author_id") nicety_target = request.form.get("target_id") if is_rachel == True: (Nicety.query.filter(Nicety.author_id == nicety_author).filter( Nicety.target_id == nicety_target).update({'text': nicety_text})) db.session.commit() return jsonify({'status': 'OK'}) else: return jsonify({'authorized': "false"})
def print_niceties(): ret = {} # Mapping from target_id to a list of niceties for that person is_admin = admin_access(current_user()) three_weeks_ago = datetime.now() - timedelta(days=21) three_weeks_from_now = datetime.now() + timedelta(days=21) if is_admin is True: valid_niceties = (Nicety.query.filter( Nicety.end_date > three_weeks_ago).filter( Nicety.end_date < three_weeks_from_now).order_by( Nicety.target_id).all()) last_target = None for n in valid_niceties: target = cache_person_call(n.target_id)['full_name'] if target != last_target: # ... set up the test for the next one last_target = target ret[target] = [] # initialize the dictionary if n.text is not None and n.text.isspace() is False: if n.anonymous is False: ret[target].append({ 'author_id': n.author_id, 'anon': False, 'name': cache_person_call(n.author_id)['full_name'], 'text': decode_str(n.text), }) else: ret[target].append({ 'anon': True, 'name': "An Unknown Admirer", 'text': decode_str(n.text), }) ret = OrderedDict(sorted(ret.items(), key=lambda t: t[0])) names = ret.keys() data = [] for k, v in ret.items(): # sort by name, then sort by reverse author_id data.append({ 'to': k, 'niceties': # sorted(v, key=lambda k: k['name']) sorted(sorted(v, key=lambda k: k['name']), key=lambda k: k['anon']) }) return render_template('printniceties.html', data={ 'names': names, 'niceties': data }) else: return jsonify({'authorized': "false"})
def niceties_by_sender(): ret = {} # Mapping from target_id to a list of niceties for that person is_rachel = admin_access(current_user()) two_weeks_from_now = datetime.now() + timedelta(days=14) if is_rachel == True: valid_niceties = (Nicety.query.order_by(Nicety.author_id).all()) last_author = None for n in valid_niceties: author = cache_person_call(n.author_id)['full_name'] if author != last_author: # ... set up the test for the next one last_author = author ret[author] = [] # initialize the dictionary if n.text is not None and n.text.isspace() == False: if n.anonymous == False: ret[author].append({ 'target_id': n.target_id, 'anon': False, 'name': cache_person_call(n.target_id)['full_name'], 'text': decode_str(n.text), }) else: ret[author].append({ 'anon': True, 'name': "An Unknown Admirer", 'text': decode_str(n.text), }) ret = OrderedDict(sorted(ret.items(), key=lambda t: t[0])) names = ret.keys() data = [] for k, v in ret.items(): # sort by name, then sort by reverse author_id data.append({ 'to': k, 'niceties': sorted(sorted(v, key=lambda k: k['name']), key=lambda k: k['anon']) }) return render_template('nicetiesbyusers.html', data={ 'names': names, 'niceties': data }) else: return jsonify({'authorized': "false"})
def get_niceties_to_edit(): is_rachel = util.admin_access(current_user()) nicety_text = util.encode_str(request.form.get("text")) nicety_author = request.form.get("author_id") nicety_target = request.form.get("target_id") if is_rachel == True: (Nicety.query .filter(Nicety.author_id==nicety_author) .filter(Nicety.target_id==nicety_target) .update({'text': nicety_text})) db.session.commit() return jsonify({'status': 'OK'}) else: return jsonify({'authorized': "false"})
def print_niceties(): ret = {} # Mapping from target_id to a list of niceties for that person is_rachel = admin_access(current_user()) three_weeks_ago = datetime.now() - timedelta(days=21) three_weeks_from_now = datetime.now() + timedelta(days=21) if is_rachel == True: valid_niceties = (Nicety.query .filter(Nicety.end_date > three_weeks_ago) .filter(Nicety.end_date < three_weeks_from_now) .order_by(Nicety.target_id) .all()) last_target = None for n in valid_niceties: target = cache_person_call(n.target_id)['full_name'] if target != last_target: # ... set up the test for the next one last_target = target ret[target] = [] # initialize the dictionary if n.text is not None and n.text.isspace() == False: if n.anonymous == False: ret[target].append({ 'author_id': n.author_id, 'anon': False, 'name': cache_person_call(n.author_id)['full_name'], 'text': decode_str(n.text), }) else: ret[target].append({ 'anon': True, 'name': "An Unknown Admirer", 'text': decode_str(n.text), }) ret = OrderedDict(sorted(ret.items(), key=lambda t: t[0])) names = ret.keys() data = [] for k, v in ret.items(): # sort by name, then sort by reverse author_id data.append({ 'to': k, 'niceties': #sorted(v, key=lambda k: k['name']) sorted(sorted(v, key=lambda k: k['name']), key=lambda k: k['anon']) }) return render_template('printniceties.html', data={ 'names': names, 'niceties': data }) else: return jsonify({'authorized': "false"})
def post_edited_niceties(): ret = {} # Mapping from target_id to a list of niceties for that person last_target = None is_admin = util.admin_access(current_user()) three_weeks_ago = datetime.now() - timedelta(days=21) three_weeks_from_now = datetime.now() + timedelta(days=21) if is_admin is True: valid_niceties = (Nicety.query .filter(Nicety.end_date > three_weeks_ago) .filter(Nicety.end_date < three_weeks_from_now) .order_by(Nicety.target_id) .all()) for n in valid_niceties: if n.target_id != last_target: # ... set up the test for the next one last_target = n.target_id ret[n.target_id] = [] # initialize the dictionary if n.anonymous is False: ret[n.target_id].append({ 'author_id': n.author_id, 'name': cache_person_call(n.author_id)['full_name'], 'no_read': n.no_read, 'text': util.decode_str(n.text), }) else: ret[n.target_id].append({ 'text': util.decode_str(n.text), 'no_read': n.no_read, }) return jsonify([ { 'to_name': cache_person_call(k)['full_name'], 'to_id': cache_person_call(k)['id'], 'niceties': v } for k, v in ret.items() ]) else: return jsonify({'authorized': "false"})
def post_edited_niceties(): ret = {} # Mapping from target_id to a list of niceties for that person last_target = None is_rachel = util.admin_access(current_user()) three_weeks_ago = datetime.now() - timedelta(days=21) three_weeks_from_now = datetime.now() + timedelta(days=21) if is_rachel == True: valid_niceties = (Nicety.query .filter(Nicety.end_date > three_weeks_ago) .filter(Nicety.end_date < three_weeks_from_now) .order_by(Nicety.target_id) .all()) for n in valid_niceties: if n.target_id != last_target: # ... set up the test for the next one last_target = n.target_id ret[n.target_id] = [] # initialize the dictionary if n.anonymous == False: ret[n.target_id].append({ 'author_id': n.author_id, 'name': cache_person_call(n.author_id)['full_name'], 'no_read': n.no_read, 'text': util.decode_str(n.text), }) else: ret[n.target_id].append({ 'text': util.decode_str(n.text), 'no_read': n.no_read, }) return jsonify([ { 'to_name': cache_person_call(k)['full_name'], 'to_id': cache_person_call(k)['id'], 'niceties': v } for k, v in ret.items() ]) else: return jsonify({'authorized': "false"})
def get_self_info(): admin = util.admin_access(current_user()) data = { 'admin': admin } return jsonify(data)
def get_self_info(): #self_info = rc.get('people/me').data admin = util.admin_access(current_user()) data = {'admin': admin} return jsonify(data)