Example #1
0
	def load(self):
		save = []
		logging.info('loading fixture')
		self.fixture_offset = Setting.get_by_key_name('fixture_offset')  
		if self.fixture_offset.status == "update_stats": #instead of 'create_account'
			logging.warning('Load Fixtures Cron Job Hit Twice In a Row')
			print "error -- current status: ", self.fixture_offset.status
			return False
		this_account, this_user, this_quiz_taker = self.get_fixture()
		scores = Scores()
		import random
		correct_prob = random.randint(80,95)
		FIXTURE_PROFICIENCY = self.get_fixture_subject()
		from model.proficiency import Proficiency 
		this_proficiency = random.sample( Proficiency.gql("WHERE status = 'public'").fetch(1000), 1 )[0]
		save_scores = scores.make_scores(this_user, this_proficiency, correct_prob, SCORE_NUM = 10) 
		memcache.set('current_fixture', ( this_account, this_user, this_quiz_taker ), 600000)
		self.fixture_offset.status = "update_stats"
		print this_user.nickname
		save.append(self.fixture_offset)
		save.extend(save_scores)
		db.put(save)
		# open fixture.xml, go to offset.
		# load one name, email pair. register. 

		FIXTURE_PROFICIENCY = self.get_fixture_subject()
Example #2
0
def get_featured_quiz():
	try: 
	    from model.dev import Setting
	    featured_subject = Setting.get_by_key_name('fixture_subject').status
	except:
		from model.proficiency import Proficiency
		featured_subject = Proficiency.gql("WHERE status = 'public' ORDER BY status, modified DESC" ).get()
	return featured_subject
Example #3
0
File: rpc.py Project: jamslevy/PQ
 def pqmember(self, *args):
   	from model.user import Profile
   	pq = Profile.get_by_key_name("PlopQuiz")
   	from model.proficiency import Proficiency
   	ps = Proficiency.gql("WHERE status = 'public'").fetch(1000)
   	from model.user import SubjectMember
   	for p in ps: 
   	   db.put(SubjectMember(key_name = pq.unique_identifier + "_" + p.name, user = pq, subject = p ))
Example #4
0
File: views.py Project: jamslevy/PQ
  def get_quiz_subjects(self):
		from model.proficiency import Proficiency
		quiz_subjects = Proficiency.gql("WHERE status = 'public' ORDER BY status, modified DESC" ).fetch(6)
		for p in quiz_subjects:
		    if p.name == eval(self.request.get('subject'))[0]: 
		        quiz_subjects.remove(p)
		        quiz_subjects.insert(0, p)
		        continue
		return quiz_subjects[0:5]
Example #5
0
File: rpc.py Project: jamslevy/PQ
	def NewTopic(self):   # set moderation status for raw item
		this_subject = Proficiency.gql("WHERE name = :1", self.request.get('subject_name')).get()
		new_topic = ProficiencyTopic(name = self.request.get('topic_name'), proficiency = this_subject)
		db.put([this_subject, new_topic])
		if self.request.get('no_template'): return "OK"
		from utils.webapp import template
		from utils.utils import tpl_path
		template_values = {"subject": this_subject, "new_topic":new_topic}
		path = tpl_path(EDITOR_PATH + 'item_topic.html')
		return template.render(path, template_values)
Example #6
0
def extra_subjects(member_subjects, these_subjects, offset=0): 
	extra_subjects = Proficiency.gql("WHERE status = 'public' ORDER BY status, modified DESC").fetch(100)
	current_count = 0
	for s in extra_subjects:
		if current_count >= MIN_SUBJECT_LENGTH: break
		elif s.name not in member_subjects:
			these_subjects.append(s)
			current_count += 1
		else: continue # subject already in these_subjects
		
	return these_subjects
