Пример #1
0
def clear_filmaster_recommends_cache(sender, instance, **kw):
    """
        If flat page is saved clear filmaster_recommends cache
    """
    if instance.url == FLATPAGE_FILMASTER_RECOMMENDS:
        key = cache.Key(FLATPAGE_FILMASTER_RECOMMENDS)
        cache.delete(key)
Пример #2
0
    def post(self, *args, **kw):
        key = cache.Key("questions_", self.request.unique_user)
        questions = cache.get(key)

        if "start" not in self.request.POST:
            self.check_answer(time.time())

        if not questions:
            return self.on_end_questions()

        question = questions.pop()
        if question:
            cache.delete(key) # delete cache for questions
            cache.set(key, questions) # set cache for questions-1
            key = cache.Key("answer_", self.request.unique_user)
            cache.set(key, question) # set cache for user answer

        context = self.get_context_data()
        context.update({
            'question': question or [],
            'tstamp': time.time(),
            'progress': (100-len(questions)*10),
            'answered': 10-len(questions)
        })
        return render(self.request, self.template_name, context )
Пример #3
0
def clear_filmaster_recommends_cache(sender, instance, **kw):
    """
        If flat page is saved clear filmaster_recommends cache
    """
    if instance.url == FLATPAGE_FILMASTER_RECOMMENDS:
        key = cache.Key(FLATPAGE_FILMASTER_RECOMMENDS)
        cache.delete(key)
Пример #4
0
def change_user_display_name(user):
    logger.info("check display name for user %s" % user)
    from film20.core.models import Profile
    profile = Profile.objects.get(user = user)
    logger.info("get profile: %s" % profile)
    key = cache.Key("display_name_profile", user.id)
    cache.delete(key)
    logger.info("end of username changes")
Пример #5
0
    def check_answer(self, serv_tstamp):
        question_key = cache.Key("answer_", self.request.unique_user)
        question = cache.get(question_key)

        if question:
            answer = question.get('answer', '')
            choice = int(self.request.POST.get('choice', 0))
            user_tstamp = float(self.request.POST.get('tstamp'))
            if answer == choice:
                self.count_points(user_tstamp, serv_tstamp)
        cache.delete(question_key)
Пример #6
0
def init_vue_recommendations():
    from film20.core.models import Film
    from film20.new_recommendations.rateless_alg import rec_engine

    unknown_film_ids = get_vue_film_ids(skip_cache=True)
    known_film_ids = get_known_film_ids(skip_cache=True)
    cache.delete(cache_key("similar_films"))
    cache.delete(cache_key("known_film_ids"))
    print "known_films", len(known_film_ids)
    print "vue_films", len(unknown_film_ids)
    assert unknown_film_ids and known_film_ids
    rec_engine.do_create_similarities(known_film_ids, unknown_film_ids)
Пример #7
0
def init_vue_recommendations():
    from film20.core.models import Film
    from film20.new_recommendations.rateless_alg import rec_engine

    unknown_film_ids = get_vue_film_ids(skip_cache=True)
    known_film_ids = get_known_film_ids(skip_cache=True)
    cache.delete(cache_key("similar_films"))
    cache.delete(cache_key("known_film_ids"))
    print "known_films", len(known_film_ids)
    print "vue_films", len(unknown_film_ids)
    assert unknown_film_ids and known_film_ids
    rec_engine.do_create_similarities(known_film_ids, unknown_film_ids)
Пример #8
0
    def add_points(self):
        quiz_points_key = cache.Key("points_", self.request.unique_user)
        quiz_points = cache.get(quiz_points_key)

        contest = self.get_contest()
        participant = ContestParticipation.objects.get(user=self.request.unique_user, contest=contest)

        if participant.state == ContestParticipation.STATE_TICKET:
            participant.quiz_count = quiz_points
            participant.score += quiz_points
            participant.state = ContestParticipation.STATE_QUIZ
            participant.save()
        cache.delete(quiz_points_key)
        return participant.score
