Code Monkey home page Code Monkey logo

Comments (5)

stephenmcd avatar stephenmcd commented on June 17, 2024

I can't reproduce this at all.

from drum.

rayonx avatar rayonx commented on June 17, 2024

You can only do it on others' posts. Not your own posts.

from drum.

stephenmcd avatar stephenmcd commented on June 17, 2024

Yes I tried that - can you try and look into it further and determine what the cause is? That will better reveal whether there actually is a bug or not.

from drum.

rayonx avatar rayonx commented on June 17, 2024

Forgive me for I am still a novice in using Django, Mezzanine and AJAX. But I am trying hard to figure out the problem. My guess is this line of code only caters to stop the OP from bumping up their own karma score ?

if rating.user != content_object.user:

@receiver(post_save, sender=Rating)
def karma(sender, **kwargs):
    """
    Each time a rating is saved, check its value and modify the
    profile karma for the related object's user accordingly.
    Since ratings are either +1/-1, if a rating is being edited,
    we can assume that the existing rating is in the other direction,
    so we multiply the karma modifier by 2.
    """
    rating = kwargs["instance"]
    value = int(rating.value)
    if not kwargs["created"]:
        value *= 2
    content_object = rating.content_object
    if rating.user != content_object.user:
        queryset = Profile.objects.filter(user=content_object.user)
        queryset.update(karma=models.F("karma") + value)

from drum.

stephenmcd avatar stephenmcd commented on June 17, 2024

I'm sorry I misread your original message as allowing the voting score to change - you're right the karma changes multiple times when it shouldn't.

Thanks

from drum.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.