예제 #1
0
def ranking_score(request):
    months = sorted(
        list(
            set(
                map(lambda x: x.month,
                    MonthlyScore.objects.filter(season=get_this_season())))))

    score_sum = {}
    score_info = []
    for month in months:
        infos = MonthlyScore.objects.filter(
            season=get_this_season(), month=month).order_by('-score_full')
        score_info.append(infos)

        for item in infos:
            if score_sum.has_key(item.user):
                score_sum[item.user][0] += item.score_personal
                score_sum[item.user][1] += item.score_group
                score_sum[item.user][2] += item.score_team
                score_sum[item.user][3] += item.score_full
            else:
                score_sum[item.user] = [
                    item.score_personal, item.score_group, item.score_team,
                    item.score_full
                ]

    score_sum = sorted(score_sum.items(), key=lambda x: -x[1][-1])

    return render(request, 'foradmin/ranking.html', {
        'score_info': score_info,
        'score_sum': score_sum,
    })
예제 #2
0
def check_evaluation(request, odd):
    odd = int(odd) % 2
    picture = (request.GET.get('picture', None) == 'true')
    groups = BuddyGroup.objects.filter(season=get_this_season())

    personal_events = []
    group_events = []
    for group in groups:
        if int(re.search(r'\d+', group.name).group()) % 2 == odd:
            users = map(lambda x: x.user,
                        UserGroup.objects.filter(group=group))
            personal_events += PersonalEvent.objects.filter(
                start_date__month=get_target_month(),
                season=get_this_season(),
                user__in=users).order_by('user__profile__korean_name',
                                         'start_date')
            group_events += GroupEvent.objects.filter(
                start_date__month=get_target_month(),
                group=group).order_by('start_date')

    group_infos = map(lambda x: (x, GroupAttend.objects.filter(event=x)),
                      group_events)

    return render(
        request, 'evaluation/check.html', {
            'picture': picture,
            'personal_events': personal_events,
            'group_infos': group_infos,
        })
예제 #3
0
def get_korean_matching_list():
    matching_list = Matching.objects.filter(
        season=base_queries.get_this_season()).order_by('id')
    matching_list = filter(
        lambda x: UserSeason.objects.filter(
            user=x.user, season=base_queries.get_this_season())[0].user_type in
        (UserSeason.KOREAN, UserSeason.ADMIN), matching_list)

    return matching_list
예제 #4
0
파일: queries.py 프로젝트: Corea/snubuddy
def exist_group_report(user, month):
    result = GroupReport.objects.filter(user=user,
                                        season=get_this_season(),
                                        month=month).exists()

    if month == 2 or month == 8:
        result |= GroupReport.objects.filter(user=user,
                                             season=get_this_season(),
                                             month=month + 1).exists()
    return result
예제 #5
0
파일: queries.py 프로젝트: Corea/snubuddy
def exist_team_report(team, month):
    result = TeamReport.objects.filter(team=team,
                                       season=get_this_season(),
                                       month=month).exists()

    if month == 2 or month == 8:
        result |= TeamReport.objects.filter(team=team,
                                            season=get_this_season(),
                                            month=month + 1).exists()

    return result
예제 #6
0
def full_list(request):
    season = get_this_season()
    groups = BuddyGroup.objects.filter(season=get_this_season())
    infos = []
    for group in groups:
        usergroups = UserGroup.objects.filter(group=group)
        inner_info = [[
            x,
            [[y, ApplicationForeigner.objects.get(user=y, season=season)]
             for y in get_personal_buddies_by_user(x.user)]
        ] for x in usergroups]
        infos.append([group, inner_info])

    return render(request, 'foradmin/full_list.html', {'infos': infos})
예제 #7
0
파일: views.py 프로젝트: Corea/snubuddy
def register(request):
    return redirect(list)
    form = MatchingKoreanForm(request.POST or None)
    if request.method == 'POST' and form.is_valid():
        matching_queries.delete_matching_by_user(request.user)

        matching = form.save(commit=False)
        matching.user = request.user
        matching.season = get_this_season()
        matching.save()

        languages = map(int, form.data.getlist('language[]'))
        language_levels = map(int, form.data.getlist('language_level[]'))
        for i in xrange(len(languages)):
            language = base_queries.get_language(languages[i])
            matching_language = MatchingLanguage.objects.create(
                matching=matching,
                language=language,
                level=language_levels[i])

        return redirect(view, id=matching.id)

    matching_exist = matching_queries.has_matching(request.user)

    return render(request, 'matching/register.html', {
        'form': form,
        'exists': matching_exist
    })