Пример #9
0
    def count_points(self, user_tstamp, serv_tstamp):
        quiz_points_key = cache.Key("points_", self.request.unique_user)
        quiz_points = cache.get(quiz_points_key)
        cache.delete(quiz_points_key)

        if not quiz_points:
            quiz_points = 0

        tdelta = serv_tstamp - user_tstamp
        tdelta = int(round(tdelta))

        quiz_points += settings.FBAPP.get('points').get('seconds').get(tdelta, 0)
        cache.set(quiz_points_key, quiz_points)
        return quiz_points
Пример #10
0
    def get(self, *args, **kw):
        if self.request.session.get('skip'):
            return http.HttpResponseRedirect(reverse(rate_films))

        self.get_context_data()

        contest = self.get_contest()

        tickets = contest.tickets.all()

        fb_uid = self.user_details['id']
        prev_winners = contest.prev_winners()
        theaters = set(theater for theater, winners in prev_winners.items() if fb_uid in winners)
        theaters = [Channel.objects.get(id=id) for id in theaters]
        try:
            last_contest = Contest.objects.all().order_by('-final_date')[0]
            score_board = last_contest.score_board
        except Contest.DoesNotExist:
            last_contest = None
            score_board = None

        try:
            participant = ContestParticipation.objects.get(
                            user=self.request.unique_user,
                            contest=contest
                        )
            if participant.state < ContestParticipation.STATE_RATINGS:
                participant.score = 0
                participant.rated_count = 0
                participant.quiz_count = 0
                participant.save()
                key = cache.Key("questions_", self.request.unique_user)
                cache.delete(key)
                participant = None
        except ContestParticipation.DoesNotExist:
            participant = None

        return render(self.request, self.template_name, {
            'tickets': tickets or [],
            'contest': self.contest,
            'theaters': theaters,
            'last_contest': last_contest,
            'score_board': score_board,
            'participant': participant,
            })
Пример #11
0
def edit_location(request):
    """
    Location selection of the user profile
    """
    profile = request.user.get_profile()

    if request.method == "POST":
        form = LocationForm(request.POST, instance=profile)
        if form.is_valid():
            form.save()
            if profile.any_field_changed('latitude', 'longitude'):
                messages.add_message(request, messages.INFO, _("Your new location has been set"))
            # invalidate personalized recommendations in area cache
            cache.delete(cache.Key("top_personalized_recommendations",
                request.user))
            cache.delete(cache.Key("tv_user_recommended", request.user))
            cache.delete(cache.Key("cinema_user_recommended", request.user))
            next = request.GET.get('next')
            if next:
                return HttpResponseRedirect(next)
    else:
        form = LocationForm(instance=profile)

    template = "usersettings/edit_location.html"
    data = {
        'section': 'location',
        'form': form, 
    }
    return render(request, template, data)
Пример #12
0
def edit_location(request):
    """
    Location selection of the user profile
    """
    profile = request.user.get_profile()

    if request.method == "POST":
        form = LocationForm(request.POST, instance=profile)
        if form.is_valid():
            form.save()
            if profile.any_field_changed('latitude', 'longitude'):
                messages.add_message(request, messages.INFO,
                                     _("Your new location has been set"))
            # invalidate personalized recommendations in area cache
            cache.delete(
                cache.Key("top_personalized_recommendations", request.user))
            cache.delete(cache.Key("tv_user_recommended", request.user))
            cache.delete(cache.Key("cinema_user_recommended", request.user))
            next = request.GET.get('next')
            if next:
                return HttpResponseRedirect(next)
    else:
        form = LocationForm(instance=profile)

    template = "usersettings/edit_location.html"
    data = {
        'section': 'location',
        'form': form,
    }
    return render(request, template, data)
