Пример #1
0
def myevents(request):
    try:
        events_matched = list()
        connected_user = App.getCurrentUser(request)
        # - 1 get Events matching with Myweesh
        for weesh in Wishes.objects(user_id=connected_user.id, is_active=True):
            for event in Events.objects(is_active=True, tags__in=weesh.tags):
                events_matched.append(event)

        # - 2 get created events by current user
        for event in Events.objects(is_active=True, user_id=connected_user.id):
            events_matched.append(event)

        context = {
            'user':
            connected_user,
            'events_matched':
            sorted(events_matched,
                   key=methodcaller('get_ref_date'),
                   reverse=True)
        }
    except DoesNotExist:
        form = UsersLoginForm()
        return render(request, 'upto/index.html', {'form': form})
    else:
        # - 3 reset notifications
        return render(request, 'upto/myevents.html', context)
Пример #2
0
def deleteEvent(request, _event_id):
    """
    Used to delete an event with an event ID
    :param _event_id:
    :return:
    """
    try:
        Events.delete(Events.objects.get(id=_event_id))
    except Wishes.DoesNotExist:
        raise Http404('Event id does not exist')
    else:
        return redirect('/upto/wishes/')
Пример #3
0
def get_favorite_tags(request, _email):
    '''
    Get favorite tags for a user
    :param request:
    :param _email:
    :return:
    '''
    try:
        connected_user = App.getCurrentUser(request)
        selected_user = Users.objects.get(user__email=_email)
        lstTags = list()
        lstEvents = Events.objects(
            Q(creator=selected_user.id)
            | Q(participants__contains=connected_user.id))
        lstWeesh = Wishes.objects(creator=selected_user.id)

        for ev in lstEvents:
            if len(ev.tags) != 0:
                lstTags.append(ev.tags[0].title.lower())
        for we in lstWeesh:
            if len(we.tags) != 0:
                lstTags.append(we.tags[0].title.lower())

        a = dict(Counter(lstTags).most_common(4))
        print json.dumps(a)
    except connected_user.DoesNotExist:
        raise Http404('Not logged')
    except selected_user.DoesNotExist:
        raise Http404('User doesnt exists')
    else:
        return Response(json.dumps(a))
Пример #4
0
def myNextEvents(request):
    try:
        connected_user = App.getCurrentUser(request)
        #TODO : Select only objects where current user is creator or participant
        lstNextEvents = Events.objects(
            user_id=connected_user.id
        )  #end_date__lte=datetime.now()) #LTE a changer an SUP
        eventssrz = EventSerializer(instance=lstNextEvents, many=True)
    except connected_user.DoesNotExist:
        raise Http404('Not logged')
    else:
        return Response(eventssrz.data)
Пример #5
0
def allEvents(request):
    '''

    :return:
    '''
    connected_user = App.getCurrentUser(request)
    if connected_user.preferences.display_events:
        AllEvents = list()
        if connected_user.preferences.selected_network == "PUBLIC":
            AllEvents = Events.objects(
                Q(title__icontains=connected_user.preferences.search_string)
            ).order_by('-creation_date')[0:4]
        if connected_user.preferences.selected_network == "friends":
            for relationship in getFriends(connected_user):
                for wish in Events.objects(
                        Q(creator=relationship.from_user.id)
                        & Q(title__icontains=connected_user.preferences.
                            search_string)).order_by('-creation_date')[0:4]:
                    AllEvents.append(wish)

        lstEvents = EventSerializer(instance=AllEvents, many=True)
        return Response(lstEvents.data)
    else:
        return None
Пример #6
0
def eventsTimeline(request):
    '''
    Get All Events for profile timeline
    :return:
    '''
    try:
        connected_user = App.getCurrentUser(request)
        lstevents = Events.objects(
            Q(creator=connected_user.id)
            | Q(participants__contains=connected_user.id))
        lstev = EventSerializer(instance=lstevents, many=True)

    except connected_user.DoesNotExist:
        raise Http404('Not logged')
    else:
        return Response(lstev.data)
Пример #7
0
    def create_event(self, **kwargs):

        if 'thumbnail' in kwargs:
            event = Events(creator=self.id,
                           title=kwargs['eventName'],
                           priv_or_pub=kwargs['priv_or_pub'],
                           start_date=kwargs['start_date'],
                           end_date=kwargs['end_date'],
                           thumbnail=kwargs['thumbnail'],
                           nbrParticipantsMax=kwargs['nbrParticipantsMax'],
                           creation_date=datetime.datetime.now(),
                           level=kwargs['level'],
                           address=kwargs['address'],
                           description=kwargs['description'])
        else:
            event = Events(creator=self.id,
                           title=kwargs['eventName'],
                           start_date=kwargs['start_date'],
                           end_date=kwargs['end_date'],
                           nbrParticipantsMax=kwargs['nbrParticipantsMax'],
                           creation_date=datetime.datetime.now(),
                           level=kwargs['level'],
                           address=kwargs['address'])

        splitTitle = kwargs['eventName'].split(' ')
        for word in splitTitle:
            if word.startswith('#'):
                tag = Tags.objects.get_or_create(title=word)
                event.tags.append(tag[0])
        event.save()
        #Connect and send message to the queue
        # Use plain credentials for authentication

        #mqueue.publish_message('coco', 'New weesh created', channel, 'amq_fanout')
        #mqueue.close(connection)

        return event