예제 #8
0
def is_foreigner(user):
    user_season = UserSeason.objects.filter(user=user,
                                            season=get_this_season())
    if not user_season.exists():
        return False

    return (user_season[0].user_type == UserSeason.FOREIGNER)
예제 #9
0
def is_korean(user):
    user_season = UserSeason.objects.filter(user=user,
                                            season=get_this_season())
    if not user_season.exists():
        return False

    return (user_season[0].user_type in (UserSeason.ADMIN, UserSeason.KOREAN))
예제 #10
0
def is_admin(user):
    user_season = UserSeason.objects.filter(user=user,
                                            season=get_this_season())
    if not user_season.exists():
        return False

    return (user_season[0].user_type == UserSeason.ADMIN)
예제 #11
0
def is_team_leader(user):
    userteam = UserTeam.objects.filter(user=user,
                                       team__season=get_this_season())

    if not userteam.exists():
        return False
    return userteam[0].is_leader
예제 #12
0
def is_group_subleader(user):
    usergroup = UserGroup.objects.filter(user=user,
                                         group__season=get_this_season())

    if not usergroup.exists():
        return False
    return usergroup[0].leader_type == usergroup[0].SUBLEADER
예제 #13
0
def korean_list(request):
    users = get_korean_list()  #'birth')
    teams = Team.objects.filter(season=get_this_season())
    groups = BuddyGroup.objects.filter(season=get_this_season())

    infos = []
    for user in users:
        exist = has_matching(user)
        userteam = get_userteam_by_user(user)
        usergroup = get_usergroup_by_user(user)
        infos.append([user, exist, userteam, usergroup])

    return render(request, 'foradmin/korean_list.html', {
        'infos': infos,
        'teams': teams,
        'groups': groups
    })
예제 #14
0
    def wrap(request, *args, **kwargs):
        user_season = UserSeason.objects.filter(user=request.user,
                                                season=get_this_season())
        if not user_season.exists():
            return HttpResponseRedirect('/')

        if user_season[0].user_type == UserSeason.ADMIN:
            return function(request, *args, **kwargs)
        else:
            return HttpResponseRedirect('/')
예제 #15
0
파일: queries.py 프로젝트: Corea/snubuddy
def get_korean_list(sort_option=''):
    sort_key = (lambda x: x.profile.korean_name)
    if sort_option == 'birth':
        sort_key = (lambda x: (x.profile.birth.month, x.profile.birth.day))

    users = map(
        lambda x: x.user,
        UserSeason.objects.filter(
            Q(season=get_this_season()),
            Q(user_type=UserSeason.KOREAN) | Q(user_type=UserSeason.ADMIN)))
    users = sorted(users, key=sort_key)
    return users
예제 #16
0
def add_personal_activity(request):
    form = PersonalEventForm(request.POST or None, request.FILES or None)
    if request.method == 'POST' and form.is_valid():
        event = form.save(commit=False)

        if exist_personal_report(request.user, event.start_date.month):
            return render(
                request, 'error.html',
                {'error': u'%s월 평가서를 이미 작성하셨습니다.' % event.start_date.month})

        event.user = request.user
        event.season = get_this_season()
        event.save()
        return redirect(evaluation_status)

    return render(request, 'evaluation/add_personal_activity.html', {
        'form': form,
    })
