Ejemplo n.º 1
0
    def run(self, *args, **kwargs):
        try:
            user_from = get_user_model().objects.get(
                pk=kwargs.get('user_from_pk'))
        except get_user_model().DoesNotExist:
            logger.error('User from does not exist')
            raise Exception()

        try:
            user_to = get_user_model().objects.get(pk=kwargs.get('user_to_pk'))
        except get_user_model().DoesNotExist:
            logger.error('Other User created does not exist')
            raise Exception()

        data = {}
        data['user_from_full_name'] = user_from.get_full_name()
        data['user_from_title'] = user_from.user_title
        data[
            'user_from_profile_picture'] = user_from.profile_picture.get_thumbnail_url(
            )
        data['title'] = '{} started a new conversation'.format(
            user_from.get_full_name())
        data['disable_notification_url'] = UserProfileWrapper(
            user_to).account_url
        data['message'] = kwargs.get('message')
        data['public_url'] = settings.FRONTEND_MESSAGES_PAGE
        data['recipients'] = [user_to.email]
        handlers.mail_handler.send_mail(MAIL_CHAT_FIRST_MESSAGE, **data)
Ejemplo n.º 2
0
    def send_participant_summary_email(self):
        email_name = 'qa_session_summary'
        headers = self.get_data_reminder()
        for team in self.project.teams.all():
            session_team = self.teams.filter(team=team).first()
            if not session_team:
                continue
            url = session_team.url
            for user in team.team_members.all():
                recipients = [user.email]
                headers.update({
                    'recipients':
                    recipients,
                    'short_name':
                    user.short_name,
                    'public_url':
                    url,
                    'disable_notification_url':
                    UserProfileWrapper(user).account_url,
                })
                try:
                    rating = round(session_team.rating_average, 1)
                except TypeError:
                    rating = None

                data = {
                    'total_questions': session_team.questions.count(),
                    'your_answers':
                    session_team.total_answers_by_participant(user),
                    'rating': rating
                }
                headers.update(data)
                handlers.mail_handler.send_mail(email_name, **headers)
Ejemplo n.º 3
0
 def reminder_participant(self, one_day):
     if one_day:
         email_name = 'reminder_participant_tomorrow_qa_session'
     else:
         email_name = 'reminder_participant_one_hour_before_qa_session'
     headers = self.get_data_reminder()
     for team in self.project.teams.all():
         url = settings.FRONTEND_PROJECT_QUESTION_PAGE.format(
             **{
                 'project_id': self.project.pk,
                 'team_id': team.pk,
                 'section': 'swarm-session',
                 'pk': 'create',
             })
         for user in team.team_members.all():
             recipients = [user.email]
             headers.update({
                 'recipients':
                 recipients,
                 'short_name':
                 user.short_name,
                 'one_day':
                 one_day,
                 'disable_notification_url':
                 UserProfileWrapper(user).account_url,
                 'subject_args': {
                     'one_day': one_day
                 },
                 'public_url':
                 url
             })
             handlers.mail_handler.send_mail(email_name, **headers)
Ejemplo n.º 4
0
 def create(self, validated_data):
     user_from = self.context.get('user_from')
     user_to = validated_data.get('user')
     data = {
         'verb': settings.USER_PROFILE_ACTION_REQUEST_CONTACT,
         'action_object': user_to,
         'description': validated_data.get('comment'),
     }
     action.send(
         user_from,
         **data
     )
     handlers.mail_handler.send_mail(
         'request_user_contact',
         recipients=[user_to.email],
         short_name=user_to.short_name,
         requester_name=user_from.get_full_name(),
         requester_short_name=user_from.short_name,
         requester_email=user_from.email,
         user_title=user_from.user_title,
         requester_profile_picture=user_from.profile_picture.get_thumbnail_url(),
         requester_profile_url=UserProfileWrapper(user_from).profile_slug_url,
         comment=validated_data.get('comment'),
     )
     return validated_data
