def my_team(request): if request.method == 'GET': params = {} if request.user.is_authenticated(): params['user'] = request.user params['team'] = request.user.team if not params['team'] is None: params['members'] = LkUser.objects.filter(team = params['team']).prefetch_related(Prefetch('skills', to_attr='user_skills')) params['team'].skills = params['team'].need_skills.all() params['team'].accept = params['team'].want_accept.all() params['team'].join = LkUser.objects.filter(want_join__id = params['team'].id) params['user'].is_admin = request.user.team.creater_id == request.user.id if params['team'].member_count <= 1: params['accept'] = Team.objects.filter(want_accept__id = params['user'].id) else: params['accept'] = Team.objects.filter(want_accept__id = params['user'].id) params['skill_groups'] = build_skills() timer = get_timer() params['is_time'] = timer['is_time'] params['post_time'] = timer['post_time'] return render(request, 'team_cabinet.html', params) else: return HttpResponseRedirect('/')
def search_teams(request): start = datetime.datetime.now() logger.info(start) if request.method == 'GET': params = request.GET query = Q(member_count__lte=5) & Q(is_hidden=False) if request.user.team: query = query & ~Q(id=request.user.team.id) if params.get('name'): name = params['name'].lower() query = query & Q(name__icontains = name) if params.get('member_count'): member_counts = json.loads(params['member_count']) query = query & Q(member_count__in = member_counts) if params.get('team_need', None) and params['team_need'] == 'true': query = query & Q(need_skills__id__in=map(lambda u: u.id, request.user.skills.all())) teams = Team.objects.filter(query).prefetch_related(Prefetch('need_skills', to_attr='need_s')) logger.info(list(map(lambda u: str(u.id), request.user.skills.all()))) if params.get('name'): for team in teams: team.pos = team.name.lower().find(name) teams = sorted(teams, key = lambda tt: tt.pos) offset = int(params.get('offset', 0)) limit = int(params.get('limit', 10)) teams = teams[offset : offset + limit] if request.user.is_authenticated(): want_join_set = set(request.user.want_join.all()) want_user_set = set(Team.objects.filter(want_accept__id=request.user.id)) for team in teams: team.accept = False team.join = False if team in want_join_set: team.join = True if team in want_user_set: team.accept = True logger.info("Python execution time: {}".format(datetime.datetime.now() - start)) timer = get_timer() if params.get('want_html'): return render(request, 'ajax/team.html', { 'teams': teams, 'is_time': timer['is_time'], 'post_time': timer['post_time'] }) logger.info(datetime.datetime.now() - start) return HttpResponse(json.dumps({'status': 'ok', 'teams': serializers.serialize("json", teams), 'is_time': timer['is_time'], 'post_time': timer['post_time']}), content_type='application/json')
def teams(request): if request.method == 'GET': params = {} if request.user.is_authenticated: params['user'] = request.user timer = get_timer() params['is_time'] = timer['is_time'] params['post_time'] = timer['post_time'] logger.info(params) return render(request, 'teams.html', params)
def index(request): if request.method == 'GET': params = {} if request.user.is_authenticated: params['user'] = request.user timer = get_timer() params['is_time'] = timer['is_time'] params['post_time'] = timer['post_time'] return render(request, 'index.html', params)
def team_profile(request, team_id): team_id = int(team_id) if request.method == 'GET': params = {} if request.user.is_authenticated: params['user'] = request.user try: params['team'] = Team.objects.filter(id = team_id).prefetch_related(Prefetch('need_skills', to_attr='skills'))[0] if params['team'].is_hidden: params['reason'] = "Данная команда скрыла свой профиль" return render(request, 'page_404.html', params) else: try: params['profile_user'] = LkUser.objects.get(id = params['team'].creater_id) except Exception as e: logger.error('Team with id has no owner', params['team'].id) params['team'].accept = False params['team'].join = False if request.user.is_authenticated and params['team'] in request.user.want_join.all(): params['team'].join = True if request.user.is_authenticated and request.user in params['team'].want_accept.all(): params['team'].accept = True params['members'] = LkUser.objects.filter(team = params['team']).prefetch_related(Prefetch('skills', to_attr='user_skills')) timer = get_timer() params['is_time'] = timer['is_time'] params['post_time'] = timer['post_time'] if request.GET.get('popup', None): return render(request, 'ajax/team_page.html', params) else: return render(request, 'team_profile.html', params) except Exception as e: logger.error('Team with id ' + str(id) + 'does not exist' + str(e)) params['reason'] = "Команда не существует" return render(request, 'page_404.html', params)