Пример #13
0
def tvchannels(request):
    """
    user TVChannel selection view
    """
    from forms import TVChannelsForm
    from film20.showtimes.models import TYPE_TV_CHANNEL, UserChannel

    profile = request.user.get_profile()
    user_channels = list(
        u.pk
        for u in request.user.selected_channels.filter(type=TYPE_TV_CHANNEL))

    queryset = Channel.objects.tv().filter(is_active=True)
    if profile.country:
        queryset = queryset.filter(country__code=profile.country)

    is_post = request.method == 'POST'
    form = TVChannelsForm(request.POST if is_post else None,
                          initial={'channels': user_channels})
    form.fields['channels'].choices = [(c.id, c.name) for c in queryset]
    if is_post:
        if form.is_valid():
            channels = form.cleaned_data['channels']
            UserChannel.objects.filter(
                user=request.user,
                channel__type=TYPE_TV_CHANNEL,
                channel__country__code=profile.country,
            ).delete()
            logger.info(channels)
            for c in channels:
                UserChannel(user=request.user, channel_id=c).save()
            # invalidate personalized recommendations in area cache
            cache.delete(
                cache.Key("top_personalized_recommendations", request.user))
            cache.delete(cache.Key("tv_user_recommended", request.user))
            cache.delete(cache.Key("cinema_user_recommended", request.user))

    ctx = dict(
        form=form,
        channels=list(queryset),
    )
    return render(request, "usersettings/tvchannels.html", ctx)
Пример #14
0
def tvchannels(request):
    """
    user TVChannel selection view
    """
    from forms import TVChannelsForm
    from film20.showtimes.models import TYPE_TV_CHANNEL, UserChannel

    profile = request.user.get_profile()
    user_channels = list(u.pk for u in request.user.selected_channels.filter(type=TYPE_TV_CHANNEL))

    queryset = Channel.objects.tv().filter(is_active=True)
    if profile.country:
        queryset = queryset.filter(country__code=profile.country)

    is_post = request.method == 'POST'
    form = TVChannelsForm(request.POST if is_post else None, initial={'channels':user_channels})
    form.fields['channels'].choices = [(c.id, c.name) for c in queryset]
    if is_post:
        if form.is_valid():
            channels = form.cleaned_data['channels']
            UserChannel.objects.filter(
                    user=request.user, 
                    channel__type=TYPE_TV_CHANNEL,
                    channel__country__code=profile.country,
            ).delete()
            logger.info(channels)
            for c in channels:
                UserChannel(user=request.user, channel_id=c).save()
            # invalidate personalized recommendations in area cache
            cache.delete(cache.Key("top_personalized_recommendations",
                request.user))
            cache.delete(cache.Key("tv_user_recommended", request.user))
            cache.delete(cache.Key("cinema_user_recommended", request.user))
    
    ctx = dict(
        form=form,
        channels=list(queryset),
    )
    return render(request, "usersettings/tvchannels.html", ctx)
Пример #15
0
def _compute_fast_recommendations(user, send_notice):
    from film20.recommendations.bot_helper import compute_fast_recommendations
    compute_fast_recommendations(user.id, send_notice)
    cache.delete(cache.Key("guess_score", user.id))
Пример #16
0
def invalidate_mood_cache():
    for mood in MOODS:
        cache.delete(cache_key("mood_film_ids", mood.tag))
Пример #17
0
 def post_save(cls, sender, instance, created, *args, **kw):
     cache.delete(cache.Key("unliked_recommendations", instance.user_id))
Пример #18
0
 def invalidate_cache(self):
     cache.delete(cache.Key("open_festivals"))
     cache.delete(cache.Key("festival_theaters", self))
     cache.delete(cache.Key("festival_screening_dates", self))
     cache.delete(cache.Key("festival_participants", self))
     cache.delete(cache.Key("festival_films", self))
     cache.delete(cache.Key("festival_screening_set", self))
     cache.delete(cache.Key("festival_screening_set", self, True))
     cache.delete(cache.Key("festival_screening_set", self, False))
     for date in self.get_screening_dates():
         cache.delete(cache.Key("festival_screenings", self, date))
