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 verified_user_view(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})
    try:
        cosmo_user = cosmo_models.CosmoUser.objects.get(user=request.user)
        if cosmo_user.verified:
            participate_status = cosmo_manager.can_participate()
            if participate_status == "1":
                participate_instance = cosmo_models.Participant.objects.none()
                participate_list = []
                try:
                    participate_instance = cosmo_models.Participant.objects.get(
                        cosmo_user=cosmo_user)
                    participate_list.append({
                        'youtube_link':
                        participate_instance.link,
                        # 'photo':participate_instance.photo.url.split('/static/')[1],
                        'vote':
                        participate_instance.vote
                    })
                except cosmo_models.Participant.DoesNotExist:
                    pass
                if participate_instance:
                    context.update({'participate': participate_list})
                return render(request,
                              "cosmo_manager/verified-view.html",
                              context=context)
            elif participate_status == "2":
                return render(request,
                              "cosmo_manager/participation-blocked.html",
                              context=context)
            elif participate_status == "3":
                participates = cosmo_manager.get_participates_for_vote()
                context.update({'participates': participates})
                voting_left = cosmo_user.votingCount
                context.update({'voting_left': voting_left})
                return render(request,
                              "cosmo_manager/votingStart.html",
                              context=context)
            elif participate_status == "4":
                participates = cosmo_manager.get_participates_for_vote()
                context.update({'participates': participates})
                top_votes = cosmo_models.Participant.objects.order_by(
                    "-vote").all()[:2]
                context.update({'votes': top_votes})

                print(top_votes)
                return render(request,
                              "cosmo_manager/votingStop.html",
                              context=context)
        else:
            return render(request, "cosmo_manager/not-verified-view.html")
    except cosmo_models.CosmoUser.DoesNotExist:
        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'))