Beispiel #1
0
def search_participate(request, id):
    if not request.user.is_authenticated:
        return HttpResponseRedirect(reverse('user-login'))

    participate_status = cosmo_manager.can_participate()
    if participate_status == "4":
        return HttpResponseRedirect(reverse('verified-user-view'))

    context = {}
    can_participate_now = False
    if cosmo_manager.can_participate() == "1":
        can_participate_now = True

    context.update({'can_participate_now': can_participate_now})
    try:
        cosmo_user = cosmo_models.CosmoUser.objects.get(user=request.user)
        voting = cosmo_user.votingCount

        if not cosmo_manager.is_verified(cosmo_user):
            return HttpResponseRedirect(reverse('not-verified-index'))
        try:
            participate_instance = cosmo_models.Participant.objects.get(id=id)
            if not participate_instance.selected:
                messages.success(request,
                                 "Sorry. This participate is not selected.",
                                 extra_tags="0")
                return HttpResponseRedirect(reverse('verified-user-view'))
            context.update({'result': participate_instance})
            context.update({'id': id})
            context.update({'voting_left': cosmo_user.votingCount})
            other_participate = cosmo_models.Participant.objects.order_by(
                '?').filter(selected=True)[:6]
            context.update({'others': other_participate})
            context.update({'voting': voting})
            return render(request,
                          "cosmo_manager/searchResult.html",
                          context=context)
        except cosmo_models.Participant.DoesNotExist:
            messages.success(request,
                             "No participate found. Please try again.",
                             extra_tags='0')
            if not cosmo_manager.is_verified(cosmo_user):
                return HttpResponseRedirect(reverse('not-verified-index'))
            else:
                return HttpResponseRedirect(reverse('verified-user-view'))
    except cosmo_models.CosmoUser.DoesNotExist:
        messages.success(request,
                         "No participate found. Please try again.",
                         extra_tags='0')
        if not cosmo_manager.is_verified(cosmo_user):
            return HttpResponseRedirect(reverse('not-verified-index'))
        else:
            return HttpResponseRedirect(reverse('verified-user-view'))
Beispiel #2
0
def search_video(request):
    cosmo_user = cosmo_models.CosmoUser.objects.get(user=request.user)

    can_participate_now = False
    if cosmo_manager.can_participate() == "1":
        can_participate_now = True
    context = {}
    context.update({'can_participate_now': can_participate_now})

    if not cosmo_manager.is_verified(cosmo_user):
        messages.success(request,
                         "Please verify your account.",
                         extra_tags="0")
        return HttpResponseRedirect(reverse('not-verified-index'))
    if request.POST['search'] == "":
        messages.success(request,
                         "Sorry. No result found. Please try again.",
                         extra_tags="0")
        return HttpResponseRedirect(reverse('verified-user-view'))

    try:
        search_result = cosmo_models.Participant.objects.filter(
            tags__title__icontains=request.POST['search'],
            selected=True).distinct()
        if search_result:
            context.update({'search_result': search_result})
            context.update({'voting_left': cosmo_user.votingCount})
            return render(request,
                          "cosmo_manager/votingStop.html",
                          context=context)
        else:
            messages.success(request,
                             "Sorry. No result found. Please try again.",
                             extra_tags="0")
            return HttpResponseRedirect(reverse('verified-user-view'))
    except cosmo_models.Participant.DoesNotExist:
        messages.success(request,
                         "Sorry. No result found. Please try again.",
                         extra_tags="0")
        return HttpResponseRedirect(reverse('verified-user-view'))
