Ejemplo n.º 1
0
def follow(request, ajax=None):
    if request.method == "POST":
        try:
            user_id = int(request.POST.get("user_id"))
            user_to_follow = get_object_or_404(User, id=user_id)
            follow_val = int(request.POST.get("follow_val"))
            next = str(request.POST.get("next"))
            if follow_val == Followers.UNKNOWN:
                request.user.followers.remove(user_to_follow)
            if follow_val == Followers.FOLLOWING:
                request.user.followers.follow(user_to_follow)
            if ajax=="json":
                context = {
                        'success': True,
                        'data': request.user.id,
                    }
                logger.debug("Sending ajax response.")
                return json_return(context)
            else:
                return HttpResponseRedirect(next)
        except:
            if ajax=="json":
                return json_error()
            else:
                raise Http404
Ejemplo n.º 2
0
def show_game(request, contest_permalink=None, game_permalink=None, ajax=None):
    """
        Simple view that show a single game with options to
                vote for the characters
    """

    the_contest = None
    the_game_vote = None
    contest_helper = ContestHelper()

    if request.POST:
        if (not request.user.is_authenticated()):
            if ajax==None:
                return HttpResponseRedirect(full_url('LOGIN') + '?next=%s' % request.path)
            elif ajax=='json':
                return json_error("LOGIN")
        voting_form = VotingForm(request.POST)
        if voting_form is not None:
            logger.debug("Voting form submitted.")
            if voting_form.is_valid():
                logger.debug("Voting form valid.")
                contest_helper.vote(voting_form.the_game, voting_form.the_character, request.user)
                if ajax == "json":
                    context = {
                            'success': True,
                            'data': request.user.id,
                        }
                    logger.debug("Sending ajax response.")
                    return json_return(context)
            else:
                logger.debug("Voting form invalid.")
        else:
            logger.debug("Voting form not submitted.")

    try:
        if contest_permalink is None:
            the_contest = contest_helper.get_current_contest()
        else:
            the_contest = contest_helper.get_contest_by_permalink(contest_permalink)

        if game_permalink is None:
            the_game = contest_helper.get_game_for_date(the_contest, datetime.today())
        else:
            the_game = contest_helper.get_game_by_permalink(game_permalink)
        if request.user.is_authenticated():
            the_game_vote = contest_helper.get_vote_for_game(the_game, request.user)
        votes_for_character1 = contest_helper.get_votes_for_character_in_game(the_game, the_game.character1)
        votes_for_character2 = contest_helper.get_votes_for_character_in_game(the_game, the_game.character2)
        if the_game_vote is None:
            voting_form1 = contest_helper.prepare_voting_form1(the_game)
            voting_form2 = contest_helper.prepare_voting_form2(the_game)
        else:
            # no need for forms if already voted
            voting_form1 = None
            voting_form2 = None
    except NoOpenContestException, e:
        raise Http404
Ejemplo n.º 3
0
def regional_info_args(request, town, region):

    from film20.utils.slughifi import slughifi
    if town is not None:
        slug_town = slughifi(town)
    else:
        slug_town = None
    if region is not None:
        slug_region = slughifi(region)
    else:
        slug_region = None

    # try to retrieve from cache
    regional_info_contents = get_cache(CACHE_REGIONAL_INFO,
                                       "%s_%s" % (slug_town, slug_region))
    #    regional_info_contents = None

    if regional_info_contents == None:
        regional_info_object = None
        try:
            regional_info_object = RegionalInfo.objects.get(
                Q(town=town) | Q(region=region))
        except:
            try:
                logger.info("No regional info for town %s and region %s" %
                            (town, region))
                regional_info_object = RegionalInfo.objects.get(town=town,
                                                                region="")
            except:
                try:
                    logger.info("No regional info for town %s" % (town))
                    regional_info_object = RegionalInfo.objects.get(
                        region=region, town="")
                except:
                    logger.info("No regional info for region %s" % (region))

        if regional_info_object == None:
            regional_info_contents = "NONE"
        else:
            regional_info_contents = regional_info_object.contents

        # store in cache
        set_cache(CACHE_REGIONAL_INFO, "%s_%s" % (slug_town, slug_region),
                  regional_info_contents)

    data = {
        'town': town,
        'region': region,
        'contents': regional_info_contents,
    }

    return json_return(data)
Ejemplo n.º 4
0
def regional_info_args(request, town, region):
	
    from film20.utils.slughifi import slughifi
    if town is not None:
        slug_town = slughifi(town)
    else: 
        slug_town = None
    if region is not None:
        slug_region = slughifi(region)
    else: 
        slug_region = None

    # try to retrieve from cache
    regional_info_contents = get_cache(CACHE_REGIONAL_INFO, "%s_%s" % (slug_town, slug_region))
#    regional_info_contents = None

    if regional_info_contents == None:
        regional_info_object = None
        try:    
            regional_info_object = RegionalInfo.objects.get(Q(town=town) | Q(region=region))
        except:
            try:
                logger.info("No regional info for town %s and region %s" % ( town, region ))
                regional_info_object = RegionalInfo.objects.get(town=town, region="")
            except:
                try:
                    logger.info("No regional info for town %s" % ( town ))
                    regional_info_object = RegionalInfo.objects.get(region=region, town="")
                except:
                    logger.info("No regional info for region %s" % ( region ))
 
        if regional_info_object == None:
            regional_info_contents = "NONE"
        else:
            regional_info_contents = regional_info_object.contents
 
        # store in cache
        set_cache(CACHE_REGIONAL_INFO, "%s_%s" % (slug_town, slug_region), regional_info_contents)
        
    data = {
            'town': town,
            'region': region,
            'contents': regional_info_contents,
        }
    
    return json_return(data)