def get(self, practice_id): id = Practice.get_long_uid(practice_id) practice = self.api.get_by_id(id) if practice: # Increment view counts on the practice view_counter.increment(id) # Get related practices related_practices = Practice.get_related_practices(practice, 3) # Get color from associated content color = '#51516c' # default color if practice.associated_content: associated_content = self.api.get_by_id( practice.associated_content) color = associated_content.color creator = practice.key.parent().get() self.write( 'practice.html', practice=practice, creator=creator, creator_json=json.dumps(creator.to_client_dict()), color=color, related_practices=related_practices, ) else: # 404 if theme cannot be found return self.http_not_found()
def get(self): # Fetches votes for currently logged in user # Replace lesson_id and practice_id with full versions params = self.get_params() if 'practice_id' in params: params[u'practice_id'] = Practice.get_long_uid( params[u'practice_id']) if 'lesson_id' in params: params[u'lesson_id'] = Lesson.get_long_uid(params[u'lesson_id']) votes = self.api.get('Vote', ancestor=self.api.user, **params) self.write(votes)
def remove_file(self, id): file_key = self.get_params().get('file') if id is not None and file_key is not None: id = Practice.get_long_uid(id) practice = self.api.get_by_id(id) practice.remove_file_data(urllib.unquote(file_key)) practice.put() self.write(practice) else: self.response.write( json.dumps({ 'error': True, 'message': 'invalid parameters' }))
def get(self, practice_id=None): user = self.get_current_user() if user is None: self.redirect('/search') return # Check if user is practice creator or admin if not user.is_admin and practice_id: practice = self.api.get_by_id(Practice.get_long_uid(practice_id)) creator = practice.key.parent().get() if creator is not user: self.redirect('/practices/{}'.format(practice_id)) self.write( 'practice-upload.html', practice_id=practice_id, )
def get(self, id=None): # convert short_uid to uid if needed if id is not None: id = Practice.get_long_uid(id) response = self.api.get_by_id(id) else: params = self.get_params() practices = self.api.get('Practice', **params) user_ids = [p.uid.split('.')[1] for p in practices] response = [] users = self.api.get_by_id(user_ids) for p in practices: for user in users: if user.uid == p.uid.split('.')[1]: practice_dict = p.to_client_dict() practice_dict['user'] = user.to_client_dict() response.append(practice_dict) break self.write(response)
def get(self, practice_id): id = Practice.get_long_uid(practice_id) practice = self.api.get_by_id(id) if practice: # Increment view counts on the practice view_counter.increment(id) # Get related practices related_practices = Practice.get_related_practices(practice, 3) creator = practice.key.parent().get().to_client_dict() self.write( 'practice.html', practice=practice, creator=creator, creator_json=json.dumps(creator), related_practices=related_practices, ) else: # 404 if theme cannot be found return self.http_not_found()