# -*- coding:utf-8 -*-
from django.template import RequestContext
from django.shortcuts import render_to_response, get_object_or_404
from django.views.decorators.csrf import ensure_csrf_cookie
from django.contrib.auth.decorators import permission_required, user_passes_test
from users.user_check import admin_check
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect, HttpResponse, Http404
from django.views.decorators.csrf import csrf_exempt
from django.core.mail import EmailMultiAlternatives

from users.models import ClientGroup

import json

#@login_required(login_url='/login_site')
@ensure_csrf_cookie
def viewer(request):
	variables = {}
	return render_to_response('pages/viewer.html', RequestContext(request, variables))
	
@ensure_csrf_cookie
def loginPage(request):
    variables = {}
    return render_to_response('pages/login.html', RequestContext(request, variables))

@ensure_csrf_cookie
@user_passes_test(admin_check)
def manageProduct(request):
	clientGroupList = ClientGroup.objects.all()
	
	variables = {'clientGroupList': clientGroupList}
	return render_to_response('pages/manageProduct.html', RequestContext(request, variables))

@ensure_csrf_cookie
@user_passes_test(admin_check)
def manageFabric(request):
	clientGroupList = ClientGroup.objects.all()
	
	variables = {'clientGroupList': clientGroupList}
	return render_to_response('pages/manageFabric.html', RequestContext(request, variables))

@ensure_csrf_cookie
@user_passes_test(admin_check)
def manageUser(request):
	clientGroupList = ClientGroup.objects.all()
	
	variables = {'clientGroupList': clientGroupList}
	return render_to_response('pages/manageUser.html', RequestContext(request, variables))

@ensure_csrf_cookie
@user_passes_test(admin_check)
def manageClientGroup(request):
	variables = {}
	return render_to_response('pages/manageClientGroup.html', RequestContext(request, variables))

@ensure_csrf_cookie
@user_passes_test(admin_check)
def manageSimulation(request):
	variables = {}
	return render_to_response('pages/manageSimulation.html', RequestContext(request, variables))
	

@csrf_exempt
def sendMail(request):
    #if request.method == "POST":
        #if not request.POST['bigImage']:
         #   response = {'success': False}
          #  return HttpResponse(json.dumps(response))
        
	msg = EmailMultiAlternatives("Hi"," ",'terun707@naver.com',['terun707@naver.com','sir-sir-yet-sir@hanmail.net','light707@texclub.com'])
	msg.attach_alternative( request.POST['content'], "text/html")
	msg.send()
	response = {'success': True}
	return HttpResponse(json.dumps(response))

    
    
    