# Path: mineid/core/mixins.py
# class UserObjectsMixin(object):
#     def get_queryset(self):
#         return self.model.objects.filter(user=self.request.user)
# 
# Path: mineid/apps/forms.py
# class ClientForm(ClientForm):
#     def full_clean(self):
#         # Make it mutable
#         self.data = self.data.copy()
# 
#         # Adds missing http(s)://
#         self._prefix_with_http('url')
#         self._prefix_with_http('redirect_uri')
# 
#         return super(ClientForm, self).full_clean()
# 
#     def _prefix_with_http(self, field):
#         url = self.data.get(field, '')
#         if not url.startswith('http://') and not url.startswith('https://'):
#             self.data[field] = 'http://' + url


from django.core.urlresolvers import reverse_lazy
from django.shortcuts import redirect
from provider.oauth2.models import Client
from braces.views import LoginRequiredMixin, FormValidMessageMixin
from ..core.mixins import UserObjectsMixin
from .forms import ClientForm




class AppViewMixin(LoginRequiredMixin):
    pass


class AppUserObjectMixin(object):
    model = Client


class AppEditObjectMixin(object):
    success_url = reverse_lazy('app:list')


class AppUserObjectsMixin(AppUserObjectMixin, UserObjectsMixin):
    pass


class BaseAppFormMixin(AppEditObjectMixin):
    form_class = ClientForm

    def form_valid(self, form):
        form.save(self.request.user)
        self.object = form.instance

# Path: mineid/core/mixins.py
# class UserObjectsMixin(object):
#     def get_queryset(self):
#         return self.model.objects.filter(user=self.request.user)
# 
# Path: mineid/apps/forms.py
# class ClientForm(ClientForm):
#     def full_clean(self):
#         # Make it mutable
#         self.data = self.data.copy()
# 
#         # Adds missing http(s)://
#         self._prefix_with_http('url')
#         self._prefix_with_http('redirect_uri')
# 
#         return super(ClientForm, self).full_clean()
# 
#     def _prefix_with_http(self, field):
#         url = self.data.get(field, '')
#         if not url.startswith('http://') and not url.startswith('https://'):
#             self.data[field] = 'http://' + url


# Path: mineid/apps/mixins.py
from django.core.urlresolvers import reverse_lazy
from django.shortcuts import redirect
from provider.oauth2.models import Client
from braces.views import LoginRequiredMixin, FormValidMessageMixin
from ..core.mixins import UserObjectsMixin
from .forms import ClientForm





class AppViewMixin(LoginRequiredMixin):
    pass


class AppUserObjectMixin(object):
    model = Client


class AppEditObjectMixin(object):
    success_url = reverse_lazy('app:list')


class AppUserObjectsMixin(AppUserObjectMixin, UserObjectsMixin):
    pass


class BaseAppFormMixin(AppEditObjectMixin):
    form_class = ClientForm

    def form_valid(self, form):
        form.save(self.request.user)
        self.object = form.instance

        return redirect(self.get_success_url())