Пример #1
0
    def get(self):
        adventure = None
        page = None
        error = None

        myAdventureKey = self.request.get('myAdventureKey')
        if myAdventureKey:
            adventure = main.getAdventure(myAdventureKey)
        else:
            error = 'error: no adventure key passed in'
        if adventure == None:
            error = 'error: could not find Adventure ' + myAdventureKey + ' in the database'
        elif not main.isUserAuthor(users.get_current_user(), adventure):
            logging.warning(
                'StoryEditor get: you are not an author of this adventure')
            error = 'Error: You are not an author of this adventure'
        elif not users.get_current_user():
            error = 'error: you are not logged in'

        if error:
            logging.info("########## ERROR: " + error)
        defaultTemplateValues = main.getDefaultTemplateValues(self)
        templateValues = {
            'adventure': adventure,
            'error': error,
            'title': "StoryForge - " + adventure.title,
        }
        templateValues = dict(defaultTemplateValues, **templateValues)

        path = os.path.join(os.path.dirname(__file__), 'storyEditor.html')
        self.response.out.write(template.render(path, templateValues))
Пример #2
0
  def get(self):
	adventure = None
	page = None
	error = None
	
	myAdventureKey = self.request.get('myAdventureKey')
	if myAdventureKey:
		adventure = main.getAdventure(myAdventureKey)
	else:
		error = 'error: no adventure key passed in'
	if adventure == None:
		error = 'error: could not find Adventure ' + myAdventureKey + ' in the database'
	elif not main.isUserAuthor(users.get_current_user(), adventure):
		logging.warning('StoryEditor get: you are not an author of this adventure')
		error = 'Error: You are not an author of this adventure'
	elif not users.get_current_user():
		error = 'error: you are not logged in'

	if error:
		logging.info("########## ERROR: " + error);
	defaultTemplateValues = main.getDefaultTemplateValues(self)
	templateValues = {
		'adventure': adventure,
		'error': error,
		'title': "StoryForge - " + adventure.title,
	}
	templateValues = dict(defaultTemplateValues, **templateValues)

	path = os.path.join(os.path.dirname(__file__), 'storyEditor.html')
	self.response.out.write(template.render(path, templateValues))
Пример #3
0
    def get(self):
        defaultTemplateValues = main.getDefaultTemplateValues(self)
        templateValues = {'title': 'Home'}
        templateValues = dict(defaultTemplateValues, **templateValues)

        path = os.path.join(os.path.dirname(__file__), 'help.html')
        self.response.out.write(template.render(path, templateValues))
Пример #4
0
  def get(self):
	adventure = None
	buttonText = None
	title = 'Create A New Story'
	url = None
	url_linktext = None
	if users.get_current_user():
		url = users.create_logout_url(self.request.uri)
		url_linktext = 'Logout'
		buttonText = 'Create Story'
		myAdventureKey = self.request.get('myAdventureKey')
		if myAdventureKey:
			title = 'Update Story Details'
			buttonText = 'Update Story Details'
			adventure = main.getAdventure(myAdventureKey)
	else:
		url = users.create_login_url(self.request.uri)
		url_linktext = 'Login To Create A Story'
		buttonText = ''

	defaultTemplateValues = main.getDefaultTemplateValues(self)
	templateValues = {
		'title': title,
		'url': url,
		'url_linktext': url_linktext,
		'buttonText': buttonText,
		'adventure': adventure,
	}
	templateValues = dict(defaultTemplateValues, **templateValues)


	path = os.path.join(os.path.dirname(__file__), 'addAdventure.html')
	self.response.out.write(template.render(path, templateValues))
Пример #5
0
  def get(self):
	defaultTemplateValues = main.getDefaultTemplateValues(self)
	templateValues = {
		'title': 'Home'
	}
	templateValues = dict(defaultTemplateValues, **templateValues)

	path = os.path.join(os.path.dirname(__file__), 'help.html')
	self.response.out.write(template.render(path, templateValues))