Beispiel #3
0
def resend_code(request):
    if not request.user.is_authenticated:
        return HttpResponseRedirect(reverse('user-login'))

    try:
        cosmo_user = cosmo_models.CosmoUser.objects.get(user=request.user)
        if cosmo_manager.is_verified(cosmo_user):
            messages.success(request,
                             "You have already been verified.",
                             extra_tags="0")
            return HttpResponseRedirect(reverse('verified-user-view'))
        else:
            if cosmo_manager.can_resend_code(cosmo_user):
                suffix_verification_code = request.user.id + randint(
                    1000, 9999) + request.user.id + 2
                verification_code = random.sample(range(
                    1000, 9999), 1)[0] + suffix_verification_code

                date = datetime.now()
                update_details = {
                    'recipient_email':
                    request.user.email,
                    'email_subject':
                    'Cosmo Acoustic Challenge | Resend: Registration verification code.',
                    'email_body':
                    f"""
                        Hi { request.user.get_full_name() }, <br/><br/>You have requested for new verification code. Your new verification code is:
                        <span style="text-align:center;text-weight:bold"><h1>{verification_code}</h1></span>
                        Please copy and paste the verification code to the link: <a href='http://{request.META['HTTP_HOST']}{reverse_lazy('not-verified-index')}'>Click Here</a> <br/><br/>

                        Date Requested: {date.strftime("%Y-%m-%d %H:%M:%S")}<br/>
                        <br/>
                        Thank You,<br/>
                        Cosmo Acoustic Challenge.<br/>
                        Arun Thapa Chowk, Jhamsikhel,<br/>
                        Nepal.<br/>
                        9841360559
                        """
                }
                if resend_verification_email(update_details, cosmo_user,
                                             verification_code):
                    messages.success(
                        request,
                        "New verification code has been send to your email. Please verify. Thank you.",
                        extra_tags="1")
                else:
                    messages.success(
                        request,
                        "New verification code is unable to send. Please try again.",
                        extra_tags="0")
                return HttpResponseRedirect(reverse('not-verified-index'))
            else:
                messages.success(
                    request,
                    "You have already request for new verification code. You cannot request again for new one. Thank You",
                    extra_tags="0")
            return HttpResponseRedirect(reverse('not-verified-index'))
    except cosmo_models.CosmoUser.DoesNotExist:
        messages.success(request, "User does not exists.", extra_tags="0")
        if request.user.is_authenticated:
            logout(request)
        return HttpResponseRedirect(reverse('user-login'))
Beispiel #4
0
def like_video(request, id):
    if not request.user.is_authenticated:
        return HttpResponseRedirect(reverse('user-login'))

    participate_status = cosmo_manager.can_participate()
    if participate_status == "4":
        return HttpResponseRedirect(reverse('verified-user-view'))

    try:
        context = {}
        can_participate_now = False
        if cosmo_manager.can_participate() == "1":
            can_participate_now = True
        context.update({'can_participate_now': can_participate_now})
        try:
            cosmo_user = cosmo_models.CosmoUser.objects.get(user=request.user)
            if cosmo_user.votingCount <= 0:
                messages.success(request,
                                 "Your voting limit exceeded. Thank You.",
                                 extra_tags="0")
                return HttpResponseRedirect(reverse('verified-user-view'))

            if not cosmo_manager.is_verified(cosmo_user):
                messages.success(request,
                                 "Please verify your account.",
                                 extra_tags="0")
                return HttpResponseRedirect(reverse('not-verified-index'))
        except cosmo_models.CosmoUser.DoesNotExist:
            if request.user.is_authenticated:
                logout(request)
            messages.success(request, "Sorry. Nothing found.", extra_tags="0")
            return HttpResponseRedirect(reverse('user-login'))

        participate_instance = cosmo_models.Participant.objects.get(id=id)
        if not participate_instance:
            messages.success(request, "Contestant not found.", extra_tags="0")
            return HttpResponseRedirect(reverse('verified-user-view'))

        if not participate_instance.selected:
            messages.success(request,
                             "Sorry. This participate is not selected.",
                             extra_tags="0")
            return HttpResponseRedirect(reverse('verified-user-view'))

        else:
            participate_instance.vote = participate_instance.vote + 1
            participate_instance.save()
            cosmo_user.votingCount = cosmo_user.votingCount - 1
            cosmo_user.save()
            messages.success(request, "Thank you for voting.", extra_tags="1")
        context.update({'result': participate_instance})
        context.update({'voting_left': cosmo_user.votingCount})
        others = cosmo_models.Participant.objects.order_by('?').filter(
            selected=True)[:6]
        context.update({'others': others})
        return redirect('/home/search-participate/' + str(id), context=context)
    except cosmo_models.Participant.DoesNotExist:
        messages.success(request,
                         "Sorry. No participate found. Please try again.",
                         extra_tags="0")
        if not cosmo_manager.is_verified(cosmo_user):
            return HttpResponseRedirect(reverse('not-verified-index'))
        else:
            return HttpResponseRedirect(reverse('verified-user-view'))
