suggestions/views.py
def update_suggestions_dictionary(request, object):
    """
    Updates the suggestions' dictionary for an object upon visiting its page
    """
    if request.user.is_authenticated():
        user = request.user
        content_type = ContentType.objects.get_for_model(type(object))
        try:
            # Check if the user has visited this page before
            ObjectView.objects.get(
                user=user, object_id=object.id, content_type=content_type)
        except:
            ObjectView.objects.create(user=user, content_object=object)
        # Get a list of all the objects a user has visited
        viewed = ObjectView.objects.filter(user=user)

    else:
        update_dict_for_guests(request, object, content_type)
        return

    if viewed:
        for obj in viewed:
            if content_type == obj.content_type:
                if not exists_in_dictionary(request, object,
                                            content_type,
                                            obj, True):
                    # Create an entry if it's non existent
                    if object.id != obj.object_id:
                        ObjectViewDictionary.objects.create(
                            current_object=object,
                            visited_before_object=obj.content_object)
                        if not exists_in_dictionary(request, obj,
                                                    obj.content_type,
                                                    object, False):
                            ObjectViewDictionary.objects.create(
                                current_object=obj.content_object,
                                visited_before_object=object)
    return
def update_suggestions_dictionary(request, object):
    if request.user.is_authenticated():
        user = request.user
        content_type = ContentType.objects.get_for_model(type(object))
        try:
            # Check if the user has visited this page before
            ObjectView.objects.get(
                user=user, object_id=object.id, content_type=content_type)
        except:
            ObjectView.objects.create(user=user, content_object=object)
        # Get a list of all the objects a user has visited
        viewed = ObjectView.objects.filter(user=user)

    else:
        update_dict_for_guests(request, object, content_type)
        return

    if viewed:
        for obj in viewed:
            if content_type == obj.content_type:
                if not exists_in_dictionary(request, object,
                                            content_type,
                                            obj, True):
                    # Create an entry if it's non existent
                    if object.id != obj.object_id:
                        ObjectViewDictionary.objects.create(
                            current_object=object,
                            visited_before_object=obj.content_object)
                        if not exists_in_dictionary(request, obj,
                                                    obj.content_type,
                                                    object, False):
                            ObjectViewDictionary.objects.create(
                                current_object=obj.content_object,
                                visited_before_object=object)
    return
def update_suggestions_dictionary ( request , object ) : if request . user . is_authenticated ( ) : user = request . user content_type = ContentType . objects . get_for_model ( type ( object ) ) try : # Check if the user has visited this page before ObjectView . objects . get ( user = user , object_id = object . id , content_type = content_type ) except : ObjectView . objects . create ( user = user , content_object = object ) # Get a list of all the objects a user has visited viewed = ObjectView . objects . filter ( user = user ) else : update_dict_for_guests ( request , object , content_type ) return if viewed : for obj in viewed : if content_type == obj . content_type : if not exists_in_dictionary ( request , object , content_type , obj , True ) : # Create an entry if it's non existent if object . id != obj . object_id : ObjectViewDictionary . objects . create ( current_object = object , visited_before_object = obj . content_object ) if not exists_in_dictionary ( request , obj , obj . content_type , object , False ) : ObjectViewDictionary . objects . create ( current_object = obj . content_object , visited_before_object = object ) return
Updates the suggestions' dictionary for an object upon visiting its page
Updates the suggestions dictionary for an object upon visiting its page