Пример #6
0
  def get(self, myAdventureKey=None):
	adventure = None
	page = None
	error = None
	title = None
	userVote = None
	
	if not myAdventureKey:
		myAdventureKey = self.request.get('myAdventureKey')
	if myAdventureKey:
		adventure = memcache.get(myAdventureKey)
		if adventure:
			logging.info("Play: got adventure from cache")
		else:
			logging.info("Play: got adventure from db")
			adventure = main.getAdventure(myAdventureKey)
			if adventure:
				memcache.add(myAdventureKey, adventure, 3600)
	else:
		error = 'Error: no adventure key passed in'
	if adventure == None:
		error = 'Error: could not find Adventure [' + myAdventureKey + '] in the database'
	elif not main.isUserReader(users.get_current_user(), adventure):
		error = 'Error: You are not a reader of this adventure'
	else:
		title = adventure.title
	if error:
		logging.info('Play get: ' + error)

	#add to the play stat counter and get the userVote if its not a playLite request
	if adventure:
		if not self.request.get('playLite'):
			adventureStatus = admin.getAdventureStatus(adventure.adventureStatus)
			if not adventureStatus:
				logging.warn("Play: could not get adventureStatus with adventure key: " + str(adventure.key()))
			else:
				userVote = ratings.getUserVote(adventureStatus, users.get_current_user(), None)
				ratings.addAdventurePlay(adventureStatus)

	defaultTemplateValues = main.getDefaultTemplateValues(self)
	templateValues = {
		'adventure': adventure,
		'error': error,
		'title': title,
		'userVote': userVote,
		'isUserAuthor': main.isUserAuthor(users.get_current_user(), adventure),
		'isUserAdmin': main.isUserAdmin(users.get_current_user(), adventure),
	}
	templateValues = dict(defaultTemplateValues, **templateValues)


	if self.request.get('playLite'):
		path = os.path.join(os.path.dirname(__file__), 'playStoryLite.html')
	else:
		path = os.path.join(os.path.dirname(__file__), 'playStory.html')
	self.response.out.write(template.render(path, templateValues))
Пример #7
0
    def get(self):
        ratings = getRatings()

        defaultTemplateValues = main.getDefaultTemplateValues(self)
        templateValues = {
            'title': 'Home',
            'ratings': ratings,
        }
        templateValues = dict(defaultTemplateValues, **templateValues)

        path = os.path.join(os.path.dirname(__file__), 'index.html')
        self.response.out.write(template.render(path, templateValues))
Пример #8
0
  def get(self):
	ratings = getRatings()

	defaultTemplateValues = main.getDefaultTemplateValues(self)
	templateValues = {
		'title': 'Home',
		'ratings': ratings,
	}
	templateValues = dict(defaultTemplateValues, **templateValues)

	path = os.path.join(os.path.dirname(__file__), 'index.html')
	self.response.out.write(template.render(path, templateValues))
Пример #9
0
  def get(self):
	adventure = None
	shares = None
	shareInvites = None
	yourRole = None
	page = None
	error = None
	title = 'Share and Collaborate'
	myAdventureKey = self.request.get('myAdventureKey')

	if not users.get_current_user():
		logging.info("ViewSharing get: you are not logged in")
		error = 'Error: you are not logged in'
	else:
		if myAdventureKey:
			#get the adventure
			adventure = main.getAdventure(myAdventureKey)
		if not adventure:
			logging.info("ViewSharing get: adventure key was not found")
			error = 'Error: adventure was not found'
		elif not main.isUserAdmin(users.get_current_user(), adventure):
			logging.warning('ViewSharing get: you are not an admin of this adventure')
			error = 'Error: You are not an admin of this adventure'
		else:
			#get all the shares for this adventure
			q1 = adventureModel.Share.all().filter('adventure =', adventure).filter('status >=', 1).order('status').order('-role').order('created')
			shares = q1.fetch(9999)
			logging.info("got %d shares for adventure %s" % (len(shares), adventure.title))
			#find your role in this adventure
			for share in shares:
				if share.child == users.get_current_user():
					yourRole = share
					break
			if yourRole == None and users.is_current_user_admin():
				logging.info("Share get: used mega admin powers to grant admin to %s" % users.get_current_user().email())
				yourRole = adventureModel.Share()
				yourRole.role = 3

	defaultTemplateValues = main.getDefaultTemplateValues(self)
	templateValues = {
		'adventure': adventure,
		'adventureKey': myAdventureKey,
		'error': error,
		'title': title,
		'shares': shares,
		'yourRole': yourRole,
	}
	templateValues = dict(defaultTemplateValues, **templateValues)

	path = os.path.join(os.path.dirname(__file__), 'share.html')
	self.response.out.write(template.render(path, templateValues))
