# Create your views here.
from django.shortcuts import render_to_response
import Image
import sys
from django.http import HttpResponse
from django.template import RequestContext
from editor.models import Article, ArticleTheme
from django.contrib.auth.decorators import login_required

def home(request):
  context = RequestContext(request, {})
  return render_to_response("main/home.html", context)

def contact(request):
  context = RequestContext(request, {})
  return render_to_response("main/contact.html", context)

def archive(request):
  context = RequestContext(request, {})
  return render_to_response("main/archive.html", context)

@login_required
def publish(request):

  user = request.user
  can_edit_list = Article.get_can_edit_list(user)
  published_list = Article.get_published_list(user)
  template_list = Article.get_template_list()
  own_list = []
  pub_list = []
  tmpl_list = []
  for c in can_edit_list:
    own_list.append(c.get_list_dict(user))
  for p in published_list:
    pub_list.append(p.get_list_dict(user))
  for t in template_list:
    tmpl_list.append(t.get_list_dict(user))
  context = RequestContext(request, {
    'own_list': own_list,
    'pub_list': pub_list,
    'tmpl_list': tmpl_list
  })

  return render_to_response("main/publish.html", context)

def browse(request):
  user = request.user
  themes = ArticleTheme.objects.all()
  first_article = Article.objects.all()[0].get_list_dict(user)
  context = RequestContext(request, {'themes': themes, 'first_article': first_article})
  return render_to_response("main/browse.html", context)

def faq(request):
  context = RequestContext(request, {})
  return render_to_response("main/faq.html", context)

def help(request):
  context = RequestContext(request, {})
  return render_to_response("main/help.html", context)

def comingsoon(request):
  context = RequestContext(request, {})
  return render_to_response("main/comingsoon.html", context)

def debug(request):
#  imageVersion = Image.VERSION
# sysPath = ",".join(sys.path)
#  return HttpResponse(imageVersion + "\n" + sysPath)  
  return Foo()  

def error(request):
  return FooBar()
