def get_data(self): data = super().get_data() user_wrapper = UserWrapper(user=self.applicant.user) data.update({ 'applicant_name': user_wrapper.get_full_name(), }) return data
def send_email(self, user, conversations, period): user_wrapper = UserWrapper(user=user) data = {} if period == DAILY: data['subject_args'] = {'period': 'Daily'} else: data['subject_args'] = {'period': 'Weekly'} data['total'] = sum(map(lambda x: x[1].count(), conversations)) data['name'] = user_wrapper.get_full_name() data['conversations'] = [] for conversation, messages in conversations: url, related_title = get_info_related(conversation, user) data_conversation = {} data_conversation['total'] = messages.count() data_conversation['message'] = messages.first().message data_conversation['url'] = url title = CONVERSATION_TITLE.get( conversation._type).format(related_title) data_conversation['title'] = title data['conversations'].append(data_conversation) data['recipients'] = [user_wrapper.email] status = mail_handler.send_mail(template=EMAIL_NAME, **data) if not status: logger.error('Error sending email to: {}'.format(data)) raise Exception('Error sending email to: {}'.format(data))
def create_conversation(opportunity, users): user_from = users[-1] user_wrapper = UserWrapper(user=user_from) icon = user_wrapper.profile_picture[1][1] group_name = user_wrapper.get_full_name() users_to = [add_user(user) for user in users] return group_name, users_to, icon
def get_data(self): data = super().get_data() user_wrapper = UserWrapper(user=self.opportunity.created_by) data.update({ 'created_by_profile_picture': user_wrapper.get_profile_picture(settings.LARGE_IMAGE_SIZE), 'created_by_name': user_wrapper.full_name, 'created_by_role': user_wrapper.user_title, 'public_url': self.opportunity.url_public, 'budget_string': self.opportunity.budget_string, 'num_positions': self.opportunity.num_positions, 'description': self.opportunity.description, 'entity_name': self.opportunity.entity, 'location_string': self.opportunity.location_string, 'start_date': self.opportunity.start_date.strftime('%d %b, %Y') if self.opportunity.start_date else '', 'duration': self.opportunity.duration, 'tags': list(self.opportunity.keywords.all().values_list('name', flat=True)), 'reply_to': [ user_wrapper.email, ], }) return data
def write_data(self, worksheet, user_from, team_step, row, sheet_name): worksheet.write(row, 0, team_step.project.name) worksheet.write(row, 1, team_step.team.name) if sheet_name == self.SHEET_TEAM: coaches = team_step.team.coaches names = [] for coach in coaches: names.append(UserWrapper(user=coach).get_full_name()) worksheet.write(row, 2, ', '.join(names)) worksheet.write(row, 3, UserWrapper(user=user_from).get_full_name()) elif sheet_name == self.SHEET_COACH: names = [] for user in self.project.users_with_admin_perm(): names.append(UserWrapper(user=user).get_full_name()) worksheet.write(row, 2, ', '.join(names)) coaches = team_step.team.coaches names = [] for coach in coaches: names.append(UserWrapper(user=coach).get_full_name()) worksheet.write(row, 3, ', '.join(names)) worksheet.write(row, 4, team_step.step.name) worksheet.write(row, 5, team_step.get_rating_for_user(user_from)) user_feedback = team_step.get_feedback_for_user(user_from) worksheet.write(row, 6, user_feedback) last_feedback = team_step.get_last_action_feedback( user=user_from, verb=settings.TEAM_ACTION_COMMENT_WEEKLY, ) worksheet.write(row, 7, last_feedback.description if last_feedback else '-')
def get_speakers(self, obj): data = [] speakers = obj.participants.filter_by_role_name( settings.EVENT_SPEAKER_NAME) for participant in speakers: user_wrapper = UserWrapper(user=participant.user) value = { 'name': user_wrapper.get_full_name(), 'profile_url': '{}{}'.format( settings.DOMAIN_NAME, user_wrapper.profile_url, ), 'bio': user_wrapper.bio_me, 'linkedin': user_wrapper.linkedin, 'profile_picture': user_wrapper.profile_picture_96, 'title': user_wrapper.user_title } data.append(value) return data
def get_data(self): data = super().get_data() user_wrapper = UserWrapper(user=self.applicant.user) answers = [ { 'question': answer.question.title, 'response': answer.response, 'response_text': answer.response_text } for answer in self.applicant.answers.all() ] data.update({ 'applicant_profile_picture': user_wrapper.get_profile_picture(settings.LARGE_IMAGE_SIZE), 'applicant_name': user_wrapper.get_full_name(), 'applicant_role': user_wrapper.user_title, 'summary': self.applicant.summary, 'questions_extra_info': self.applicant.questions_extra_info, 'applicant_email': user_wrapper.email, 'applicant_profile_url': user_wrapper.profile_url, 'public_url': self.opportunity.admin_url_public, 'answers': answers, 'reply_to': [ user_wrapper.email, ], }) return data
def get_info_related(conversation, user_from): if conversation._type == settings.CONVERSATIONS_CH_USER: other_user = conversation.users.exclude(user=user_from).first() user_wrapper = UserWrapper(user=other_user) url = user_wrapper.profile_url title = user_wrapper.get_full_name() elif conversation._type == settings.CONVERSATIONS_CH_PROJECT: project_uuid = conversation.uuid_related_object response = get_info_core_project(user_from, project_uuid) url = response['chatUrl'] title = '{} ({})'.format(response['name'], conversation.name) elif conversation._type == settings.CONVERSATIONS_CH_EXO_PROJECT: project_uuid = conversation.uuid_related_object response = get_info_exo_project(user_from, project_uuid) url = response['chatUrl'] title = '{} ({})'.format(response['name'], conversation.name) elif conversation._type == settings.CONVERSATIONS_CH_OPPORTUNITIES: opportunity_uuid = conversation.uuid_related_object response = get_info_opportunities(user_from, opportunity_uuid) url = response['chatUrl'] title = response['title'] return url, title
def get_data(self): data = super().get_data() user_wrapper = UserWrapper(user=self.user) data.update({ 'applicant_name': user_wrapper.get_full_name(), 'public_url': settings.OPPORTUNITIES_PUBLIC_URL, }) return data
def add_user(user, project, team=None): user_wrapper = UserWrapper(user=user) return { 'name': user_wrapper.get_full_name(), 'profile_picture': user_wrapper.profile_picture[1][1], 'short_title': get_user_title_in_project(project, user, team), 'profile_url': user_wrapper.profile_url, 'user_uuid': str(user.uuid), }
def get_data(self, opportunity, user): data = {} user_wrapper = UserWrapper(user=user) data['user_from_full_name'] = user_wrapper.get_full_name() data['user_from_title'] = user_wrapper.userTitle data['user_from_profile_picture'] = user_wrapper.profilePicture[1][1] data['title'] = '{} started a new conversation related to {}'.format( user_wrapper.get_full_name(), opportunity.title) return data
def get_data(self): user_wrapper = UserWrapper(user=self.opportunity.created_by) return { 'title': self.opportunity.title, 'created_by_profile_picture': user_wrapper.get_profile_picture(settings.MEDIUM_IMAGE_SIZE), 'created_by_name': user_wrapper.get_full_name(), 'created_by_role': user_wrapper.user_title, 'role': self.opportunity.role_string, 'category_code': self.opportunity.category.code, }
def get_feedback_from_objects(team_step, objects): results = [] sum_rate = 0 sum_feelings = 0 sum_comments = 0 average_rate = 0 average_feeling = 0 total_reviews = 0 total_reviewers = objects.count() for user in objects: comment = None rate = team_step.get_rating_for_user(user) feeling = team_step.get_feedback_for_user(user) if rate and feeling: total_reviews += 1 sum_rate += rate sum_feelings += feeling last_feedback_action = team_step.get_last_action_feedback( user=user, verb=settings.TEAM_ACTION_COMMENT_WEEKLY) if last_feedback_action and last_feedback_action.description: sum_comments += 1 comment = { 'text': last_feedback_action.description, 'date': last_feedback_action.timestamp, } user_wrapper = UserWrapper(user=user) result = { 'fullName': user_wrapper.get_full_name(), 'thumbnail': user_wrapper.profile_picture_96, 'feeling': team_step.get_feedback_for_user(user), 'rate': team_step.get_rating_for_user(user), 'comment': comment, } results.append(result) if total_reviews: average_rate = round(sum_rate / total_reviews, 1) average_feeling = round(sum_feelings / total_reviews, 0) data = { 'average_rate': average_rate, 'average_feelings': average_feeling, 'total_reviewers': total_reviewers, 'total_comments': sum_comments, 'results': results, } return data
def run(self, user_uuid, *args, **kwargs): user_wrapper = UserWrapper(uuid=user_uuid) mail_kwargs = { 'user_full_name': user_wrapper.get_full_name(), 'user_profile_url': user_wrapper.profile_url, 'comments': kwargs.get('comment', ''), } mail_handler.send_mail( template='event_summit_notification', recipients=[settings.EVENT_SUMMIT_DISTRIBUTION_LIST_EMAIL], **mail_kwargs, )
def add_user(user): if isinstance(user, dict): uuid = user['uuid'].__str__() user_wrapper = UserWrapper(uuid) else: user_wrapper = UserWrapper(user=user) uuid = user.uuid.__str__() return { 'name': user_wrapper.get_full_name(), 'profile_picture': user_wrapper.profile_picture[1][1], 'short_title': user_wrapper.user_title, 'profile_url': user_wrapper.profile_url, 'user_uuid': uuid, }
def get_data(self): data = super().get_data() user_wrapper = UserWrapper(user=self.user) data.update({ 'location': self.project.location, 'user_name': user_wrapper.get_full_name(), 'email': user_wrapper.email, 'public_url': self.project.url_zone(self.user), 'subject_args': { 'name': self.project.name, } }) return data
def test_simple(self, m): self.init_mock(m) request_mock_account.add_mock(self.super_user, is_consultant=False, is_superuser=True) user_wrapper = UserWrapper(user=self.super_user) self.assertTrue(user_wrapper.is_superuser)
def get_users_tagged(self, obj): response = [] for user_tagged in obj.users_tagged.all(): user = user_tagged.user user_wrapper = UserWrapper(user=user) response.append(UserSerializer(user_wrapper).data) return response
def get_contracting_data(user): data = {} url = URL_CONTRACTING_DATA.format(user.uuid.__str__()) url = '{}{}'.format( settings.EXOLEVER_HOST, url) logger.info('Calling to contracting data') if settings.POPULATOR_MODE: return {} try: response = requests.get( url, headers={'USERNAME': settings.AUTH_SECRET_KEY}) except Exception as err: message = 'requests.Exception: {}'.format(err) logger.error(message) response = None raise err if response and response.status_code == requests.codes.ok: response_data = response.json() if not response_data.get('name'): response_data['name'] = UserWrapper(user=user).get_full_name() data = response_data.copy() return data
def run(self, *args, **kwargs): opportunity_pk = kwargs.get('pk') user_pk = kwargs.get('user_pk') email_name = settings.OPPORTUNITIES_MAIL_VIEW_APPLICANT_NOT_SELECTED try: opp = Opportunity.objects.get(pk=opportunity_pk) except Opportunity.DoesNotExist: logger.error('Opportunity does not exist') raise Exception() try: user = get_user_model().objects.get(pk=user_pk) except get_user_model().DoesNotExist: logger.error('Applicant does not exist') raise Exception() user_wrapper = UserWrapper(user=user) try: data = ApplicantNotSelected(opp, user).get_data() except Exception as err: logger.error( 'Applicant not selected data exception: {}'.format(err)) raise Exception() data['recipients'] = [user_wrapper.email] status = mail_handler.send_mail(template=email_name, **data) if not status: logger.error('Error sending email to: {}'.format(data)) raise Exception()
def can_apply(self, user_from, raise_exception=True): # Return true if user_from can apply for this opportunity # user is a consultant # user can't apply twice if settings.POPULATOR_MODE: return True user_wrapper = UserWrapper(user=user_from) user_is_consultant = user_wrapper.is_consultant user_can_apply = user_is_consultant opportunity_is_visible = not (self.is_draft or self.is_removed) not_applied_yet = not self.get_applicants_for_user(user_from).exists() opportunity_can_be_applied = not self.status > settings.OPPORTUNITIES_CH_REQUESTED if self.is_opened: can_do_action = not_applied_yet and opportunity_can_be_applied else: user_is_tagged = self.users_tagged.filter(user=user_from).exists() can_do_action = not_applied_yet and opportunity_can_be_applied and user_is_tagged result = user_can_apply and opportunity_is_visible and can_do_action if not result and raise_exception: raise ValidationError("User can't apply for this opportunity") return result
def run(self, *args, **kwargs): opportunity_pk = kwargs.get('pk') user_pk = kwargs.get('user_pk') comment = kwargs.get('comment') email_name = settings.OPPORTUNITIES_MAIL_VIEW_CLOSED_MANUALLY try: opp = Opportunity.objects.get(pk=opportunity_pk) except Opportunity.DoesNotExist: logger.error('Opportunity does not exist') raise Exception() try: user = User.objects.get(id=user_pk) except User.DoesNotExist: logger.error('User does not exist') raise Exception() user_wrapper = UserWrapper(user=user) try: data = ApplicantNotSelected(opp, user).get_data() except Exception as err: logger.error( 'Applicant not selected data exception: {}'.format(err)) raise Exception() data['recipients'] = [user_wrapper.email] if comment is not None: data['comment'] = comment status = mail_handler.send_mail(template=email_name, **data) if not status: logger.error('Error sending email to: {}'.format(data)) raise Exception()
def user_actions(self, user_from, remove_admin_actions=False): actions = [] user_wrapper = UserWrapper(user=user_from) user_with_actions = user_wrapper.is_consultant \ or user_wrapper.is_superuser \ or user_wrapper.is_delivery_manager \ or user_from in self.admin_users if not user_with_actions: return actions admin_perms = user_from.is_superuser or\ user_wrapper.is_delivery_manager or\ user_from in self.admin_users if self.is_draft and admin_perms: actions.extend(settings.OPPORTUNITIES_ACTION_CH_SEND) elif self.is_requested: can_apply = self.can_apply(user_from, raise_exception=False) if can_apply: actions.extend(settings.OPPORTUNITIES_ACTION_CH_APPLY_OPEN) if admin_perms: actions.extend(settings.OPPORTUNITIES_ACTION_CH_EDIT) actions.extend(settings.OPPORTUNITIES_ACTION_CH_CLOSE) actions.extend(settings.OPPORTUNITIES_ACTION_CH_REMOVE) elif self.is_closed: if admin_perms: actions.extend(settings.OPPORTUNITIES_ACTION_CH_RE_OPEN) if remove_admin_actions: actions = list( set(actions) - set(settings.OPPORTUNITIES_ADMIN_ACTIONS)) return actions
def get_data(self): data = super().get_data() user_wrapper = UserWrapper(user=self.user) data.update({ 'start_date': self.project.start.strftime('%d-%m-%Y'), 'user_name': user_wrapper.get_full_name(), 'email': user_wrapper.email, 'public_url': self.project.url_zone(self.user), 'subject_args': { 'name': self.project.name, 'start_date': self.project.start.strftime('%d-%m-%Y'), } }) return data
def get_data(self): data = super().get_data() user_wrapper = UserWrapper(user=self.applicant.user) file = self.applicant.get_ics_event() data.update({ 'applicant_name': user_wrapper.get_full_name(), 'comment': self.applicant.response_message, 'public_url': '/ecosystem/opportunities/{}'.format(self.opportunity.pk), 'opportunity_url': '/ecosystem/opportunities/{}'.format(self.opportunity.pk), 'start_date_full': self.applicant.start_date_full, 'attachments': [file] if file else [], }) return data
def get_file(self, applicants): output = io.StringIO() writer = csv.writer(output) writer.writerow([ 'Title', 'Role', 'ID', 'Created by', 'Applicant Selected', 'Opportunity Status', 'Applicant status' ]) for app in applicants: opportunity = app.opportunity created = UserWrapper(user=opportunity.created_by).get_full_name() applicant = UserWrapper(user=app.user).get_full_name() writer.writerow([ opportunity.title, opportunity.role_string, opportunity.id, created, applicant, opportunity.get_status_display(), app.get_status_display() ]) return output.getvalue()
def get_data(self): data = super().get_data() user_wrapper = UserWrapper(user=self.user) roles = self.user.user_team_roles.filter(team=self.team).values_list( 'team_role__role', flat=True) roles = ', '.join(list(roles)) data.update({ 'roles': roles, 'team_name': self.team.name, 'user_name': user_wrapper.get_full_name(), 'email': user_wrapper.email, 'public_url': self.project.url_zone(self.user), 'subject_args': { 'team_name': self.team.name, 'roles': roles, } }) return data
def user_status(self, user_from): user_wrapper = UserWrapper(user=user_from) user_is_consultant_and_can_apply = user_wrapper.is_consultant if self.is_applicant(user_from): return self.user_status_for_applicant(user_from) elif self.is_opened and user_is_consultant_and_can_apply: return settings.OPPORTUNITIES_CH_APPLICANT_DRAFT return self._status
def create(self, validated_data): event = validated_data.get('event') user_wrapper = UserWrapper(user=validated_data.get('user')) instance = Participant.objects.create( event=event, created_by=validated_data.get('user_from'), user=validated_data.get('user'), exo_role=validated_data.get('exo_role'), order=event.participants.count(), user_name=user_wrapper.get_full_name(), user_email=user_wrapper.email, ) OpportunityParticipant.objects.create( participant=instance, opportunity_uuid=validated_data.get('opportunity_uuid')) job = instance.job job.delete() Job.objects.update_or_create(participant=instance) return instance
def _serialize_user_by(self, user_by, date): user_wrapper = UserWrapper(user=user_by) return { 'created': date.isoformat(), 'user': { 'uuid': str(user_by.uuid), 'email': user_wrapper.email, 'fullName': user_wrapper.full_name, 'user_title': user_wrapper.user_title, } }