Пример #10
0
  def get(self):
	myUser = users.get_current_user()
	if myUser:
		pass
	else:
		url = users.create_login_url(self.request.uri)
		self.redirect(url)
		return

	shares = getMyShares(myUser)
	
	#get any pending share invites
	shareInvites = None
	shareInviteCacheString = "invites_" + users.get_current_user().email()
	shareInvites = memcache.get(shareInviteCacheString)
	if shareInvites and shareInvites != "None":
		logging.info("got %d invites from cache for user %s" % (len(shareInvites), users.get_current_user().email()))
	elif shareInvites and shareInvites == "None":
		logging.info("got 0 invites from cache for user %s" % users.get_current_user().email())
		shareInvites = None
	else:
		q = adventureModel.Share.all().filter('status =', 1).filter('childEmail =', users.get_current_user().email()).order('-created')
		shareInvites = q.fetch(9999)
		if shareInvites:
			if not memcache.add(shareInviteCacheString, shareInvites, 3600):
				logging.info("myStories shareInvites true memcache set failed.")
		else:
			if not memcache.add(shareInviteCacheString, "None", 3600):
				logging.info("myStories shareInvites false memcache set failed.")
		logging.info("got %d invites from db for user %s" % (len(shareInvites), users.get_current_user().email()))
	
	#get iphone links
	iphoneLinks = getIphoneLinks()

	defaultTemplateValues = main.getDefaultTemplateValues(self)
	templateValues = {
		'title': 'My Stories',
		'shares': shares,
		'shareInvites': shareInvites,
		'iphoneLinks': iphoneLinks,
	}
	templateValues = dict(defaultTemplateValues, **templateValues)

	path = os.path.join(os.path.dirname(__file__), 'myStories.html')
	self.response.out.write(template.render(path, templateValues))
	
Пример #11
0
  def get(self):
	iphoneLink = None
	error = None
	myKey = self.request.get('key')
	if not myKey:
		logging.warn("SignupDone: ERROR: requires myKey")
		error = "Error: missing signup key"
	else:
		q = adventureModel.iphoneLink.all().filter('regKey =', myKey).filter('verified =', 0)
		iphoneLinks = q.fetch(1)
		for myIphoneLink in iphoneLinks:
			iphoneLink = myIphoneLink
		if not iphoneLink:
			logging.warn("SignupDone: ERROR: iphoneLink was not found with regKey: " + myKey)
			error = "Error: unused signup key was not found in the database. Maybe you already signed up with this key?"
		else:
			logging.info("SignupDone: iphoneLink was found with regkey: " + myKey)
	
	#if they are signed in, consume the iphoneLink record
	if iphoneLink and users.get_current_user():
		iphoneLink.verified = 1
		iphoneLink.user = users.get_current_user()
		iphoneLink.put()
		#remove the cache record
		memcache.delete('iphoneLinks' + users.get_current_user().email())
		memcache.delete('myStoriesXML' + users.get_current_user().email())
	
	defaultTemplateValues = main.getDefaultTemplateValues(self)
	templateValues = {
		'error': error,
		'iphoneLink': iphoneLink,
		'title': 'Thanks For Signing Up!'
	}
	templateValues = dict(defaultTemplateValues, **templateValues)

	path = os.path.join(os.path.dirname(__file__), 'signup.html')
	self.response.out.write(template.render(path, templateValues))
