Beispiel #1
0
def niceties_for_me():
    ret = []
    whoami = current_user().id
    two_weeks_from_now = datetime.now() - timedelta(days=14)
    valid_niceties = (Nicety.query
                      .filter(Nicety.end_date + timedelta(days=1) < datetime.now()) # show niceties one day after the end date
                      .filter(Nicety.target_id == whoami)
                      .all())
    for n in valid_niceties:
        if n.text != None:
            if n.anonymous == True:
                store = {
                    'end_date': n.end_date,
                    'anonymous': n.anonymous,
                    'text': util.decode_str(n.text),
                    'no_read': n.no_read,
                    'date_updated': n.date_updated
                }
            else:
                store = {
                    'avatar_url': cache_person_call(n.author_id)['avatar_url'],
                    'name': cache_person_call(n.author_id)['name'],
                    'author_id': n.author_id,
                    'end_date': n.end_date,
                    'anonymous': n.anonymous,
                    'text': util.decode_str(n.text),
                    'no_read': n.no_read,
                    'date_updated': n.date_updated
                }
            ret.append(store)
    return jsonify(ret)
Beispiel #2
0
def niceties_for_me():
    ret = []
    whoami = current_user().id
    valid_niceties = (Nicety.query
                      .filter(Nicety.end_date + timedelta(days=1) < datetime.now())  # show niceties one day after the end date
                      .filter(Nicety.target_id == whoami)
                      .all())
    for n in valid_niceties:
        if n.text is not None:
            if n.anonymous is True:
                store = {
                    'end_date': n.end_date,
                    'anonymous': n.anonymous,
                    'text': util.decode_str(n.text),
                    'no_read': n.no_read,
                    'date_updated': n.date_updated
                }
            else:
                store = {
                    'avatar_url': cache_person_call(n.author_id)['avatar_url'],
                    'name': cache_person_call(n.author_id)['name'],
                    'author_id': n.author_id,
                    'end_date': n.end_date,
                    'anonymous': n.anonymous,
                    'text': util.decode_str(n.text),
                    'no_read': n.no_read,
                    'date_updated': n.date_updated
                }
            ret.append(store)
    return jsonify(ret)
Beispiel #3
0
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"})
Beispiel #4
0
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"})
Beispiel #5
0
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"})
Beispiel #6
0
def niceties_from_me():
    user_id = current_user().id
    niceties = (Nicety.query.filter(Nicety.author_id == user_id).all())
    ret = [{
        'target_id': n.target_id,
        'text': util.decode_str(n.text),
        'anonymous': n.anonymous,
        'no_read': n.no_read,
        'date_updated': n.date_updated
    } for n in niceties]
    return jsonify(ret)
Beispiel #7
0
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"})
Beispiel #8
0
def niceties_from_me():
    user_id = current_user().id
    niceties = (Nicety.query
                .filter(Nicety.author_id == user_id)
                .all())
    ret = [{
        'target_id': n.target_id,
        'text': util.decode_str(n.text),
        'anonymous': n.anonymous,
        'no_read': n.no_read,
        'date_updated': n.date_updated
    } for n in niceties]
    return jsonify(ret)
Beispiel #9
0
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"})