Beispiel #5
0
def participate(request):
    if not request.user.is_authenticated:
        return HttpResponseRedirect(reverse('user-login'))

    context = {}
    can_participate_now = False
    if cosmo_manager.can_participate() == "1":
        can_participate_now = True
    context.update({'can_participate_now': can_participate_now})
    can_participates = cosmo_manager.can_participate()
    if can_participates == '1':
        try:
            cosmo_user = cosmo_models.CosmoUser.objects.get(user=request.user)
            if cosmo_manager.is_verified(cosmo_user):
                if can_participates == '1':
                    if request.method == "POST":
                        is_participated_user = cosmo_models.Participant.objects.filter(
                            cosmo_user=cosmo_user).exists()
                        if is_participated_user:
                            messages.success(request,
                                             "You have already participated.",
                                             extra_tags="0")
                            if cosmo_manager.is_verified(cosmo_user):
                                return HttpResponseRedirect(
                                    reverse('verified-user-view'))
                            else:
                                return HttpResponseRedirect(
                                    reverse('not-verified-index'))
                        else:
                            # form = ParticipantForm(request.POST, request.FILES)
                            error = []
                            # if request.POST.get('photo') == "":
                            #     error.append('Photo field is required.')
                            if request.POST['youtube_link'] == "":
                                error.append('Youtube link is required.')
                            if request.POST['secondary_phone'] == "":
                                error.append('Secondary Phone is required.')
                            if error:
                                context.update({'error': error})
                                # form = ParticipantForm()
                                # context.update({'form':form})
                                return render(request,
                                              "cosmo_manager/participate.html",
                                              context=context)
                            else:
                                try:
                                    cosmo_user = cosmo_models.CosmoUser.objects.get(
                                        user=request.user)
                                    contestantNumber = 'CAC2' + str(
                                        request.user.id)

                                    if not cosmo_models.Tags.objects.filter(
                                            title=request.user.first_name):
                                        tags = cosmo_models.Tags.objects.create(
                                            title=request.user.first_name)

                                    if not cosmo_models.Tags.objects.filter(
                                            title=request.user.last_name):
                                        tags2 = cosmo_models.Tags.objects.create(
                                            title=request.user.last_name)
                                    if not cosmo_models.Tags.objects.filter(
                                            title=contestantNumber):
                                        tags3 = cosmo_models.Tags.objects.create(
                                            title=contestantNumber)
                                    if not cosmo_models.Tags.objects.filter(
                                            title=request.user.get_full_name(
                                            )):
                                        cosmo_models.Tags.objects.create(
                                            title=request.user.get_full_name())

                                    participate_user = cosmo_models.Participant.objects.create(
                                        cosmo_user=cosmo_user,
                                        link=request.POST['youtube_link'],
                                        secondaryPhone=request.
                                        POST['secondary_phone'],
                                        contestantNumber=contestantNumber)
                                    for data in cosmo_models.Tags.objects.filter(
                                            Q(title=request.user.first_name)
                                            | Q(title=request.user.last_name)
                                            | Q(title=request.user.
                                                get_full_name())
                                            | Q(title=contestantNumber)):
                                        participate_user.tags.add(data)

                                    if participate_user:
                                        messages.success(
                                            request,
                                            "Congratulations. You have successfully participated in Cosmo Event. Thank You.",
                                            extra_tags="1")
                                    else:
                                        messages.success(
                                            request,
                                            "Sorry. We are unable to save the records. Please try again.",
                                            extra_tags="0")
                                except Exception as e:
                                    print(e)
                                    messages.success(
                                        request,
                                        "Sorry. There was a problem on participating. Please try again."
                                    )

                                if cosmo_manager.is_verified(cosmo_user):
                                    return HttpResponseRedirect(
                                        reverse('verified-user-view'))
                                else:
                                    return HttpResponseRedirect(
                                        reverse('not-verified-index'))
                    else:
                        return render(request,
                                      "cosmo_manager/participate.html",
                                      context=context)
                else:
                    messages.success(request,
                                     "Sorry. Participation time is finished.",
                                     extra_tags="0")
                    if cosmo_manager.is_verified(cosmo_user):
                        return HttpResponseRedirect(
                            reverse('verified-user-view'))
                    else:
                        return HttpResponseRedirect(
                            reverse('not-verified-index'))
            else:
                return HttpResponseRedirect(reverse('not-verified-index'))

        except cosmo_models.CosmoUser.DoesNotExist:
            if request.user.is_authenticated:
                logout(request)
            return HttpResponseRedirect(reverse('user-login'))
    else:
        try:
            cosmo_user = cosmo_models.CosmoUser.objects.get(user=request.user)
        except cosmo_models.CosmoUser.DoesNotExist:
            if request.user.is_authenticated:
                logout(request)
            return HttpResponseRedirect(reverse('user-login'))

        messages.success(request,
                         "Sorry. Participation time is finished.",
                         extra_tags="0")
        if cosmo_manager.is_verified(cosmo_user):
            return HttpResponseRedirect(reverse('verified-user-view'))
        else:
            return HttpResponseRedirect(reverse('not-verified-index'))