Пример #12
0
    def get(self, comment_in=None, myAdventureKey_in=None, submitFlag=False):
        adventure = None
        adventureStatus = None
        error = None
        myAdventureKey = None
        submitComment = comment_in
        comment = None
        if myAdventureKey_in:
            myAdventureKey = myAdventureKey_in
        else:
            myAdventureKey = self.request.get('myAdventureKey')
        adventure = main.getAdventure(myAdventureKey)
        if not adventure:
            logging.warn('Submit: adventure was not found in the DB: ' +
                         myAdventureKey)
            error = "Adventure key was not found in the DB"
        else:
            #make sure the logged in person is an admin
            if not main.isUserAdmin(users.get_current_user(), adventure):
                logging.warning(
                    'RemoveShare post: you are not an admin of this adventure')
                error = 'Error: You are not an admin of this adventure'
            else:
                #try to get the AdventureStatus record, if it doesn't exist, create it
                adventureStatus = getAdventureStatus(adventure.adventureStatus)
                if not adventureStatus:
                    logging.warn(
                        "Submit: could not found adventureStatus record: " +
                        myAdventureKey)
                else:
                    logging.info('Submit: got adventureStatus record')

        #if we have a submitFlag, then we're trying to submit the form
        if submitFlag and adventure and adventureStatus:
            logging.info("Submit: submit flag was set. comment(%s)" % comment)
            #delete the previous submitted adventure
            submittedAdventure = adventureStatus.submittedAdventure
            memcache.delete(str(adventureStatus.key()))
            if submittedAdventure:
                deleteAdventure(submittedAdventure)
            #now duplicate the story
            adventureStatus.submittedAdventure = duplicateAdventure(adventure)
            if adventureStatus.submittedAdventure:
                comment = 'Your story has been submitted.'
                adventureStatus.status = 2
                adventureStatus.comment = submitComment
                adventureStatus.put()
                #reset the cache
                memcache.delete('advStat' + str(adventure.key()))
                #send an email to the admins
                body = '''%s (%s) has just submitted a story for approval.
Title: %s
Author: %s
RealAuthor: %s
Description: %s

Check it out at: http://istoryweb.appspot.com/admin
''' % (users.get_current_user().email(), users.get_current_user().nickname(),
                adventure.title, adventure.author, adventure.realAuthor, adventure.desc)
                mail.send_mail(
                    users.get_current_user().email(),
                    '*****@*****.**',
                    users.get_current_user().nickname() +
                    ' has just submitted a story for approval', body)
            else:
                error = 'Error, something went wrong with the submission.'

        defaultTemplateValues = main.getDefaultTemplateValues(self)
        templateValues = {
            'comment': comment,
            'error': error,
            'adventureStatus': adventureStatus,
            'title': 'Submit Your Story For Approval',
        }
        templateValues = dict(defaultTemplateValues, **templateValues)

        path = os.path.join(os.path.dirname(__file__), 'submit.html')
        self.response.out.write(template.render(path, templateValues))
Пример #13
0
                except Exception, e:
                    myOutput = "%d: *** exception ***: %s<br>" % (
                        n, image.imageName)
                    memcache.delete('img' + str(image.key()))
                    image.delete()
                output += myOutput
            #remove cached images
            q = adventureModel.Share.all()
            roles = q.fetch(9999)
            n = 0
            for role in roles:
                if role.child:
                    n = n + 1
                    memcache.delete("images" + role.child.email())
            output += "<br>removed %d user images cache entries<br>" % n

        #show any stories waiting to be approved
        q = adventureModel.AdventureStatus.all().filter('status =', 2)
        adventureStatuses = q.fetch(9999)

        defaultTemplateValues = main.getDefaultTemplateValues(self)
        templateValues = {
            'title': 'Admin',
            'output': output,
            'adventureStatuses': adventureStatuses,
        }
        templateValues = dict(defaultTemplateValues, **templateValues)

        path = os.path.join(os.path.dirname(__file__), 'admin.html')
        self.response.out.write(template.render(path, templateValues))
Пример #14
0
    def get(self, myAdventureKey=None):
        adventure = None
        page = None
        error = None
        title = None
        userVote = None

        if not myAdventureKey:
            myAdventureKey = self.request.get('myAdventureKey')
        if myAdventureKey:
            adventure = memcache.get(myAdventureKey)
            if adventure:
                logging.info("Play: got adventure from cache")
            else:
                logging.info("Play: got adventure from db")
                adventure = main.getAdventure(myAdventureKey)
                if adventure:
                    memcache.add(myAdventureKey, adventure, 3600)
        else:
            error = 'Error: no adventure key passed in'
        if adventure == None:
            error = 'Error: could not find Adventure [' + myAdventureKey + '] in the database'
        elif not main.isUserReader(users.get_current_user(), adventure):
            error = 'Error: You are not a reader of this adventure'
        else:
            title = adventure.title
        if error:
            logging.info('Play get: ' + error)

        #add to the play stat counter and get the userVote if its not a playLite request
        if adventure:
            if not self.request.get('playLite'):
                adventureStatus = admin.getAdventureStatus(
                    adventure.adventureStatus)
                if not adventureStatus:
                    logging.warn(
                        "Play: could not get adventureStatus with adventure key: "
                        + str(adventure.key()))
                else:
                    userVote = ratings.getUserVote(adventureStatus,
                                                   users.get_current_user(),
                                                   None)
                    ratings.addAdventurePlay(adventureStatus)

        defaultTemplateValues = main.getDefaultTemplateValues(self)
        templateValues = {
            'adventure': adventure,
            'error': error,
            'title': title,
            'userVote': userVote,
            'isUserAuthor': main.isUserAuthor(users.get_current_user(),
                                              adventure),
            'isUserAdmin': main.isUserAdmin(users.get_current_user(),
                                            adventure),
        }
        templateValues = dict(defaultTemplateValues, **templateValues)

        if self.request.get('playLite'):
            path = os.path.join(os.path.dirname(__file__),
                                'playStoryLite.html')
        else:
            path = os.path.join(os.path.dirname(__file__), 'playStory.html')
        self.response.out.write(template.render(path, templateValues))
