Example #1
0
 def post(self, request):
     activate_language(request.session)
     if request.POST['psw'] == request.POST['psw-repeat']:
         try:
             get_object_or_404(User, email=request.POST['email'])
             request.session['alerts'] = [{'type': 'error', 'message': _('User with this email is already exist.')}]
             return render(request, self.template_name, get_session_attributes(request))
         except Http404:
             pass
         user = User.objects.create_user(request.POST['email'],
                                         request.POST['first_name'],
                                         request.POST['last_name'],
                                         request.POST['psw'],
                                         )
         Profile.objects.create(user=user, city=request.POST['city'])
         # if not settings.DEBUG:
         #     with open(settings.BASE_DIR + '/auth_main/templates/email/email_confirm_{}.html'.format(translation.get_language())) as file:
         #         link = request.build_absolute_uri() + '/verificate/' + user.profile.verification_code
         #         send_mail('Q-ORCA email confirm', '',
         #                   settings.EMAIL_HOST_USER,
         #                   [user.email, ], fail_silently=settings.DEBUG,
         #                   html_message=file.read().replace('{link}', link))
         # else:
         user.profile.is_verificated = True
         user.profile.save()
         # request.session['alerts'] = [{'type': 'success', 'message': _('We have sent verification link to your email. Please, follow it to verificate your email. If there is no letter, please check "spam" in your email.')}]
         return redirect('/')
     request.session['alerts'] = [{'type': 'error', 'message': _('Passwords are not equal each other.')}]
     return render(request, self.template_name, get_session_attributes(request))
Example #2
0
    def get(self, request, *args, **kwargs):
        activate_language(request.session)
        opt = {}

        day = int(kwargs['day'])
        if day not in [1, 2]:
            raise Http404
        if request.user.is_authenticated and request.user.profile.role == 2:
            competition = get_object_or_404(Competition, id=kwargs['pk'])
            if competition.created_by == request.user.id or request.user.is_admin:
                users_distances, last_swim = get_swim_params(
                    int(kwargs['swim']), competition, day)
                opt['users_distances'] = users_distances
                opt['distance'] = users_distances[0].distance
                opt['swim_n'] = kwargs['swim']
                opt['day'] = _('Day {}'.format(day))
                opt['day_n'] = day
                opt['is_next_day'] = competition.count_days > day
                opt['is_prev_day'] = day > 1
                opt['is_next'] = last_swim > int(kwargs['swim'])
                opt['is_prev'] = int(kwargs['swim']) - 1 != 0
                opt['competition'] = competition
                return render(request, self.template_name,
                              dict(opt, **get_session_attributes(request)))

        raise Http404
Example #3
0
def main(request, *args, **kwargs):
    activate_language(request.session)
    competitions = Competition.getLastCompetitions()
    opt = dict()
    opt['competitions'] = competitions
    if request.user.is_authenticated:
        opt.update({
            'gender':
            _('male') if request.user.profile.gender == 1 else _('female')
        })
        request.user.profile.get_age_group()
        return render(request, 'core/index.html',
                      dict(opt, **get_session_attributes(request)))
    else:
        return render(request, 'core/index.html',
                      dict(opt, **get_session_attributes(request)))
Example #4
0
    def get(self, request, *args, **kwargs):
        activate_language(request.session)
        if 'team' in request.session:
            return redirect('/core/teams/{}'.format(
                request.session['team'].name))

        opt = {}
        return render(request, self.template_name,
                      dict(opt, **get_session_attributes(request)))
Example #5
0
 def get(self, request, *args, **kwargs):
     activate_language(request.session)
     opt = get_session_attributes(request)
     try:
         next = request.environ['QUERY_STRING'].split('=')[1]
         if next:
             request.session['next'] = next
     except:
         pass
     return render(request, self.template_name, opt)
Example #6
0
 def get(self, request, *args, **kwargs):
     activate_language(request.session)
     team = Team.objects.get(name=kwargs['name'])
     team_rel_users = TeamRelationToUser.objects.filter(team=team)
     is_coach = team_rel_users.filter(user=request.user).first().is_coach
     competitions_count = CompetitionTeam.objects.filter(team=team).count()
     opt = {
         'curr_team': team,
         'team_rel_users': team_rel_users,
         'is_coach': is_coach,
         'competitions': competitions_count,
     }
     return render(request, self.template_name,
                   dict(opt, **get_session_attributes(request)))
Example #7
0
    def get(self, request, *args, **kwargs):
        activate_language(request.session)
        if request.user.is_authenticated:
            teams_rel_user = None
            try:
                teams_rel_user = TeamRelationToUser.objects.filter(user=request.user)
            except:
                pass

            invitations = Invitations.objects.filter(to_user=request.user, is_active=True).order_by('-created_at')
            opt = {'user': request.user,
                   'teams_rel_user': teams_rel_user,
                   'invitations': invitations}
            return render(request, self.template_name, dict(opt, **get_session_attributes(request)))
        else:
            return redirect('/auth/login')
