# Path: models/post.py
# class Post(ndb.Model):
# 	text = ndb.TextProperty()
# 	date = ndb.DateProperty()
# 	source = ndb.StringProperty(choices=['empty', 'ohlife','email','web','mixed'], default='empty')
# 	created = ndb.DateTimeProperty(auto_now_add=True)
# 	updated = ndb.DateTimeProperty(auto_now=True)
# 	images=ndb.StringProperty(repeated=True)
# 	has_images = ndb.BooleanProperty(default=False)
# 
# 	seperator = '-------------------------'
# 	
# 	def date_string(self):
# 		return self.date.strftime('%Y-%m-%d')
# 
# 	@classmethod
# 	def min_date(cls):
# 		post = Post.query().order(Post.date).get()
# 		if post:
# 			return post.date
# 		return None
# 
# 	@classmethod
# 	def max_date(cls):
# 		post = Post.query().order(-Post.date).get()
# 		if post:
# 			return post.date
# 		return None		


import webapp2, datetime, json
from models.post import Post
from google.appengine.ext import ndb


class PostDatesHandler(webapp2.RequestHandler):
	def get(self, year, month):
		year, month = int(year), int(month)
		from_date = datetime.date(int(year), int(month), 1)
		next_month = from_date + datetime.timedelta(days=33)

		to_date = datetime.date(next_month.year, next_month.month, 1)


# Path: models/post.py
# class Post(ndb.Model):
# 	text = ndb.TextProperty()
# 	date = ndb.DateProperty()
# 	source = ndb.StringProperty(choices=['empty', 'ohlife','email','web','mixed'], default='empty')
# 	created = ndb.DateTimeProperty(auto_now_add=True)
# 	updated = ndb.DateTimeProperty(auto_now=True)
# 	images=ndb.StringProperty(repeated=True)
# 	has_images = ndb.BooleanProperty(default=False)
# 
# 	seperator = '-------------------------'
# 	
# 	def date_string(self):
# 		return self.date.strftime('%Y-%m-%d')
# 
# 	@classmethod
# 	def min_date(cls):
# 		post = Post.query().order(Post.date).get()
# 		if post:
# 			return post.date
# 		return None
# 
# 	@classmethod
# 	def max_date(cls):
# 		post = Post.query().order(-Post.date).get()
# 		if post:
# 			return post.date
# 		return None		


# Path: handlers/postdates.py
import webapp2, datetime, json
from models.post import Post
from google.appengine.ext import ndb



class PostDatesHandler(webapp2.RequestHandler):
	def get(self, year, month):
		year, month = int(year), int(month)
		from_date = datetime.date(int(year), int(month), 1)
		next_month = from_date + datetime.timedelta(days=33)

		to_date = datetime.date(next_month.year, next_month.month, 1)


		days = [p.date.day for p in Post.query(ndb.AND(Post.date >= from_date, Post.date < to_date)).order(-Post.date).fetch()]