Пример #15
0
  def get(self, comment_in=None, myAdventureKey_in=None, submitFlag=False):
	adventure = None
	adventureStatus = None
	error = None
	myAdventureKey = None
	submitComment = comment_in
	comment = None
	if myAdventureKey_in:
		myAdventureKey = myAdventureKey_in
	else:
		myAdventureKey = self.request.get('myAdventureKey')
	adventure = main.getAdventure(myAdventureKey)
	if not adventure:
		logging.warn('Submit: adventure was not found in the DB: ' + myAdventureKey)
		error = "Adventure key was not found in the DB"
	else:
		#make sure the logged in person is an admin
		if not main.isUserAdmin(users.get_current_user(), adventure):
			logging.warning('RemoveShare post: you are not an admin of this adventure')
			error = 'Error: You are not an admin of this adventure'
		else:
			#try to get the AdventureStatus record, if it doesn't exist, create it
			adventureStatus = getAdventureStatus(adventure.adventureStatus)
			if not adventureStatus:
				logging.warn("Submit: could not found adventureStatus record: " + myAdventureKey)
			else:
				logging.info('Submit: got adventureStatus record')
	
	#if we have a submitFlag, then we're trying to submit the form
	if submitFlag and adventure and adventureStatus:
		logging.info("Submit: submit flag was set. comment(%s)" % comment)
		#delete the previous submitted adventure
		submittedAdventure = adventureStatus.submittedAdventure
		memcache.delete(str(adventureStatus.key()))
		if submittedAdventure:
			deleteAdventure(submittedAdventure)
		#now duplicate the story
		adventureStatus.submittedAdventure = duplicateAdventure(adventure)
		if adventureStatus.submittedAdventure:
			comment = 'Your story has been submitted.'
			adventureStatus.status = 2
			adventureStatus.comment = submitComment
			adventureStatus.put()
			#reset the cache
			memcache.delete('advStat' + str(adventure.key()))
			#send an email to the admins
			body = '''%s (%s) has just submitted a story for approval.
Title: %s
Author: %s
RealAuthor: %s
Description: %s

Check it out at: http://istoryweb.appspot.com/admin
''' % (users.get_current_user().email(), users.get_current_user().nickname(), adventure.title, adventure.author, adventure.realAuthor, adventure.desc)
			mail.send_mail(users.get_current_user().email(), '*****@*****.**', users.get_current_user().nickname() + ' has just submitted a story for approval', body)
		else:
			error = 'Error, something went wrong with the submission.'
		

	defaultTemplateValues = main.getDefaultTemplateValues(self)
	templateValues = {
		'comment': comment,
		'error': error,
		'adventureStatus': adventureStatus,
		'title': 'Submit Your Story For Approval',
	}
	templateValues = dict(defaultTemplateValues, **templateValues)

	path = os.path.join(os.path.dirname(__file__), 'submit.html')
	self.response.out.write(template.render(path, templateValues))
Пример #16
0
				image.delete()
			output += myOutput
		#remove cached images
		q = adventureModel.Share.all()
		roles = q.fetch(9999)
		n = 0
		for role in roles:
			if role.child:
				n = n + 1
				memcache.delete("images" + role.child.email())
		output += "<br>removed %d user images cache entries<br>" % n

	#show any stories waiting to be approved
	q = adventureModel.AdventureStatus.all().filter('status =', 2)
	adventureStatuses = q.fetch(9999)

	defaultTemplateValues = main.getDefaultTemplateValues(self)
	templateValues = {
		'title': 'Admin',
		'output': output,
		'adventureStatuses': adventureStatuses,
	}
	templateValues = dict(defaultTemplateValues, **templateValues)

	path = os.path.join(os.path.dirname(__file__), 'admin.html')
	self.response.out.write(template.render(path, templateValues))




