# Path: presentation/models.py
# class Presentation(TimeStampedModel):
#     subject = models.CharField(max_length=50)
#     author = models.ForeignKey(User, on_delete=models.CASCADE, related_name='author')
#     views = models.IntegerField(default=0)
#     likes = models.IntegerField(default=0)
#     is_public = models.BooleanField(default=True)
#     tags = TaggableManager()
# 
#     like_users = models.ManyToManyField(User, related_name='like_users')
# 
#     def like_toggle(self, user):
#         is_like = self.is_user_like_presentation(user)
#         if is_like:
#             self.like_users.remove(user)
#         else:
#             self.like_users.add(user)
# 
#         result_like = not is_like
#         self.likes = self.like_users.count()
#         self.save()
#         return result_like
# 
#     def is_user_like_presentation(self, user):
#         is_like = False
#         try:
#             self.like_users.get(id=user.id)
#             is_like = True
#         except User.DoesNotExist:
#             pass
#         return is_like
# 
#     objects = PresentationManager()
# 
#     def view(self):
#         self.views += 1
#         self.save()
# 
#     def __str__(self):
#         return self.subject
# 
#     def get_absolute_url(self, *args, **kwargs):
#         return reverse('presentation:detail', kwargs={'pk': self.pk})
# 
# Path: warp/users/models.py
# class User(AbstractUser):
# 
#     # First Name and Last Name do not cover name patterns
#     # around the globe.
#     name = models.CharField(_('Name of User'), blank=True, max_length=255)
# 
#     def __str__(self):
#         return self.username
# 
#     def get_profile_image_url(self):
#         social_image = None
#         if self.socialaccount_set.all():
#             social_image = self.socialaccount_set.all()[0].get_avatar_url()
#         if social_image:
#             return social_image
#         return '/static/images/default_profile.svg'
# 
#     def get_absolute_url(self):
#         return reverse('users:detail', kwargs={'username': self.username})


from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.urlresolvers import reverse
from django.views.generic import DetailView, ListView, RedirectView, UpdateView
from presentation.models import Presentation
from .models import User
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals




class UserDetailView(LoginRequiredMixin, DetailView):
    model = User
    # These next two lines tell the view to index lookups by username
    slug_field = 'username'
    slug_url_kwarg = 'username'

    def get_context_data(self, **kwargs):
        context = super(UserDetailView, self).get_context_data(**kwargs)
        username = self.kwargs['username']
        if username == self.request.user.username:
            context['presentations'] = Presentation.objects.authored_by(username).order_by('-pk')[:9]
        else:

# Path: presentation/models.py
# class Presentation(TimeStampedModel):
#     subject = models.CharField(max_length=50)
#     author = models.ForeignKey(User, on_delete=models.CASCADE, related_name='author')
#     views = models.IntegerField(default=0)
#     likes = models.IntegerField(default=0)
#     is_public = models.BooleanField(default=True)
#     tags = TaggableManager()
# 
#     like_users = models.ManyToManyField(User, related_name='like_users')
# 
#     def like_toggle(self, user):
#         is_like = self.is_user_like_presentation(user)
#         if is_like:
#             self.like_users.remove(user)
#         else:
#             self.like_users.add(user)
# 
#         result_like = not is_like
#         self.likes = self.like_users.count()
#         self.save()
#         return result_like
# 
#     def is_user_like_presentation(self, user):
#         is_like = False
#         try:
#             self.like_users.get(id=user.id)
#             is_like = True
#         except User.DoesNotExist:
#             pass
#         return is_like
# 
#     objects = PresentationManager()
# 
#     def view(self):
#         self.views += 1
#         self.save()
# 
#     def __str__(self):
#         return self.subject
# 
#     def get_absolute_url(self, *args, **kwargs):
#         return reverse('presentation:detail', kwargs={'pk': self.pk})
# 
# Path: warp/users/models.py
# class User(AbstractUser):
# 
#     # First Name and Last Name do not cover name patterns
#     # around the globe.
#     name = models.CharField(_('Name of User'), blank=True, max_length=255)
# 
#     def __str__(self):
#         return self.username
# 
#     def get_profile_image_url(self):
#         social_image = None
#         if self.socialaccount_set.all():
#             social_image = self.socialaccount_set.all()[0].get_avatar_url()
#         if social_image:
#             return social_image
#         return '/static/images/default_profile.svg'
# 
#     def get_absolute_url(self):
#         return reverse('users:detail', kwargs={'username': self.username})


# Path: warp/users/views.py
from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.urlresolvers import reverse
from django.views.generic import DetailView, ListView, RedirectView, UpdateView
from presentation.models import Presentation
from .models import User

# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals




class UserDetailView(LoginRequiredMixin, DetailView):
    model = User
    # These next two lines tell the view to index lookups by username
    slug_field = 'username'
    slug_url_kwarg = 'username'

    def get_context_data(self, **kwargs):
        context = super(UserDetailView, self).get_context_data(**kwargs)
        username = self.kwargs['username']
        if username == self.request.user.username:
            context['presentations'] = Presentation.objects.authored_by(username).order_by('-pk')[:9]
        else:

            context['presentations'] = Presentation.objects.authored_by(username).public().order_by('-pk')[:9]