예제 #17
0
def add_group_report(request):
    if not is_group_leader(request.user) and \
            not is_group_subleader(request.user):
        return redirect(evaluation_status)

    month = get_target_month()
    group = get_buddygroup_by_user(request.user)
    if exist_group_report(request.user, month):
        return render(request, 'error.html', {'error': u'이미 작성하셨습니다.'})

    members = []
    valid = True
    for user in get_member_by_buddygroup(group):
        score1 = request.POST.get('score1_' + str(user.id), '')
        score2 = request.POST.get('score2_' + str(user.id), '')
        reason = request.POST.get('reason_' + str(user.id), u'')
        error = u''

        if request.method == 'POST' and \
                score1 not in '012345' or score2 not in '012345':
            error = u'점수를 선택해주세요.'
            valid = False
        members.append((user, score1, score2, reason, error))

    if request.method == 'POST' and valid:
        report = GroupReport.objects.create(user=request.user,
                                            group=group,
                                            season=get_this_season(),
                                            month=month)

        for user, score1, score2, reason, _ in members:
            evaluation = GroupEvaluation.objects.create(report=report,
                                                        user=user,
                                                        score1=int(score1),
                                                        score2=int(score2),
                                                        reason=reason)
            evaluation.save()

        return redirect(evaluation_status)

    return render(request, 'evaluation/add_group_report.html', {
        'month': month,
        'members': members,
    })
예제 #18
0
def add_personal_report(request):
    month = get_target_month()
    if exist_personal_report(request.user, month):
        return render(request, 'error.html', {'error': u'이미 작성하셨습니다.'})

    form = PersonalReportForm(request.POST or None)

    if request.method == 'POST' and form.is_valid():
        report = form.save(commit=False)
        report.user = request.user
        report.season = get_this_season()
        report.month = month
        report.save()
        return redirect(evaluation_status)

    return render(request, 'evaluation/add_personal_report.html', {
        'form': form,
        'month': month,
    })
예제 #19
0
파일: views.py 프로젝트: Corea/snubuddy
def register_foreigner(request, id):
    korean_matching = get_object_or_404(Matching, id=id)

    matching_count = MatchingConnection.objects.filter(
        korean_matching=korean_matching).count()
    matching_valid = (korean_matching.max_buddy_number > matching_count)
    if not matching_valid:
        return redirect(register_full)

    form = MatchingForeignerForm(request.POST or None)

    if request.method == 'POST' and form.is_valid():
        matching_queries.delete_matching_by_user(request.user)

        matching = form.save(commit=False)
        matching.user = request.user
        matching.season = get_this_season()
        matching.save()

        matching_connection = MatchingConnection.objects.create(
            korean_matching=korean_matching,
            foreign_matching=matching)

        languages = map(int, form.data.getlist('language[]'))
        language_levels = map(int, form.data.getlist('language_level[]'))
        for i in xrange(len(languages)):
            language = base_queries.get_language(languages[i])
            matching_language = MatchingLanguage.objects.create(
                matching=matching,
                language=language,
                level=language_levels[i])

        return redirect(view, id=id)

    matching_exist = matching_queries.has_matching(request.user)

    return render(request, 'matching/register_foreigner.html', {
        'matching': korean_matching,
        'form': form,
        'exists': matching_exist
    })
예제 #20
0
def add_team_report(request):
    if not is_team_leader(request.user):
        return redirect(evaluation_status)
    month = get_target_month()
    team = get_team_by_user(request.user)
    if exist_team_report(team, month):
        return render(request, 'error.html', {'error': u'이미 작성하셨습니다.'})

    members = []
    valid = True
    for user in get_member_by_team(team):
        grade = request.POST.get('grade_' + str(user.id), '')
        reason = request.POST.get('reason_' + str(user.id), u'')
        error = u''
        if request.method == 'POST' and grade not in ('0', '1', '2', '3'):
            error = u'선택해주세요.'
            valid = False
        members.append((user, grade, reason, error))

    if request.method == 'POST' and valid:
        report = TeamReport.objects.create(user=request.user,
                                           team=team,
                                           season=get_this_season(),
                                           month=month)

        for user, grade, reason, _ in members:
            evaluation = TeamEvaluation.objects.create(report=report,
                                                       user=user,
                                                       grade=int(grade),
                                                       reason=reason)
            evaluation.save()

        return redirect(evaluation_status)

    return render(request, 'evaluation/add_team_report.html', {
        'month': month,
        'members': members,
    })
