# Path: niuauth/models.py
# class ReputationStat(models.Model):
#     user = models.ForeignKey(User, related_name='repu_stat')
#     date = models.DateTimeField(auto_now=True, blank=False, null=False)
#     stat_type = models.IntegerField()
#     amount = models.IntegerField(blank=False, null=False)
#     total = models.IntegerField(blank=False, null=False)
#     topic_id = models.IntegerField(blank=True, null=True)
#     node_id = models.IntegerField(blank=True, null=True)


from django.conf import settings
from niuauth.models import ReputationStat

def user_reward(user, reward_type, topic_id=None, node_id=None):
    amount = settings.REP_GET_SETTING[reward_type]
    total = user.profile.reputation + amount
    stat = ReputationStat(user=user, stat_type=reward_type, amount=amount, total=total,
                          topic_id=topic_id, node_id=node_id)

# Path: niuauth/models.py
# class ReputationStat(models.Model):
#     user = models.ForeignKey(User, related_name='repu_stat')
#     date = models.DateTimeField(auto_now=True, blank=False, null=False)
#     stat_type = models.IntegerField()
#     amount = models.IntegerField(blank=False, null=False)
#     total = models.IntegerField(blank=False, null=False)
#     topic_id = models.IntegerField(blank=True, null=True)
#     node_id = models.IntegerField(blank=True, null=True)


# Path: niuauth/utils.py
from django.conf import settings
from niuauth.models import ReputationStat


def user_reward(user, reward_type, topic_id=None, node_id=None):
    amount = settings.REP_GET_SETTING[reward_type]
    total = user.profile.reputation + amount
    stat = ReputationStat(user=user, stat_type=reward_type, amount=amount, total=total,
                          topic_id=topic_id, node_id=node_id)

    stat.save()