Example #7
0
File: views.py Project: jamslevy/PQ
 def get(self):
 	proficiencies = Proficiency.gql("WHERE status = :1", "public");
 	proficiencies = proficiencies.fetch(1000)
 	buy_buttons = []
 	for p in proficiencies: 
 	    p.checkout_button = checkout.render_quiz_button(self, p.tag(), p.name)
 	    buy_buttons.append( { 'tag': p.tag().lower(), 'html' : p.checkout_button})
 	    
 	prof_json = encode(proficiencies)
     template_values = {'proficiencies' : proficiencies, 'prof_json': prof_json, 'buy_buttons': encode(buy_buttons), 'load': 2000}
     path = tpl_path(STORE_PATH + 'proficiency.html')
     self.response.out.write(template.render(path, template_values))
Example #8
0
 def get_html(self):   
   import urllib
   template_values = {'text': urllib.unquote( self.request.get('text') ) }
   from model.proficiency import Proficiency 
   if self.request.get('subject_key'): template_values['subject_key'] = self.request.get('subject_key')
   else: 
     subjects = Proficiency.gql("WHERE status = 'public'").fetch(1000) 
     template_values['subjects'] = subjects
   if self.request.get('topic_key'): template_values['topic_key'] = self.request.get('topic_key')
   if self.request.get('topic_name'): 
       from model.proficiency import ProficiencyTopic
       p = ProficiencyTopic.gql("WHERE name = :1",  self.request.get('topic_name')).get()
       template_values['topic_key'] = p.key()
   path = tpl_path(DEV_PATH +'ubiquity_builder.html')
   response = simplejson.dumps(template.render(path, template_values))
   self.response.out.write(jsonp(self.request.get("callback"), response))
Example #9
0
File: rpc.py Project: jamslevy/PQ
	def join_subject(self):
		from utils.appengine_utilities.sessions import Session
		self.session = Session()	
		from model.proficiency import Proficiency	
		this_subject = Proficiency.gql("WHERE name = :1", self.request.get('subject_name') ).get()
		from model.user import SubjectMember
		admin_status = False
		from google.appengine.api import users
		user = users.get_current_user()
		if user: admin_status = True
		this_membership = SubjectMember(keyname = self.session['user'].unique_identifier + "_" + this_subject.name, user = self.session['user'], subject = this_subject, is_admin = admin_status)
		logging.info('user %s joined subject %s'% (self.session['user'].unique_identifier, this_subject.name) )
		db.put([this_membership])		
		from utils.webapp import template
		path = tpl_path(EDITOR_PATH +'load_member_section.html')
		template_values = {'s': {"subject": this_subject, "is_member": "contributor" }} # Only admins can edit links, for now. 
		return template.render(path, template_values)	
Example #10
0
File: rpc.py Project: jamslevy/PQ
	def create_new_subject(self):
		from utils.appengine_utilities.sessions import Session
		self.session = Session()	
		from model.proficiency import Proficiency		
		existing_subject = Proficiency.gql("WHERE name = :1", self.request.get('subject_name') ).get()
		if existing_subject is not None: 
		    logging.warning("user %s attempted to create duplicate subject with name %s" %(self.session['user'].unique_identifier, self.request.get('subject_name')) )
		    return "exists"
		this_subject = Proficiency(key_name = self.request.get('subject_name'), name = self.request.get('subject_name'))
		from model.user import SubjectMember
		this_membership = SubjectMember(keyname = self.session['user'].unique_identifier + "_" + this_subject.name, 
		                                user = self.session['user'], 
		                                subject = this_subject, 
		                                status = "public",
		                                is_admin = True)
		                                
		logging.info('user %s created subject %s'% (self.session['user'].unique_identifier, this_subject.name) )
		db.put([this_subject, this_membership])		
		from utils.webapp import template
		path = tpl_path(EDITOR_PATH +'subject_container.html')
		from editor.methods import get_subjects_for_user     
		template_values = { 'subjects' : get_subjects_for_user(self.session['user'])}
		return template.render(path, template_values)	
