Exemplo n.º 1
0
    def _notify_project_message(self):
        """
        Send email to participants about new message in project.
        """
        tpl = 'projects/emails/project_message.html'

        # get all participants on this project, except the event creator.
        participants = UserProjectParticipant.objects \
            .select_related('user') \
            .filter(user_project=self.user_project, subscribed=True) \
            .exclude(user=self.event_user)

        notify = []
        emails = []
        for p in participants:
            to_user = p.user
            notify.append(feed_manager.get_notification_feed(to_user.pk))

            # check user notification settings
            if to_user.is_email_verified(
            ) and UserSetting.objects.email_notify_project_message(to_user):
                self.context.update({'to_user': to_user})
                msg = render_to_string(tpl, self.context)
                subject = f'[Proyek] Pesan dari @{self.event_user.username}'
                emails.append((subject, msg, FROM, [to_user.email]))

        # add to user feed and notify participants
        activity = feed_manager.add_notify_to_activity(self.activity, notify)
        feed_manager.add_activity(self.user_feed, activity)

        if emails and not self.is_sync:
            send_mass_mail(emails, fail_silently=True)
Exemplo n.º 2
0
    def _notify_review_request(self):
        """
        Send email to staff/project creator about project need a review.
        """
        tpl = 'projects/emails/project_review_request.html'

        # get all active staff except event_user
        participants = User.get_active_staffs(exclude_user=self.event_user)

        notify = [self.challenge_feed, self.challenge_feed_global]
        emails = []
        for staff in participants:
            notify.append(feed_manager.get_notification_feed(staff.pk))

            # check user notification settings
            if staff.is_email_verified(
            ) and UserSetting.objects.email_notify_project_review_request(
                    staff):
                self.context.update({'to_user': staff})
                msg = render_to_string(tpl, self.context)
                subject = f'[Proyek] Permintaan review dari @{self.event_user.username}'
                emails.append((subject, msg, FROM, [staff.email]))

        # add to user feed and notify staff
        activity = feed_manager.add_notify_to_activity(self.activity, notify)
        feed_manager.add_activity(self.user_feed, activity)

        # send emails
        if emails and not self.is_sync:
            send_mass_mail(emails, fail_silently=True)
Exemplo n.º 3
0
    def _notify_project_disapproved(self):
        """
        Send email to user who working on a project about their project status changed.
        """
        tpl = 'projects/emails/project_disapproved.html'
        user_project_owner = self.user_project.user

        # add to disapproving user and notify user project owner
        owner_notification_feed = feed_manager.get_notification_feed(
            user_project_owner.pk)
        activity = feed_manager.add_notify_to_activity(
            self.activity, owner_notification_feed)
        feed_manager.add_activity(self.user_feed, activity)

        # check user notification settings
        if not self.is_sync and user_project_owner.is_email_verified(
        ) and UserSetting.objects.email_notify_project_disapproved(
                user_project_owner):
            self.context.update({'to_user': user_project_owner})
            msg = render_to_string(tpl, self.context)
            subject = '[Proyek] Status proyek kamu diralat'
            send_mail(subject,
                      msg,
                      FROM, [user_project_owner.email],
                      fail_silently=True)
Exemplo n.º 4
0
 def _add_to_user_feed(self):
     """
     Add activity to global, individual challenge feed and user feed.
     """
     notify = [self.challenge_feed, self.challenge_feed_global]
     activity = feed_manager.add_notify_to_activity(self.activity, notify)
     feed_manager.add_activity(self.user_feed, activity=activity)
Exemplo n.º 5
0
    def _notify_project_approved(self):
        """
        Send email to user who working on a project about their project has been approved.
        """
        tpl = 'projects/emails/project_approved.html'
        user_project_owner = self.user_project.user

        notify = [self.challenge_feed, self.challenge_feed_global]
        activity = feed_manager.add_notify_to_activity(self.activity, notify)

        if user_project_owner == self.event_user:
            feed_manager.add_activity(self.user_feed, activity)
            return

        # add to approving user and notify user project owner
        activity = feed_manager.add_notify_to_activity(
            activity,
            feed_manager.get_notification_feed(user_project_owner.pk))
        feed_manager.add_activity(self.user_feed, activity)

        # check user notification settings
        if not self.is_sync and user_project_owner.is_email_verified(
        ) and UserSetting.objects.email_notify_project_approved(
                user_project_owner):
            self.context.update({'to_user': user_project_owner})
            msg = render_to_string(tpl, self.context)
            subject = '[Proyek] Proyek kamu telah disetujui!'
            send_mail(subject,
                      msg,
                      FROM, [user_project_owner.email],
                      fail_silently=True)