コード例 #1
0
ファイル: forms.py プロジェクト: hamed1369/Cluster
    def save(self, commit=True):
        message = super(MemberMessageForm, self).save(commit=False)
        message.sender = self.user
        message.save()

        if not self.user.member.cluster:
            receivers = PermissionController.get_admins()
            message.receivers = receivers
            if receivers:
                for user in receivers:
                    message_text = MessageServices.get_send_message(self.user, message.title, message.body)
                    MessageServices.send_message(subject=u"پیام دریافتی سامانه",
                                                 message=message_text, user=user)
            return message

        send_type = int(self.cleaned_data.get('send_type'))

        if send_type == 7:
            receivers = PermissionController.get_admins()
        elif send_type == 8:
            receivers = User.objects.filter(member__in=self.user.member.cluster.members.filter().distinct())
            #receivers = self.user.member.cluster.members.filter().values_list('user', flat=True)
        else:
            receivers = self.cleaned_data.get('receivers')

        message.receivers = receivers

        if receivers:
            for user in receivers:
                message_text = MessageServices.get_send_message(self.user, message.title, message.body)
                MessageServices.send_message(subject=u"پیام دریافتی سامانه",
                                             message=message_text, user=user)
        return message
コード例 #2
0
    def save(self, commit=True):
        message = super(MemberMessageForm, self).save(commit=False)
        message.sender = self.user
        message.save()

        if not self.user.member.cluster:
            receivers = PermissionController.get_admins()
            message.receivers = receivers
            if receivers:
                for user in receivers:
                    message_text = MessageServices.get_send_message(
                        self.user, message.title, message.body)
                    MessageServices.send_message(
                        subject=u"پیام دریافتی سامانه",
                        message=message_text,
                        user=user)
            return message

        send_type = int(self.cleaned_data.get('send_type'))

        if send_type == 7:
            receivers = PermissionController.get_admins()
        elif send_type == 8:
            receivers = User.objects.filter(
                member__in=self.user.member.cluster.members.filter().distinct(
                ))
            #receivers = self.user.member.cluster.members.filter().values_list('user', flat=True)
        else:
            receivers = self.cleaned_data.get('receivers')

        message.receivers = receivers

        if receivers:
            for user in receivers:
                message_text = MessageServices.get_send_message(
                    self.user, message.title, message.body)
                MessageServices.send_message(subject=u"پیام دریافتی سامانه",
                                             message=message_text,
                                             user=user)
        return message
コード例 #3
0
ファイル: forms.py プロジェクト: hamed1369/Cluster
    def save(self, commit=True):
        message = super(ArbiterMessageForm, self).save(commit=False)
        message.sender = self.user
        message.save()

        receivers = PermissionController.get_admins()
        message.receivers = receivers
        if receivers:
            for user in receivers:
                message_text = MessageServices.get_send_message(self.user, message.title, message.body)
                MessageServices.send_message(subject=u"پیام دریافتی سامانه",
                                             message=message_text, user=user)
        return message
コード例 #4
0
ファイル: models.py プロジェクト: hamed1369/Cluster
    def check_milestones(cls):
        import datetime
        from cluster.message.models import Message

        two_days_later = datetime.date.today() + datetime.timedelta(days=2)
        milestones = ProjectMilestone.objects.filter(milestone_date__lte=two_days_later, is_announced=False)
        body = u"""
        موعد های طرح های زیر گذشته اند یا نزدیک هستند:
        """
        i = 1
        if not milestones:
            return

        admin_users = PermissionController.get_admins()

        for milestone in milestones:
            receiver = (
                milestone.project.single_member.user
                if milestone.project.single_member
                else milestone.project.cluster.head.user
            )
            receiver_mobile = (
                milestone.project.single_member.mobile
                if milestone.project.single_member
                else milestone.project.cluster.head.mobile
            )
            section = u"""
                 موعد  %s  مربوط به طرح %s  برای زمان  %s
            """ % (
                milestone.comment,
                milestone.project.title,
                gregorian_to_jalali(milestone.milestone_date),
            )
            Message.send_message(admin_users[0], title=u"موعدهای گذشته یا نزدیک", body=body, receivers=[receiver])
            message = MessageServices.get_title_body_message(title=u"موعد طرح زیر گذشته یا نزدیک است:", body=section)
            MessageServices.send_message(subject=u"موعد طرح", message=message, user=receiver)
            SMSService.send_sms(
                message=u"موعد طرح زیر گذشته یا نزدیک است:" + "\n" + section, to_numbers=[receiver_mobile]
            )
            body += "\n" + unicode(i) + u"- " + section.strip()
            i += 1
            milestone.is_announced = True
            milestone.save()
            if milestone.project.supervisor:
                MessageServices.send_message(
                    subject=u"موعد طرح", message=message, user=milestone.project.supervisor.user
                )

        # message = MessageServices.get_title_body_message(title=u"موعد های طرح های زیر گذشته اند یا نزدیک هستند:",
        #                                                 body=body)
        Message.send_message(admin_users[0], title=u"موعدهای گذشته یا نزدیک", body=body, receivers=admin_users)
コード例 #5
0
    def check_milestones(cls):
        import datetime
        from cluster.message.models import Message

        two_days_later = datetime.date.today() + datetime.timedelta(days=2)
        milestones = ProjectMilestone.objects.filter(
            milestone_date__lte=two_days_later, is_announced=False)
        body = u"""
        موعد های طرح های زیر گذشته اند یا نزدیک هستند:
        """
        i = 1
        if not milestones:
            return

        admin_users = PermissionController.get_admins()

        for milestone in milestones:
            receiver = milestone.project.single_member.user if milestone.project.single_member else milestone.project.cluster.head.user
            receiver_mobile = milestone.project.single_member.mobile if milestone.project.single_member else milestone.project.cluster.head.mobile
            section = u"""
                 موعد  %s  مربوط به طرح %s  برای زمان  %s
            """ % (milestone.comment, milestone.project.title,
                   gregorian_to_jalali(milestone.milestone_date))
            Message.send_message(admin_users[0],
                                 title=u"موعدهای گذشته یا نزدیک",
                                 body=body,
                                 receivers=[receiver])
            message = MessageServices.get_title_body_message(
                title=u"موعد طرح زیر گذشته یا نزدیک است:", body=section)
            MessageServices.send_message(subject=u"موعد طرح",
                                         message=message,
                                         user=receiver)
            SMSService.send_sms(message=u"موعد طرح زیر گذشته یا نزدیک است:" +
                                '\n' + section,
                                to_numbers=[receiver_mobile])
            body += '\n' + unicode(i) + u'- ' + section.strip()
            i += 1
            milestone.is_announced = True
            milestone.save()
            if milestone.project.supervisor:
                MessageServices.send_message(
                    subject=u"موعد طرح",
                    message=message,
                    user=milestone.project.supervisor.user)

        #message = MessageServices.get_title_body_message(title=u"موعد های طرح های زیر گذشته اند یا نزدیک هستند:",
        #                                                 body=body)
        Message.send_message(admin_users[0],
                             title=u"موعدهای گذشته یا نزدیک",
                             body=body,
                             receivers=admin_users)
コード例 #6
0
    def save(self, commit=True):
        message = super(ArbiterMessageForm, self).save(commit=False)
        message.sender = self.user
        message.save()

        receivers = PermissionController.get_admins()
        message.receivers = receivers
        if receivers:
            for user in receivers:
                message_text = MessageServices.get_send_message(
                    self.user, message.title, message.body)
                MessageServices.send_message(subject=u"پیام دریافتی سامانه",
                                             message=message_text,
                                             user=user)
        return message