# Path: snippet/models.py
# class Snippet(models.Model):
#     code         = models.TextField()
#     description  = models.TextField()
#     slug         = models.SlugField()
#     lexer        = models.TextField()
#     key          = models.TextField()
#     created      = models.DateTimeField(auto_now_add=True)
#     user         = models.ForeignKey(User)
#     public       = models.BooleanField()
#     tags         = TagField()
#     
#     def __unicode__(self):
#         return u'%s' %(self.description)
#     
#     def get_tags(self):
#         return Tag.objects.get_for_object(self) 
#     
#     def get_absolute_url(self):
#         return "/%s/%s/" % (self.user.username, self.slug)
#     
#     def is_favorite(self, user):
#         from snipt.favsnipt.models import FavSnipt
#         try:
#             FavSnipt.objects.get(snipt=self, user=user)
#             return 'favorited'
#         except:
#             return ''


from django.contrib.auth.models import User
from piston.handler import AnonymousBaseHandler, BaseHandler
from piston.utils import rc
from snippet.models import Snippet
from tagging.models import Tag, TaggedItem
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter
            'users_with_tag': users_tag_list
        }
        return data

class TagsHandler(BaseHandler):
    
    def read(self, request):
        tags = Tag.objects.usage_for_queryset(Snippet.objects.filter(public='1'), counts=True)
        tags_list = []
        for tag in tags:
            tags_list.append({
                'id': tag.id,
                'name': tag.name,
                'count': tag.count
            })
        data = {
            'tags': tags_list
        }
        return data

class UserHandler(BaseHandler):
    
    def read(self, request, username):
        try:
            user = User.objects.get(username=username)
        except:
            resp = rc.NOT_HERE
            resp.write(": User does not exist.")
            return resp
        

# Path: snippet/models.py
# class Snippet(models.Model):
#     code         = models.TextField()
#     description  = models.TextField()
#     slug         = models.SlugField()
#     lexer        = models.TextField()
#     key          = models.TextField()
#     created      = models.DateTimeField(auto_now_add=True)
#     user         = models.ForeignKey(User)
#     public       = models.BooleanField()
#     tags         = TagField()
#     
#     def __unicode__(self):
#         return u'%s' %(self.description)
#     
#     def get_tags(self):
#         return Tag.objects.get_for_object(self) 
#     
#     def get_absolute_url(self):
#         return "/%s/%s/" % (self.user.username, self.slug)
#     
#     def is_favorite(self, user):
#         from snipt.favsnipt.models import FavSnipt
#         try:
#             FavSnipt.objects.get(snipt=self, user=user)
#             return 'favorited'
#         except:
#             return ''


# Path: api/handlers.py
from django.contrib.auth.models import User
from piston.handler import AnonymousBaseHandler, BaseHandler
from piston.utils import rc
from snippet.models import Snippet
from tagging.models import Tag, TaggedItem
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter

            'users_with_tag': users_tag_list
        }
        return data

class TagsHandler(BaseHandler):
    
    def read(self, request):
        tags = Tag.objects.usage_for_queryset(Snippet.objects.filter(public='1'), counts=True)
        tags_list = []
        for tag in tags:
            tags_list.append({
                'id': tag.id,
                'name': tag.name,
                'count': tag.count
            })
        data = {
            'tags': tags_list
        }
        return data

class UserHandler(BaseHandler):
    
    def read(self, request, username):
        try:
            user = User.objects.get(username=username)
        except:
            resp = rc.NOT_HERE
            resp.write(": User does not exist.")
            return resp
        

        snipts = Snippet.objects.filter(user=user.id, public='1')