#from django.contrib import messages
from django.core import serializers
from django.http import HttpResponseRedirect, HttpResponse, JsonResponse
from django.shortcuts import render, get_object_or_404
#from django.urls import reverse
#from django.utils.translation import gettext as _

#from lazysignup.decorators import allow_lazy_user
from account.decorators import login_required

from procat2.models import Catalog


@login_required
def cataloglist(request):
    return render(request, 'cataloglist/cataloglist.html')


@login_required
def my_catalogs(request):
    cats = Catalog.objects.filter(owner=request.user).order_by('-updated')
    data = [c.summary() for c in cats]
    # from time import sleep
    # sleep(5)
    return JsonResponse({'catalogs': data})


@login_required
def public_catalogs(request):
    cats = Catalog.objects.filter(public=True).order_by('-updated')
    data = [c.summary() for c in cats]
    return JsonResponse({'catalogs': data})
