示例#1
0
    def test_filter_by_keywords_my_events(self):
        e = Event.objects.create(starts_on='2055-06-13T05:15:22.792659',
                                 ends_on='2055-06-14T05:15:22.792659',
                                 name="Play piano",
                                 location=[7000, 22965.83])

        e1 = Event.objects.create(starts_on='2055-06-13T05:15:22.792659',
                                  ends_on='2055-06-14T05:15:22.792659',
                                  name="python meetup",
                                  location=[700, 22965.83])

        Membership.objects.create(user=self.user,
                                  event=e,
                                  is_organizer=True,
                                  rsvp='yes')
        Membership.objects.create(user=self.user,
                                  event=e1,
                                  is_organizer=True,
                                  rsvp='yes')
        assign_perm('view_event', self.user, e)
        assign_perm('view_event', self.user, e1)
        FilterState.objects.create(user=self.user,
                                   min_age=18,
                                   max_age=99,
                                   keyword='python',
                                   distance=16516)
        update_index.Command().handle(interactive=False)
        events = MatchQuerySet.all_event(self.user.id,
                                         feed='my',
                                         is_filter=True)
        self.assertEqual(len(events), 1)
        self.assertEqual(events[0].name, 'python meetup')
示例#2
0
    def get_object_list(self, request):
        match = []
        if request.GET.get('filter') == 'true':
            if request.GET.get('feed') == 'my':
                feed = 'my'
            elif request.GET.get('feed') == 'all':
                feed = 'all'
            elif request.GET.get('feed') == 'connections':
                feed = 'connections'
            else:
                feed = 'all'
            fs = FilterState.objects.filter(user=request.user.id)
            attrs = [fs[0].gender, fs[0].min_age, fs[0].max_age,
                     fs[0].distance, fs[0].distance_unit,
                     fs[0].order_criteria, fs[0].keyword]
            filter_updated = '.'.join(map(str, attrs))
            filter_updated_sha = hashlib.sha1(filter_updated).hexdigest()
            cache_key = 'e_%s_%s_%s' % (feed, request.user.id,
                                        filter_updated_sha)
            cached_match = cache.get(cache_key)
            if cached_match:
                match = cached_match
            else:
                match = MatchQuerySet. \
                    all_event(request.user.id, feed=feed,
                              is_filter=True)
                cache.set('e_%s_%s_%s' % (feed, request.user.id,
                                          filter_updated_sha), match, 180)
            if fs:
                if fs[0].order_criteria == 'match_score':
                    return sorted(
                        match, key=lambda x: -x.cumulative_match_score)
                elif fs[0].order_criteria == 'event_score':
                    return sorted(match,
                                  key=lambda x: -x.recommended_event_score)
                elif fs[0].order_criteria == 'mutual_friends':
                    return sorted(
                        match, key=lambda x: -x.friend_attendees_count)
                elif fs[0].order_criteria == 'date':
                    return sorted(match, key=lambda x: x.starts_on)
        else:
            match = MatchQuerySet.all_event(request.user.id, feed='my')

        return match
示例#3
0
    def test_filter_by_recommended_event_score_my_events(self):
        e = Event.objects.create(starts_on='2055-06-13T05:15:22.792659',
                                 ends_on='2055-06-14T05:15:22.792659',
                                 description='PyCon is a conference for the '
                                 'Python community, organized by '
                                 'members of the Python community '
                                 'PyCon is for Python enthusiasts '
                                 'of all experience levels, from '
                                 'new users to core developers.',
                                 name="Python Con",
                                 location=[7000, 22965.83])

        e1 = Event.objects.create(starts_on='2055-06-13T05:15:22.792659',
                                  ends_on='2055-06-14T05:15:22.792659',
                                  name="python meetup",
                                  location=[700, 22965.83])

        Goal.objects.get_or_create(user=self.user, goal=self.subject)
        Goal.objects.get_or_create(user=self.user, goal=self.subject2)
        Membership.objects.create(user=self.user,
                                  event=e,
                                  is_organizer=True,
                                  rsvp='yes')
        Membership.objects.create(user=self.user,
                                  event=e1,
                                  is_organizer=True,
                                  rsvp='yes')
        assign_perm('view_event', self.user, e)
        assign_perm('view_event', self.user, e1)
        FilterState.objects.create(user=self.user,
                                   min_age=18,
                                   max_age=99,
                                   keyword='python',
                                   order_criteria='event_score',
                                   distance=16516)
        update_index.Command().handle(interactive=False)
        events = MatchQuerySet.all_event(self.user.id,
                                         feed='my',
                                         is_filter=True)
        self.assertEqual(len(events), 2)
        self.assertEqual(events[0].name, 'python meetup')
        self.assertEqual(events[0].recommended_event_score, 1)
        self.assertEqual(events[1].recommended_event_score, 4)
示例#4
0
 def test_my_events(self):
     self.event = Event.objects. \
         create(starts_on='2055-06-13T05:15:22.792659',
                ends_on='2055-06-14T05:15:22.792659',
                name="Play piano", location=[7000, 22965.83])
     self.event1 = Event.objects. \
         create(starts_on='2055-06-13T05:15:22.792659',
                ends_on='2055-06-14T05:15:22.792659',
                name="python meetup", location=[7000, 22965.83])
     self.membership = Membership.objects. \
         create(user=self.user, event=self.event,
                is_organizer=True, rsvp='yes')
     self.membership = Membership.objects. \
         create(user=self.user1, event=self.event1,
                is_organizer=True, rsvp='yes')
     assign_perm('view_event', self.user, self.event)
     update_index.Command().handle(interactive=False)
     events = MatchQuerySet.all_event(self.user.id, feed='my')
     self.assertEqual(len(events), 1)
     self.assertEqual(events[0].name, 'Play piano')