Example #8
0
    def get(self, request, *args, **kwargs):
        activate_language(request.session)
        user_list = User.objects.order_by('-created_at')
        paginator = Paginator(user_list, 20)
        page = request.GET.get('page', 1)

        try:
            users = paginator.page(page)
        except PageNotAnInteger:
            users = paginator.page(1)
        except EmptyPage:
            users = paginator.page(paginator.num_pages)

        opt = {'users': users}
        return render(request, self.template_name,
                      dict(opt, **get_session_attributes(request)))
Example #9
0
    def post(self, request):
        activate_language(request.session)
        if request.user.is_authenticated:
            if 'city' in request.POST:
                data = dict()
                for x in request.POST:
                    data[x] = request.POST[x]
                try:
                    request.user.profile.update_data(**data)
                except ValueError:
                    opt = {'error': _('Wrong date format')}
                    return render(request, self.template_name, dict(opt, **get_session_attributes(request)))

                return redirect('/auth/profile')
            else:
                request.user.profile.avatar = request.FILES['img']
                request.user.profile.save()
                return HttpResponse()
Example #10
0
    def get(self, request, *args, **kwargs):
        activate_language(request.session)
        user = get_object_or_404(User, pk=kwargs['pk'])
        if 'team' in request.session:
            team = Team.objects.get(pk=request.session['team'])
            is_teamlead = team.is_user_teamlead(request.user)
        else:
            is_teamlead = False

        try:
            user_team = TeamRelationToUser.objects.get(user=user).team.name
        except:
            user_team = False

        opt = {
            'curr_user': user,
            'is_teamlead': is_teamlead,
            'user_team': user_team
        }

        return render(request, self.template_name,
                      dict(opt, **get_session_attributes(request)))
Example #11
0
    def get(self, request, *args, **kwargs):
        activate_language(request.session)
        opt = {}

        competition = get_object_or_404(Competition, pk=kwargs['pk'])
        if request.user.is_authenticated and request.user.profile.role == 2:
            if competition.created_by == request.user.id or request.user.is_admin:
                paginator = Paginator(competition.getAllUsersDistances(), 20)
                page = request.GET.get('page', 1)

                try:
                    users_distances = paginator.page(page)
                except PageNotAnInteger:
                    users_distances = paginator.page(1)
                except EmptyPage:
                    users_distances = paginator.page(paginator.num_pages)

                opt['users_distances'] = users_distances
                opt['competition'] = competition
                return render(request, self.template_name,
                              dict(opt, **get_session_attributes(request)))

        raise Http404
Example #12
0
 def get(self, request, *args, **kwargs):
     activate_language(request.session)
     return render(request, self.template_name, get_session_attributes(request))
Example #13
0
    def get(self, request, *args, **kwargs):
        activate_language(request.session)
        competition = Competition.objects.get(pk=kwargs['pk'])

        members_count = competition.getCountUsers()
        teams_count = competition.getTeamsUsers()
        distances = competition.getDistances(1)
        distances_second = None
        if competition.count_days == 2:
            distances_second = competition.getDistances(2)

        if request.user.is_authenticated:
            can_signup = dict()
            is_registed = False

            can_signup['user'] = competition.canUserRegister(request.user)
            if 'team' in request.session:
                team = Team.objects.filter(pk=request.session['team']).first()
                can_signup['team'] = competition.canTeamRegister(
                    team, request.user)
                is_registed = CompetitionTeam.objects.filter(
                    team=team, competition=competition).exists()
            else:
                try:
                    team = TeamRelationToUser.objects.filter(
                        user=request.user).first().team
                    if team:
                        can_signup['team'] = competition.canTeamRegister(
                            team, request.user)
                        is_registed = CompetitionTeam.objects.filter(
                            team=team, competition=competition).exists()
                    else:
                        can_signup['team'] = 0
                except:
                    can_signup['team'] = 0

            if can_signup['user'] == -1:
                is_registed = True

            is_manager = competition.is_manager(request.user)

            opt = {
                'competition': competition,
                'members_count': members_count,
                'teams_count': teams_count,
                'can_signup': can_signup,
                'distances': distances,
                'types': Distance.TYPES,
                'distances_second': distances_second,
                'is_registed': is_registed,
                'is_manager': is_manager
            }
            return render(request, self.template_name,
                          dict(opt, **get_session_attributes(request)))

        return render(
            request, self.template_name, {
                'competition': competition,
                'members_count': members_count,
                'teams_count': teams_count,
                'distances': distances,
                'types': Distance.TYPES,
                'distances_second': distances_second,
            })