# -*- coding: utf-8 -*-

from django.db import transaction
from django.shortcuts import render
from django_logit import logit
from django_query import get_query_value
from json_render import json_render

from account.models import UserInfo
from utils.home_photo_utils import get_home_photos


@logit
@transaction.atomic
def mini_preview(request):
    return render(request, 'page/mini_preview.html', {})


@logit
@transaction.atomic
def mini_preview2(request):
    user_id = get_query_value(request, 'user_id')

    try:
        user = UserInfo.objects.get(user_id=user_id)
    except UserInfo.DoesNotExist:
        user = None

    photos, session_photos, left = get_home_photos(request)

    return json_render(request, 'page/mini_preview2.html', {
        'session_photos': session_photos,
        'left': left,
    }, unjsondumpsdict={
        'session_photos': session_photos,
        'left': left,
        'user_id': user_id,
        'nickname': user.nickname if user else '',
    })