Пример #17
0
  def get(self):
	#this method takes an existing share invite record and accepts it
	#get the invite from the db
	error = None
	state = None
	share = None
	myInviteKey = self.request.get('key')
	myShareKey = self.request.get('shareInviteKey')
	myResponse = self.request.get('response')
	logging.info("ShareInvite: key(%s) shareInviteKey(%s) response(%s)" % (myInviteKey, myShareKey, myResponse))
	
	#if we have an invite key, this must be the first click of the invite link
	if myInviteKey:
		logging.info("ShareInvite: someone clicked the invite link with key %s" % myInviteKey )
		q = adventureModel.Share.all().filter('status =', 1).filter('inviteKey =', myInviteKey)
		myShares = q.fetch(1)
		for myShare in myShares:
			share = myShare
		if not share:
			error = 'Error: that invite key (%s) was not found. Please check the link from the email carefully.'
		else:
			state = "1"
	elif myShareKey and myResponse:
		if myResponse == "1":
			#now we need to make sure they're logged in
			if not users.get_current_user():
				logging.info("ShareInvite: invite tried to be accepted but the user needs to login")
				error = 'To continue, you need to <a href="%s">login with your Google account</a>.' % users.create_login_url(self.request.uri)
			else:
				share = db.Model.get(myShareKey)
				if not share:
					logging.info("ShareInvite: invite accepted and the user is logged in, but the invite key did not exist " + myShareKey)
					error = 'Error: this share key was not found.'
				else:
					logging.info("ShareInvite: invite accepted and the user is logged in")
					state = "2"
					share.status = 2
					share.child = users.get_current_user()
					share.put()
					#delete the current adventure cache object
					memcache.delete("adventures_" + share.child.email())
					memcache.delete('myStoriesXML' + share.child.email())
					#remove the share invite cache object
					memcache.delete("invites_" + share.childEmail)
					memcache.delete("invites_" + users.get_current_user().email())
					#remove the user share object from cache
					removeUserShareCache(share.child, str(share.adventure.key()))
					removeUserShareCache(share.child, str(share.adventure.key()))
		else:
			logging.info("ShareInvite: invite ignored")
			error = "Invite ignored."

	defaultTemplateValues = main.getDefaultTemplateValues(self)
	templateValues = {
		'error': error,
		'share': share,
		'response': myResponse,
		'state': state,
	}
	templateValues = dict(defaultTemplateValues, **templateValues)

	path = os.path.join(os.path.dirname(__file__), 'shareInvite.html')
	self.response.out.write(template.render(path, templateValues))
