def to_dashboard_response_message(self, user): user_message = None if self.creator is not None: user_info = self.creator.get() user_message = UserMessage(display_name=user_info.display_name, user_email=user_info.user_email, image_url=user_info.image_url) app = self.app.get() if self.app else None app_name = app.name if app else self.app_name app_version = app.version if app else self.app_version # set anno association with followups from model.follow_up import FollowUp followups = FollowUp.find_by_anno(self, True) followup_messages = [ entity.to_message(auth_user=user) for entity in followups ] from model.vote import Vote is_my_vote = Vote.is_belongs_user(self, user) from model.flag import Flag is_my_flag = Flag.is_belongs_user(self, user) mentions = [] for tagged_user in self.tagged_users: tagged_user_info = User.get_by_id(int(tagged_user)) is_auth_user = tagged_user_info.user_email == user.user_email mentions.append(AnnoMentionsResponseMessage(id=tagged_user_info.key.id(), display_name=tagged_user_info.display_name, user_email=tagged_user_info.user_email, image_url=tagged_user_info.image_url, is_auth_user=is_auth_user)) team_notes_metadata = AnnoTeamNotesMetadataMessage(tags=parseTeamNotesForHashtags(self.team_notes), mentions=mentions) engaged_users = Anno.getEngagedUsers(anno_id=self.key.id(), auth_user=user, include_auth_user=True) anno_message = AnnoDashboardResponseMessage(id=self.key.id(), anno_text=self.anno_text, device_model=self.device_model, app_name=app_name, app_version=app_version, os_name=self.os_name, os_version=self.os_version, created=self.created, creator=user_message, draw_elements=self.draw_elements, vote_count=self.vote_count, flag_count=self.flag_count, followup_count=self.followup_count, followup_list=followup_messages, is_my_vote=is_my_vote, is_my_flag=is_my_flag, team_notes_metadata=team_notes_metadata, team_notes=self.team_notes, engaged_users=engaged_users, archived=self.archived) return anno_message
def anno_get(self, request): """ Exposes an API endpoint to get an anno detail by the specified id. """ try: user = auth_user(self.request_state.headers) except Exception: user = None if request.id is None: raise endpoints.BadRequestException('id field is required.') anno = Anno.get_by_id(request.id) if anno is None: raise endpoints.NotFoundException('No anno entity with the id "%s" exists.' % request.id) # set anno basic properties anno_resp_message = anno.to_response_message(user, list_message=False) # set anno association with followups followups = FollowUp.find_by_anno(anno) followup_messages = [ entity.to_message(team_key=request.team_key) for entity in followups ] anno_resp_message.followup_list = followup_messages # set anno association with votes/flags # if current user exists, then fetch vote/flag. if user is not None: anno_resp_message.is_my_vote = Vote.is_belongs_user(anno, user) anno_resp_message.is_my_flag = Flag.is_belongs_user(anno, user) # update last_read of UserAnnoState UserAnnoState.update_last_read(user=user, anno=anno) return anno_resp_message