Пример #19
0
 def post_save(cls, instance, *args, **kwargs):
     cache.delete(cache.Key('contest'))
     if instance.has_field_changed(
             'state') and instance.state == cls.STATE_CLOSED:
         instance.compute_winners()
Пример #20
0
 def post_save(cls, sender, instance, created, *args, **kw):
     cache.delete(cache.Key("unliked_recommendations", instance.user_id))
Пример #21
0
 def invalidate_cache(self):
     cache.delete(cache.Key("open_festivals"))
     cache.delete(cache.Key("festival_theaters", self))
     cache.delete(cache.Key("festival_screening_dates", self))
     cache.delete(cache.Key("festival_participants", self))
     cache.delete(cache.Key("festival_films", self))
     cache.delete(cache.Key("festival_screening_set", self))
     cache.delete(cache.Key("festival_screening_set", self, True))
     cache.delete(cache.Key("festival_screening_set", self, False))
     for date in self.get_screening_dates():
         cache.delete(cache.Key("festival_screenings", self, date))
Пример #22
0
 def _clear_baskets(cls, user):
     for tag in settings.BASKETS_TAGS_LIST:
         cache.delete(cache.Key(cache.CACHE_TAG_BASKET, user, tag))
     cache.delete(cache.Key(cache.CACHE_USER_BASKET, user))
     cache.delete(cache.Key(cache.CACHE_SPECIAL_USER_BASKET, user))
Пример #23
0
 def clear_cache( cls, sender, instance, *args, **kwargs ):
     cache.delete( cache.Key( "fragments-ld-%s" % instance.key ) )
     cache.delete( cache.Key( "fragments-set-%s" % instance.key ) )
Пример #24
0
 def _clear_baskets(self, user):
     for tag in self.BASKETS_TAGS_LIST:
         cache.delete(self.cache_key(cache.CACHE_TAG_BASKET, user, tag))
     cache.delete(self.cache_key(cache.CACHE_USER_BASKET, user))
     cache.delete(self.cache_key(cache.CACHE_SPECIAL_USER_BASKET, user))
Пример #25
0
 def clear_cache(cls, sender, instance, *args, **kwargs):
     cache.delete(cache.Key("fragments-ld-%s" % instance.key))
     cache.delete(cache.Key("fragments-set-%s" % instance.key))
Пример #26
0
 def profile_post_save(cls, sender, instance, created, *args, **kw):
     if instance.is_field_changed('country'):
         cache.delete(cache.Key("geolocation", instance.user_id))
Пример #27
0
def invalidate_mood_cache():
    for mood in MOODS:
        cache.delete(cache_key("mood_film_ids", mood.tag))
Пример #28
0
 def post_save(cls, instance, *args, **kwargs):
     cache.delete(cache.Key('contest'))
     if instance.has_field_changed('state') and instance.state == cls.STATE_CLOSED:
         instance.compute_winners()
Пример #29
0
 def post_save(cls, sender, instance, created, *args, **kw):
     cache.delete(cache.Key("open_festivals"))
     cache.delete(cache.Key("festival_theaters", instance))
     cache.delete(cache.Key("festival_screening_dates", instance))
     cache.delete(cache.Key("festival_participants", instance))
     cache.delete(cache.Key("festival_films", instance))
     cache.delete(cache.Key("festival_screening_set", instance))
     cache.delete(cache.Key("festival_screening_set", instance, True))
     cache.delete(cache.Key("festival_screening_set", instance, False))
     for date in instance.get_screening_dates():
         cache.delete(cache.Key("festival_screenings", instance, date))
Пример #30
0
 def profile_post_save(cls, sender, instance, created, *args, **kw):
     if instance.is_field_changed('country'):
         cache.delete(cache.Key("geolocation", instance.user_id))