예제 #21
0
def secret(request, month=None):
    picture = (request.GET.get('picture', None) == 'true')

    personal_events = PersonalEvent.objects.filter(
        season=get_this_season()).order_by('start_date',
                                           'user__profile__korean_name')

    group_events = GroupEvent.objects.filter(
        group__season=get_this_season()).order_by('start_date')
    # ).order_by('group__name', 'start_date')

    team_events = TeamEvent.objects.filter(
        team__season=get_this_season()).order_by('start_date', 'team__name')

    personal_reports = PersonalReport.objects.filter(
        season=get_this_season()).order_by('month',
                                           'user__profile__korean_name')
    team_reports = TeamReport.objects.filter(
        season=get_this_season()).order_by('month')
    group_reports = GroupReport.objects.filter(
        season=get_this_season()).order_by('month', 'group__name')

    if month:
        personal_events = personal_events.filter(start_date__month=month)
        group_events = group_events.filter(start_date__month=month)
        team_events = team_events.filter(start_date__month=month)

        personal_reports = personal_reports.filter(month=month)
        team_reports = team_reports.filter(month=month)
        group_reports = group_reports.filter(month=month)

    return render(
        request, 'foradmin/secret.html', {
            'picture': picture,
            'personal_events': personal_events,
            'group_events': group_events,
            'team_events': team_events,
            'personal_reports': personal_reports,
            'group_reports': group_reports,
            'team_reports': team_reports,
        })
예제 #22
0
def get_matching_by_user(user):
    try:
        return Matching.objects.get(user=user,
                                    season=base_queries.get_this_season())
    except:
        return None
예제 #23
0
def delete_matching_by_user(user):
    matching_list = Matching.objects.filter(
        user=user, season=base_queries.get_this_season())

    for matching in matching_list:
        delete_matching(matching)
예제 #24
0
파일: queries.py 프로젝트: Corea/snubuddy
def get_userteam_by_user(user):
    try:
        return UserTeam.objects.get(user=user, team__season=get_this_season())
    except:
        return None
예제 #25
0
파일: queries.py 프로젝트: Corea/snubuddy
def make_team_member(user, team):
    UserTeam.objects.filter(user=user, team__season=get_this_season()).delete()

    if team != 0:
        UserTeam.objects.create(user=user, team=team)
예제 #26
0
def calculate_score(request, month):
    personal_base = [0.5, 0.5, 1, 2]
    personal_count_limit = [6, 6, 3, 1]
    group_base = [0.5, 1, 2, 3, 0.5]
    group_count_limit = [6, 3, 3, 2, 1]
    if month == 2 or month == 8:
        personal_count_limit = [0, 0, 0, 0]
        group_count_limit = [0, 0, 0, 0, 1]

    users = get_korean_list()
    for user in users:
        personal_events = PersonalEvent.objects.filter(
            user=user,
            season=get_this_season(),
            start_date__month=month,
            is_confirm=True,
            is_language_exchange=False)

        temp = {}
        for event in personal_events:
            date = event.start_date
            if temp.has_key(date):
                temp[date] = max(temp[date], event.place_type)
            else:
                temp[date] = event.place_type

        personal_place_types = temp.values()
        personal_place_types += map(
            lambda x: x.place_type,
            PersonalEvent.objects.filter(user=user,
                                         season=get_this_season(),
                                         start_date__month=month,
                                         is_confirm=True,
                                         is_language_exchange=True))

        group_events = GroupAttend.objects.filter(
            user=user,
            event__group__season=get_this_season(),
            event__start_date__month=month,
            event__is_confirm=True,
            event__is_lunch=False)

        temp = {}
        for attend in group_events:
            event = attend.event
            date = event.start_date
            if temp.has_key(date):
                temp[date] = max(temp[date], event.place_type)
            else:
                temp[date] = event.place_type

        group_place_types = temp.values()
        group_place_types += map(
            lambda x: x.event.place_type,
            GroupAttend.objects.filter(user=user,
                                       event__group__season=get_this_season(),
                                       event__start_date__month=month,
                                       event__is_confirm=True,
                                       event__is_lunch=True))

        count_personals = [personal_place_types.count(x) for x in range(4)]
        tmp = copy.deepcopy(count_personals)
        tmp[2] += max(tmp[3] - personal_count_limit[3], 0)
        tmp[1] += max(tmp[2] - personal_count_limit[2], 0)
        tmp = map(min, zip(tmp, personal_count_limit))
        personal_score = sum(map(lambda (x, y): x * y, zip(personal_base,
                                                           tmp)))

        count_groups = [group_place_types.count(x) for x in range(5)]
        tmp = copy.deepcopy(count_groups)
        tmp[2] += max(tmp[3] - group_count_limit[3], 0)
        tmp[1] += max(tmp[2] - group_count_limit[2], 0)
        tmp = map(min, zip(tmp, group_count_limit))
        group_score = sum(map(lambda (x, y): x * y, zip(group_base, tmp)))

        team_score = sum(
            map(
                lambda x: x.score,
                TeamAttend.objects.filter(
                    user=user,
                    event__start_date__month=month,
                    event__team__season=get_this_season())))

        MonthlyScore.objects.filter(user=user,
                                    season=get_this_season(),
                                    month=month).delete()
        MonthlyScore.objects.create(user=user,
                                    season=get_this_season(),
                                    month=month,
                                    count_personal_0=count_personals[0],
                                    count_personal_1=count_personals[1],
                                    count_personal_2=count_personals[2],
                                    count_personal_3=count_personals[3],
                                    count_group_0=count_groups[0],
                                    count_group_1=count_groups[1],
                                    count_group_2=count_groups[2],
                                    count_group_3=count_groups[3],
                                    count_group_4=count_groups[4],
                                    score_personal=personal_score,
                                    score_group=group_score,
                                    score_team=team_score,
                                    score_full=personal_score + group_score +
                                    team_score).save()

    return redirect(evaluation_status)