Ejemplo n.º 5
0
def show_picture(consultant, field):
    field_label = field.get('label').lower()
    if field_label == 'name':
        url = consultant.user.profile_picture.get_thumbnail_url(
            settings.EXO_ACCOUNTS_MEDIUM_IMAGE_SIZE,
            settings.EXO_ACCOUNTS_MEDIUM_IMAGE_SIZE,
        )
        image = """
            <img alt=\"{name}\" title=\"{name}\" class=\"img-circle\"
                src=\"{url}\" />""".format(name=consultant.user.full_name,
                                           url=url)
        content = mark_safe("<span class='l-h-34'>{} {}</span>".format(
            image,
            consultant.user.full_name,
        ))
        if not consultant.is_disabled:
            return mark_safe("<a data-action='stop' href='{}'>{}</a>".format(
                UserProfileWrapper(consultant.user).profile_slug_url,
                content,
            ))
        else:
            return content
    elif field_label == 'e-mail':
        return consultant.user.email
    elif field_label == 'location':
        return consultant.user.location or ''
    elif field_label == 'status':
        return consultant.status_detail
Ejemplo n.º 6
0
def add_user(user, project):
    return {
        'name': user.get_full_name(),
        'profile_picture': user.profile_picture.get_thumbnail_url(48, 48),
        'short_title': get_user_title_in_project(project, user),
        'profile_url': UserProfileWrapper(user).profile_slug_url,
        'user_uuid': str(user.uuid),
    }
Ejemplo n.º 7
0
def add_user(user):
    return {
        'name': user.get_full_name(),
        'profile_picture': user.profile_picture.get_thumbnail_url(48, 48),
        'short_title': user.user_title,
        'profile_url': UserProfileWrapper(user).profile_slug_url,
        'user_uuid': user.uuid.__str__(),
    }
Ejemplo n.º 8
0
 def new_question_reply(self, answer):
     email_name = 'ask_to_ecosystem_replied'
     user = self.created_by
     recipients = [user.email]
     headers_json = AskToEcosystemReplied(answer.post, answer).get_data()
     headers = {
         'recipients': recipients,
         'disable_notification_url': UserProfileWrapper(user).account_url,
     }
     headers.update(headers_json)
     handlers.mail_handler.send_mail(email_name, **headers)
Ejemplo n.º 9
0
def render_row(context, item):
    user = context.get('user')
    fields = get_fields()
    profile_url = UserProfileWrapper(user=item.user).profile_slug_url

    return {
        'fields': fields,
        'consultant': item,
        'profile_url': profile_url,
        'object_pk': item.pk,
        'user': user,
    }
Ejemplo n.º 10
0
 def new_announcement_created(self):
     email_name = 'post_announcement_created'
     for consultant in Consultant.objects.all():
         user = consultant.user
         recipients = [user.email]
         headers_json = PostAnnouncementCreated(self).get_data()
         headers = {
             'recipients': recipients,
             'disable_notification_url':
             UserProfileWrapper(user).account_url,
         }
         headers.update(headers_json)
         handlers.mail_handler.send_mail(email_name, **headers)
Ejemplo n.º 11
0
 def new_topic_created(self):
     email_name = 'post_circle_created'
     for user in followers(self.content_object):
         if user == self.created_by:
             continue
         recipients = [user.email]
         headers_json = PostCircleCreated(self).get_data()
         headers = {
             'recipients': recipients,
             'disable_notification_url':
             UserProfileWrapper(user).account_url
         }
         headers.update(headers_json)
         handlers.mail_handler.send_mail(email_name, **headers)
Ejemplo n.º 12
0
    def send_advisor_selected_email(self):
        email_name = 'qa_session_advisor_selected'
        headers = self.get_data_reminder()

        for advisor in self.members.all():
            user = advisor.consultant.user
            recipients = [user.email]
            headers.update({
                'recipients':
                recipients,
                'short_name':
                user.short_name,
                'disable_notification_url':
                UserProfileWrapper(user).account_url,
            })
            handlers.mail_handler.send_mail(email_name, **headers)
Ejemplo n.º 13
0
 def new_announcement_reply(self, answer):
     email_name = 'post_announcement_replied'
     user = self.created_by
     recipients = [user.email]
     recipients_cc = list(
         self.get_group_destinataries(
             settings.MAIL_SUPPORT_LIST_MAIL_GROUP, ))
     headers_json = PostAnnouncementReplied(answer.post, answer).get_data()
     headers = {
         'recipients': recipients,
         'short_name': user.short_name,
         'cc': recipients_cc,
         'disable_notification_url': UserProfileWrapper(user).account_url,
     }
     headers.update(headers_json)
     handlers.mail_handler.send_mail(email_name, **headers)
