Exemplo n.º 1
0
def deleteWish(request, _wish_id):
    """
    Used to delete wish with a wish ID
    :param request:
    :param _wish_id:
    :return:
    """
    try:
        Wishes.delete(Wishes.objects.get(id=_wish_id))
    except Wishes.DoesNotExist:
        raise Http404('Wish id does not exist')
    else:
        return redirect('/upto/wishes/')
Exemplo n.º 2
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))
Exemplo n.º 3
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)
Exemplo n.º 4
0
def createWish(request):

    try:
        _wish_title = request.POST['weesh']
        _idLevel = request.POST['idLevel']

        selectedLevel = Level.objects.get(idLevel=_idLevel)
        connected_user = App.getCurrentUser(request)
        createdWish = connected_user.create_wish(_wish_title, selectedLevel)
        wishSerializer = WishSerializer(instance=createdWish)

        #TODO : Lancer le code suivant en asynchrone
        #1 - rechercher les weeshes similaires avec Tags
        if (len(createdWish.tags) > 0):
            lstMatchingWishes = Wishes.objects(
                title__icontains=createdWish.tags[0].title)
            geoTool = geolocalisation()
            for aWeesh in lstMatchingWishes:
                if connected_user.user.email != aWeesh.creator.user.email:
                    if geoTool.getDistance(
                            connected_user.current_coordinates,
                            aWeesh.creator.current_coordinates
                    ) <= connected_user.preferences.search_distance:
                        isExisting = Notifications.objects(
                            from_user=aWeesh.creator,
                            to_user=connected_user,
                            referenced_object=aWeesh)
                        if len(isExisting) == 0:
                            notif = WeeshMatchingNotifications()
                            notif.referenced_object = aWeesh
                            notif.from_user = aWeesh.creator
                            notif.to_user = connected_user
                            notif.content = aWeesh.creator.user.username + " post a matching Weesh to : "
                            notif.save()

                    if geoTool.getDistance(
                            connected_user.current_coordinates,
                            aWeesh.creator.current_coordinates
                    ) <= aWeesh.creator.preferences.search_distance:
                        isExisting = Notifications.objects(
                            from_user=connected_user,
                            to_user=aWeesh.creator,
                            referenced_object=createdWish)
                        if len(isExisting) == 0:
                            notif = WeeshMatchingNotifications()
                            notif.referenced_object = createdWish
                            notif.from_user = connected_user
                            notif.to_user = aWeesh.creator
                            notif.content = connected_user.user.username + " post a matching Weesh to : "
                            notif.save()

    except selectedLevel.DoesNotExist:
        raise Http404('Level is not existing. Check DB')
    except connected_user.DoesNotExist:
        raise Http404('Not logged')
    else:
        return Response(wishSerializer.data)
Exemplo n.º 5
0
    def create_wish(self, _title, _level):
        """
        Method used to create a wish
        :param _title:
        :param _creation_date:
        :return: self
        """

        wish = Wishes(creator=self.id,
                      title=_title,
                      creation_date=datetime.datetime.now(),
                      level=_level)

        splitTitle = _title.split(' ')
        for word in splitTitle:
            if word.startswith('#'):
                tag = Tags.objects.get_or_create(title=word)
                wish.tags.append(tag[0])

        wish.save()

        return wish
Exemplo n.º 6
0
def allweeshes(request):
    '''
    :return:
    '''
    connected_user = App.getCurrentUser(request)
    if connected_user.preferences.display_weeshes:
        AllWishes = list()
        if connected_user.preferences.selected_network == "PUBLIC":
            AllWishes = Wishes.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 Wishes.objects(
                        Q(creator=relationship.from_user.id)
                        & Q(title__icontains=connected_user.preferences.
                            search_string)).order_by('-creation_date')[0:4]:
                    AllWishes.append(wish)

        lstWishes = WishSerializer(instance=AllWishes, many=True)
        return Response(lstWishes.data)
    else:
        return None
Exemplo n.º 7
0
def weeshTimeline(request):
    '''
    Get All Weeshes for profile timeline
    :return:
    '''
    try:
        connected_user = App.getCurrentUser(request)
        lstweesh = Wishes.objects(
            Q(creator=connected_user.id)
            | Q(weeshback__contains=connected_user.id))
        lstWishes = WishSerializer(instance=lstweesh, many=True)

    except connected_user.DoesNotExist:
        raise Http404('Not logged')
    else:
        return Response(lstWishes.data)