예제 #27
0
파일: queries.py 프로젝트: Corea/snubuddy
def get_usergroup_by_user(user):
    try:
        return UserGroup.objects.get(user=user,
                                     group__season=get_this_season())
    except:
        return None
예제 #28
0
파일: queries.py 프로젝트: Corea/snubuddy
def make_group_member(user, group):
    UserGroup.objects.filter(user=user,
                             group__season=get_this_season()).delete()

    UserGroup.objects.create(user=user, group=group)
예제 #29
0
 def wrap(request, *args, **kwargs):
     if UserSeason.objects.filter(user=request.user,
                                  season=get_this_season()).exists():
         return function(request, *args, **kwargs)
     else:
         return HttpResponseRedirect('/')
예제 #30
0
def evaluation_status(request):
    # Events
    personal_events = PersonalEvent.objects.filter(
        user=request.user, season=get_this_season()).order_by('start_date')

    team_attends = TeamAttend.objects.filter(
        user=request.user,
        event__team__season=get_this_season()).order_by('event__start_date')

    group_attended_events = map(
        lambda x: x.event,
        GroupAttend.objects.filter(
            user=request.user,
            event__group__season=get_this_season()).order_by(
                'event__start_date'))

    attended_events = map(lambda x: ('Personal', x), list(personal_events)) + \
        map(lambda x: ('Group', x), list(group_attended_events)) + \
        map(lambda x: ('Team', x), list(team_attends))
    attended_events = sorted(attended_events,
                             key=lambda (x, y): y.start_date
                             if x != 'Team' else y.event.start_date)

    # Scores
    score_info = MonthlyScore.objects.filter(
        user=request.user, season=get_this_season()).order_by('month')
    score_sum = sum(map(lambda x: x.score_full, score_info))

    # Reports
    personal_report = PersonalReport.objects.filter(user=request.user,
                                                    season=get_this_season())
    reports = map(lambda x: ('Personal', x), personal_report)
    team_events = []
    group_events = []

    if is_team_leader(request.user):
        team = get_team_by_user(request.user)
        team_events = TeamEvent.objects.filter(
            team=team).order_by('start_date')
        team_reports = TeamReport.objects.filter(team=team,
                                                 season=get_this_season())
        reports += map(lambda x: ('Team', x), team_reports)

    if is_group_leader(request.user):
        group = get_buddygroup_by_user(request.user)
        group_events = GroupEvent.objects.filter(
            group=group).order_by('start_date')
    if is_group_leader(request.user) or is_group_subleader(request.user):
        group_reports = GroupReport.objects.filter(user=request.user,
                                                   season=get_this_season())
        reports += map(lambda x: ('Group', x), group_reports)

    reports = sorted(reports, key=lambda (x, y): (y.month, x))

    return render(
        request, 'evaluation/status.html', {
            'score_info': score_info,
            'score_sum': score_sum,
            'attended_events': attended_events,
            'personal_events': personal_events,
            'team_events': team_events,
            'group_events': group_events,
            'reports': reports,
        })