Пример #18
0
  def post(self):
	error = None
	newAdventure = False
	myAdventureKey = self.request.get('myAdventureKey')
	logging.info("AddAdventure for key: " + myAdventureKey)
	if not users.get_current_user():
		logging.warning('AddAdventure post: you need to login')
		error = "Error: You need to login."
	if myAdventureKey:
		logging.info("existing adventure.")
		adventure = main.getAdventure(myAdventureKey)
		if not main.isUserAdmin(users.get_current_user(), adventure):
			logging.warning('AddAdventure post: you are not an admin of this adventure')
			error = "Error: You are not an admin of this adventure."
	else:
		logging.info("new adventure.")
		adventure = adventureModel.Adventure()
		newAdventure = True

	if error:
		defaultTemplateValues = main.getDefaultTemplateValues(self)
		templateValues = {
			'error': error
		}
		templateValues = dict(defaultTemplateValues, **templateValues)
		path = os.path.join(os.path.dirname(__file__), 'addAdventure.html')
		self.response.out.write(template.render(path, templateValues))
		return

	if not adventure.realAuthor:
		adventure.realAuthor = users.get_current_user()
	adventure.title = self.request.get('title') or "[no title]"
	adventure.author = self.request.get('author') or "[no author]"
	adventure.desc = self.request.get('desc') or "[no description]"
	adventure.approved = 0
	adventure.version = 0.0
	adventure.put()
	#we dont want to delete the cache of ratings because this adventure won't be approved or rated yet
	#memcache.delete("ratings")
	memcache.delete("adventures_" + users.get_current_user().email())
	logging.info("AddAdventure data: " + simplejson.dumps(adventure.toDict()))
	if newAdventure:
		#now create an admin role for this user + adventure, only if its a new adventure
		share = adventureModel.Share()
		share.adventure = adventure
		share.owner = users.get_current_user()
		share.child = users.get_current_user()
		share.role = 3
		share.status = 2
		share.put()
		#now create the adventureStatus record
		adventureStatus = adventureModel.AdventureStatus()
		adventureStatus.editableAdventure = adventure
		adventureStatus.status = 1
		adventureStatus.version = 0.0
		adventureStatus.put()
		#save the adventureStatus key back to the adventure record
		adventure.adventureStatus = str(adventureStatus.key())
		adventure.put()
		#now create the rating record for this adventure
		rating = adventureModel.AdventureRating()
		rating.adventureStatus = adventureStatus
		rating.voteCount = 0
		rating.voteSum = 0
		rating.plays = 0
		rating.approved = 0
		rating.rating = 0.0
		rating.put()
	#handle the coverImage
	newCoverImage = self.request.get('coverImage')
	oldCoverImage = adventure.coverImage
	if newCoverImage:
		myImageSizeBytes = len(newCoverImage)
		logging.info("GOT IMAGE DATA!! " + str(myImageSizeBytes) + ' bytes.')
		if myImageSizeBytes > 1048576:
			logging.info("ERROR: Image was too large(%d bytes). 1 megabyte is the max size." % (myImageSizeBytes))
			self.response.out.write("ERROR: Image was too large. 1 megabyte is the max size.")
			return
		if len(newCoverImage) > 100:
			logging.info("AddAdventure: got new cover image")
			imageOBJ = images.Image(newCoverImage)
			#resize to 320x150
			imageOBJ.resize(320, 150)
			newImage = adventureModel.Image()
			newImage.imageData = imageOBJ.execute_transforms()
			#setup the rest of the image metadata
			newImage.adventure = adventure
			if adventure.adventureStatus:
				adventureStatus = main.getAdventure(adventure.adventureStatus)
				if adventureStatus:
					newImage.adventureStatus = adventureStatus
			if not newImage.adventureStatus:
				logging.warn("AddAdventure: trying to use new coverImage and adventureStatus could not be found")
			newImage.pageElement = "coverImage"
			newImage.imageName = "Cover Image"
			newImage.realAuthor = users.get_current_user()
			newImage.put()
			adventure.coverImage = str(newImage.key())
			adventure.put()
			#delete the old cover image if it exists and no page elements are using it
			if oldCoverImage:
				oldCoverImage = db.Model.get(oldCoverImage)
				if oldCoverImage:
					deleteFlag = True
					for pageElement in oldCoverImage.pageElements:
						deleteFlag = False
						logging.info("AddAdventure: not deleting old cover image because it is in use by a page element")
						break
					#also check the editable, submitted, and published adventure on this adventureStatus
					if adventureStatus.editableAdventure:
						if adventureStatus.editableAdventure.coverImage == str(oldCoverImage.key()):
							deleteFlag = False
					if adventureStatus.submittedAdventure:
						if adventureStatus.submittedAdventure.coverImage == str(oldCoverImage.key()):
							deleteFlag = False
					if adventureStatus.publishedAdventure:
						if adventureStatus.publishedAdventure.coverImage == str(oldCoverImage.key()):
							deleteFlag = False
					if deleteFlag:
						logging.info("AddAdventure: deleting old cover image")
						oldCoverImage.delete()
	
	#remove the cache object for all users who have a role for this adventure
	q = adventureModel.Share.all().filter('adventure =', adventure)
	shares = q.fetch(9999)
	logging.info("AddAdventure: removed %d cache objects" % len(shares))
	for share in shares:
		if share.child:
			memcache.delete("adventures_" + share.child.email())
			memcache.delete("myStoriesXML" + share.child.email())
			memcache.delete("images" + share.child.email())
	logging.info("addAdventure: deleting memcache object: " + str(adventure.key()))
	memcache.delete(str(adventure.key()))
	memcache.delete('XmlPages' + str(adventure.key()))
	
	logging.info("AddAdventure done for key: " + myAdventureKey)
	#self.redirect('/myStories')
	#if not myAdventureKey:
	#	#redirect you right to the story editor if its a new story
	#	self.redirect('/storyEditor?myAdventureKey=' + str(adventure.key()))
	#else:
	#redirect you back to myStories
	self.redirect('/myStories')