# Path: activity/models.py
# class Event(models.Model):
#     timestamp = models.DateTimeField(auto_now=True)
#     type = models.TextField(choices=(
#         ("chat", "Chat"), ("rpg", "RPG"), ("other", "Other"))
#     )
#     message = models.TextField()
#     user = models.ForeignKey(get_user_model())
# 
# Path: rpg/models.py
# class Title(models.Model):
#     name = models.CharField(max_length=40, unique=True, db_index=True)
# 
#     def __unicode__(self):
#         return self.name
# 
# Path: emergent/websockets.py
# class PusherWrapper(object):
#     def __init__(self):
#     def send(self, channel, event, msg):


from django.views.generic import View
from braces.views import AjaxResponseMixin, JSONResponseMixin
from django.contrib.auth import get_user_model
from activity.models import Event
from rpg.models import Title
from emergent.websockets import Pusher
from datetime import datetime
import random
        Pusher.send("activity", "my_event", msg)
        return self.render_json_response(json_dict)


class GiveCoin(JSONResponseMixin, AjaxResponseMixin, View):
    def get_ajax(self, request, *args, **kwargs):
        if self.request.user.credits:
            target_user = get_user_model().objects.get(username=kwargs['username'])
            target_user.credits += 1
            target_user.save()
            self.request.user.credits -= 1
            self.request.user.save()
            json_dict = {
                'success': True,
                'my': self.request.user.credits,
                'new': target_user.credits
            }
        else:
            json_dict = {
                'success': False,
                'reason': "No money"
            }

        return self.render_json_response(json_dict)


class BuyView(JSONResponseMixin, AjaxResponseMixin, View):
    def get_ajax(self, request, *args, **kwargs):
        if kwargs["item"] == "cheater" and self.request.user.credits >= 5:
            self.request.user.credits -= 5

# Path: activity/models.py
# class Event(models.Model):
#     timestamp = models.DateTimeField(auto_now=True)
#     type = models.TextField(choices=(
#         ("chat", "Chat"), ("rpg", "RPG"), ("other", "Other"))
#     )
#     message = models.TextField()
#     user = models.ForeignKey(get_user_model())
# 
# Path: rpg/models.py
# class Title(models.Model):
#     name = models.CharField(max_length=40, unique=True, db_index=True)
# 
#     def __unicode__(self):
#         return self.name
# 
# Path: emergent/websockets.py
# class PusherWrapper(object):
#     def __init__(self):
#     def send(self, channel, event, msg):


# Path: rpg/views.py
from django.views.generic import View
from braces.views import AjaxResponseMixin, JSONResponseMixin
from django.contrib.auth import get_user_model
from activity.models import Event
from rpg.models import Title
from emergent.websockets import Pusher
from datetime import datetime
import random

        Pusher.send("activity", "my_event", msg)
        return self.render_json_response(json_dict)


class GiveCoin(JSONResponseMixin, AjaxResponseMixin, View):
    def get_ajax(self, request, *args, **kwargs):
        if self.request.user.credits:
            target_user = get_user_model().objects.get(username=kwargs['username'])
            target_user.credits += 1
            target_user.save()
            self.request.user.credits -= 1
            self.request.user.save()
            json_dict = {
                'success': True,
                'my': self.request.user.credits,
                'new': target_user.credits
            }
        else:
            json_dict = {
                'success': False,
                'reason': "No money"
            }

        return self.render_json_response(json_dict)


class BuyView(JSONResponseMixin, AjaxResponseMixin, View):
    def get_ajax(self, request, *args, **kwargs):
        if kwargs["item"] == "cheater" and self.request.user.credits >= 5:
            self.request.user.credits -= 5

            self.request.user.titles.add(Title.objects.get(name="Cheater"))