Exemple #1
0
def find_history(request):
    user = request.__user__
    # 读取年份、月份
    year = int(request.GET['year'])
    month = int(request.GET['month'])
    # 计算每日是周几
    firstDayWDay, monthDays = calendar.monthrange(year, month)
    everyDayData = {}
    for day in range(monthDays):
        wday = (firstDayWDay + day) % 7
        everyDayData[day] = {}
        everyDayData[day]['wday'] = wday2weekday(wday)
        # 调取打卡记录
        everyDayData[day]['status'] = yield from check_status(
            year, month, day + 1, user.name)
        # 调取关注的好友
        friends = yield from Relation.findAll('active_user_name=?',
                                              [user.name])
        everyDayData[day]['friends'] = {}
        for friend in friends:
            friend.status = yield from check_status(year, month, day + 1,
                                                    friend.passive_user_name)
            everyDayData[day]['friends'][
                '%s' % friend.passive_user_name] = friend.status
    # 返回
    return {
        '__template__': 'history.html',
        'username': user.name,
        'year': year,
        'month': month,
        'monthDays': monthDays,
        'everyDayData': everyDayData
    }
Exemple #2
0
def rm_following(request):
    user = request.__user__
    following_name = request.GET['following_name']
    relations = yield from Relation.findAll('active_user_name=?', [user.name])
    for relation in relations:
        if relation.passive_user_name == following_name:
            yield from relation.remove()
    return web.HTTPFound('/group')
Exemple #3
0
def add_following(request):
    user = request.__user__
    add_following = request.POST['add']
    new_following = yield from User.findAll('name=?', [add_following])
    result = None
    if len(new_following) == 1:
        following_user = new_following[0]
        relations = yield from Relation.findAll('active_user_name=?',
                                                [user.name])
        if len(relations) >= 1:
            for relation in relations:
                if relation.passive_user_name == following_user.name:
                    result = 'already following'
            if result != 'already following':
                r1 = Relation(active_user_id=user.id,
                              active_user_name=user.name,
                              passive_user_id=following_user.id,
                              passive_user_name=following_user.name)
                yield from r1.save()
        else:
            r1 = Relation(active_user_id=user.id,
                          active_user_name=user.name,
                          passive_user_id=following_user.id,
                          passive_user_name=following_user.name)
            yield from r1.save()
    else:
        result = 'User Not Found'
    # 重新载入此页
    following = yield from Relation.findAll('active_user_name=?', [user.name])
    noFollowing = False
    if type(following) == type(None):
        noFollowing = True
    follower = yield from Relation.findAll('passive_user_name=?', [user.name])
    noFollower = False
    if type(follower) == type(None):
        noFollower = True
    return {
        '__template__': 'group.html',
        'username': user.name,
        'following': following,
        'follower': follower,
        'noFollowing': noFollowing,
        'noFollower': noFollower,
        'result': result
    }
Exemple #4
0
def group(request):
    user = request.__user__
    name = user.name
    following = yield from Relation.findAll('active_user_name=?', [name])
    noFollowing = False
    if type(following) == type(None):
        noFollowing = True
    follower = yield from Relation.findAll('passive_user_name=?', [name])
    noFollower = False
    if type(follower) == type(None):
        noFollower = True
    return {
        '__template__': 'group.html',
        'username': name,
        'following': following,
        'follower': follower,
        'noFollowing': noFollowing,
        'noFollower': noFollower
    }
Exemple #5
0
def find_history_journal(request):
    # 查询日的信息
    user = request.__user__
    name = user.name
    year = int(request.GET['year'])
    month = int(request.GET['month'])
    day = int(request.GET['day'])
    weekday = wday2weekday(dt.date(year, month, day).weekday())
    r_dict = {
        '__template__': 'history_journal.html',
        'username': user.name,
        'year': year,
        'month': month,
        'day': day,
        'weekday': weekday,
    }
    # 读取朋友列表、朋友的打卡记录与日志
    friends = yield from Relation.findAll('active_user_name=?', [name])
    for friend in friends:
        status = yield from check_status(year, month, day,
                                         friend.passive_user_name)
        journal = yield from find_journal_data(year, month, day,
                                               friend.passive_user_name)
        content = None
        if not type(journal) == type(None):
            content = journal.content
        friend.status = status
        friend.journal = content
    r_dict['friends'] = friends
    # 你至己的打卡信息与日志
    status = yield from check_status(year, month, day, name)
    journal = yield from find_journal_data(year, month, day, name)
    content = None
    if not type(journal) == type(None):
        content = journal.content
    r_dict['status'] = status
    r_dict['journal'] = content
    return r_dict
Exemple #6
0
def index(request):
    if request.__user__ is None:
        return web.HTTPFound('/signin')
    user = request.__user__
    name = user.name
    todayTime = time.localtime()
    year = todayTime.tm_year
    month = todayTime.tm_mon
    day = todayTime.tm_mday
    weekday = wday2weekday(todayTime.tm_wday)
    r_dict = {
        '__template__': 'index.html',
        'username': name,
        'year': year,
        'month': month,
        'day': day,
        'weekday': weekday
    }
    friends = yield from Relation.findAll('active_user_name=?', [name])
    for friend in friends:
        status = yield from check_status(year, month, day,
                                         friend.passive_user_name)
        journal = yield from find_journal_data(year, month, day,
                                               friend.passive_user_name)
        content = None
        if not type(journal) == type(None):
            content = journal.content
        friend.status = status
        friend.journal = content
    r_dict['friends'] = friends
    status = yield from check_status(year, month, day, name)
    journal = yield from find_journal_data(year, month, day, name)
    content = None
    if not type(journal) == type(None):
        content = journal.content
    r_dict['status'] = status
    r_dict['journal'] = content
    return r_dict