Ejemplo n.º 14
0
 def create_sprint(self, **kwargs):
     user_from = kwargs.pop('user_from')
     self.can_add_service(user_from)
     steps_default = self.model.get_steps()
     if 'duration' not in kwargs:
         kwargs['duration'] = steps_default.get('steps')
     if 'lapse' not in kwargs:
         kwargs['lapse'] = steps_default.get('lapse')
     partner = kwargs.pop('partner')
     kwargs['created_by'] = user_from
     kwargs['internal_organization'] = UserProfileWrapper(
         user_from).organization
     fastrack = super().create(**kwargs)
     if partner:
         fastrack.project_ptr.partner = partner
     return fastrack
Ejemplo n.º 15
0
 def new_question_created(self):
     email_name = 'ask_to_ecosystem_created'
     consultants = Consultant.objects.filter_consulting_enabled()
     for consultant in consultants:
         user = consultant.user
         if user == self.created_by:
             continue
         recipients = [user.email]
         headers_json = AskToEcosystemCreated(self).get_data()
         headers = {
             'recipients': recipients,
             'disable_notification_url':
             UserProfileWrapper(user).account_url,
         }
         headers.update(headers_json)
         handlers.mail_handler.send_mail(email_name, **headers)
Ejemplo n.º 16
0
    def create_sprint_automated(self, user_from, name, description, customer,
                                duration):
        SprintAutomated = apps.get_model(
            app_label='sprint_automated',
            model_name='SprintAutomated',
        )

        sprint_automated = SprintAutomated.objects.create(
            created_by=user_from,
            internal_organization=UserProfileWrapper(user_from).organization,
            lapse=settings.PROJECT_LAPSE_PERIOD,
            name=name,
            description=description,
            customer=customer,
            duration=duration)

        return sprint_automated
Ejemplo n.º 17
0
    def create_generic_project(self, user_from, name, customer, duration,
                               lapse):
        GenericProject = apps.get_model(
            app_label='generic_project',
            model_name='GenericProject',
        )

        generic_project = GenericProject.objects.create(
            created_by=user_from,
            internal_organization=UserProfileWrapper(user_from).organization,
            name=name,
            customer=customer,
            duration=duration,
            lapse=lapse,
        )

        return generic_project
Ejemplo n.º 18
0
    def post(self, request, format=None):
        serializer = self.get_serializer(data=request.data)
        if serializer.is_valid():
            search = serializer.data.get('search').lower()
            circle = Circle.objects.get(pk=serializer.data.get('circle_pk'))
            followers = Follow.objects.followers_qs(circle).filter(
                user__full_name__icontains=search)[:5]
            results = [{
                'type_object':
                'user',
                'name':
                follow.user.full_name,
                'uuid':
                follow.user.pk,
                'url':
                settings.DOMAIN_NAME +
                UserProfileWrapper(follow.user).profile_public_slug_url
            } for follow in followers]
            output_serializer = self.output_serializer_class(data=results,
                                                             many=True)
            if output_serializer.is_valid():
                data = output_serializer.data
                status_code = status.HTTP_200_OK
            else:
                data = output_serializer.errors
                status_code = status.HTTP_400_BAD_REQUEST

            response = Response(
                data=data,
                status=status_code,
            )

        else:
            response = Response(data=serializer.errors,
                                status=status.HTTP_400_BAD_REQUEST)

        return response
Ejemplo n.º 19
0
    def reminder_advisor(self, one_day):
        if one_day:
            email_name = 'reminder_advisor_tomorrow_qa_session'
        else:
            email_name = 'reminder_advisor_one_hour_before_qa_session'
        headers = self.get_data_reminder()

        for advisor in self.members.all():
            user = advisor.consultant.user
            recipients = [user.email]
            headers.update({
                'recipients':
                recipients,
                'short_name':
                user.short_name,
                'one_day':
                one_day,
                'disable_notification_url':
                UserProfileWrapper(user).account_url,
                'subject_args': {
                    'one_day': one_day
                },
            })
            handlers.mail_handler.send_mail(email_name, **headers)
Ejemplo n.º 20
0
 def _profile(self):
     return UserProfileWrapper(user=self.user)
Ejemplo n.º 21
0
 def get_profile_url(self, instance):
     return settings.DOMAIN_NAME + UserProfileWrapper(
         instance).profile_public_slug_url
Ejemplo n.º 22
0
 def get_is_staff(self, obj):
     user_wrapper = UserProfileWrapper(obj)
     return user_wrapper.is_openexo_member
Ejemplo n.º 23
0
 def get_url_view(self, obj):
     return UserProfileWrapper(obj).profile_slug_url
Ejemplo n.º 24
0
 def get_public_profile_v2(self):
     return UserProfileWrapper(self.user).profile_slug_url