Example #11
0
def get_subjects_for_user(this_user, offset=0): # Can this be refactored?
	"""
	
	This current method places member subjects first, and then loads non-member subjects.
	
	This is just a prototype and a later implementation may be different.
	
	"""	
	memberships = this_user.member_subjects.fetch(100) 
	member_subjects = []
	for m in memberships: member_subjects.append(m.subject.name)
	these_subjects = Proficiency.gql("WHERE name IN  :1 AND status = 'public' ORDER BY status, modified DESC", member_subjects).fetch(1000)
	# In case there aren't enough member subjects, add more
	if len(these_subjects) - offset < MIN_SUBJECT_LENGTH: these_subjects = extra_subjects(member_subjects, these_subjects, offset=offset)
	subject_list = []
	if len(these_subjects[offset:offset+5]) > 0: these_subjects = these_subjects[offset:offset+5]
	for s in these_subjects[:5]:
		is_member = False
		for m in memberships:
			if m.subject.name == s.name:
				if m.is_admin: is_member = "admin"
				else: is_member = "contributor"
		subject_list.append({"subject": s, "is_member": is_member})
	return subject_list
Example #12
0
File: views.py Project: jamslevy/PQ
  def get(self):
    self.proficiencies = {}
      # Create random list of three quiz items.
    if self.request.get('proficiencies'):
        quiz_items = []
        for p in eval(self.request.get('proficiencies')):  # TODO make these keys for easy lookup   -- these are proficiencies, not topics.
			this_p = Proficiency.gql("WHERE name = :1", p)
			q = QuizItem.gql("WHERE proficiency = :1", this_p.get())   # use topic for key
			quiz_items.extend(q.fetch(1000))
    # Query all quiz items
    else:
        q = db.GqlQuery("SELECT * FROM QuizItem")
        quiz_items = q.fetch(1000) 
    # Load Fixture Data if Necessary
        q = db.GqlQuery("SELECT * FROM QuizItem")
        quiz_items = q.fetch(1000)
    import random
    for item in quiz_items:
        self.load_item(item, random)
    self.load_array(random)
    template_values = {"quiz_items": self.quiz_array  }
    logging.debug(template_values)
    path = tpl_path(DEMO_PATH + 'ad.html')
    self.response.out.write(template.render(path, template_values))
Example #13
0
File: rpc.py Project: jamslevy/PQ
	def SubmitItem(self):   
		from model.proficiency import Proficiency, ProficiencyTopic
		this_subject = Proficiency.gql("WHERE name = :1", self.request.get('subject_name') ).get()
		logging.info('submitting item')
		from utils.appengine_utilities.sessions import Session
		session = Session()
		if len( self.request.get('item_key') ) < 1:
			this_item = QuizItem(pending_proficiency = this_subject)
			if session['user']: this_item.author= session['user']
		else: 
			this_item = QuizItem.get(self.request.get('item_key'))         	
		if self.request.get('item_status') == "approved":
			this_item.active = True
			this_item.pending_proficiency = None
			this_item.proficiency = this_subject        	
		if self.request.get('item_status') == "not_approved":
			this_item.active = False
			this_item.pending_proficiency = this_subject  
			this_item.proficiency = None        		
		this_item.topic = ProficiencyTopic.get( self.request.get('topic_key') )
		this_item.index = self.request.get('correct_answer')
		this_item.answers = [a.strip("'") for a in self.request.get('answers').split(",")] 
		this_item.content = self.request.get('item_text')
		save = [ this_subject, this_item]
		#if session['user']: save.append(session['user'])
		db.put( save )
		logging.info('saving new quiz item %s with subject %s and index %s' % (this_item.__dict__, self.request.get('subject_name'), self.request.get('correct_answer') ))
		if self.request.get('ubiquity'): return "OK"
		from utils.webapp import template
		from utils.utils import tpl_path        
		from editor.methods import get_membership, get_user_items		
		template_values = {"subject": this_subject, 
						   'subject_membership': get_membership(session['user'], this_subject),
						   'user_items': get_user_items(session['user'], this_subject), }
		path = tpl_path(EDITOR_PATH + 'quiz_item_editor_template.html')
		return template.render(path, template_values)
Example #14
0
 def get_html(self):
   from model.proficiency import Proficiency 
   subjects = Proficiency.gql("WHERE status = 'public'").fetch(1000) 
   template_values = {'text': self.request.get('text'), 'subjects': subjects}
   path = tpl_path(DEV_PATH +'ubiquity_builder.html')
   self.response.out.write(template.render(path, template_values))