Esempio n. 1
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
Esempio n. 2
0
    def action_view(self, http_request, selected_instances):
        members = selected_instances
        if http_request.method == 'POST':
            form = MemberSendMessageForm(http_request.POST,
                                         http_request=http_request)
            if form.is_valid():
                subject = form.cleaned_data.get('subject')
                body = form.cleaned_data.get('body')
                is_sms = form.cleaned_data.get('is_sms')
                is_mail = form.cleaned_data.get('is_mail')
                receivers = [member.user for member in members]
                Message.send_message(http_request.user,
                                     u"پیام دریافتی از مدیریت سیستم", body,
                                     receivers)
                if is_mail:
                    receivers_mail = [user.email for user in receivers]
                    message_text = MessageServices.get_send_message(
                        http_request.user, subject, body)
                    MessageServices.send_mass_message(subject, message_text,
                                                      receivers_mail)
                if is_sms:
                    mobiles = [member.mobile for member in members]
                    if mobiles:
                        SMSService.send_sms(subject + '\n' + body, mobiles)
                form = None
                messages.success(http_request, u"پیام شما با موفقیت انجام شد.")
        else:
            form = MemberSendMessageForm(http_request=http_request)

        return render_to_response(
            'manager/actions/add_edit.html', {
                'form': form,
                'title': u"ارسال پیام"
            },
            context_instance=RequestContext(http_request))
Esempio n. 3
0
    def action_view(self, http_request, selected_instances):
        members = selected_instances
        if http_request.method == 'POST':
            form = MemberSendMessageForm(http_request.POST, http_request=http_request)
            if form.is_valid():
                subject = form.cleaned_data.get('subject')
                body = form.cleaned_data.get('body')
                is_sms = form.cleaned_data.get('is_sms')
                is_mail = form.cleaned_data.get('is_mail')
                receivers = [member.user for member in members]
                Message.send_message(http_request.user, u"پیام دریافتی از مدیریت سیستم", body, receivers)
                if is_mail:
                    receivers_mail = [user.email for user in receivers]
                    message_text = MessageServices.get_send_message(http_request.user, subject, body)
                    MessageServices.send_mass_message(subject, message_text, receivers_mail)
                if is_sms:
                    mobiles = [member.mobile for member in members]
                    if mobiles:
                        SMSService.send_sms(subject + '\n' + body, mobiles)
                form = None
                messages.success(http_request, u"پیام شما با موفقیت انجام شد.")
        else:
            form = MemberSendMessageForm(http_request=http_request)

        return render_to_response('manager/actions/add_edit.html', {'form': form, 'title': u"ارسال پیام"},
                                  context_instance=RequestContext(http_request))
Esempio n. 4
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
Esempio n. 5
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
Esempio n. 6
0
    def save(self, commit=True):
        message = super(AdminMessageForm, self).save(commit=False)
        message.sender = self.user
        message.save()

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

        if send_type == 1:
            receivers = User.objects.all()
        elif send_type == 2:
            receivers = User.objects.filter(member__isnull=False)
        elif send_type == 3:
            receivers = User.objects.filter(
                member__id__in=Cluster.objects.filter().values_list('head',
                                                                    flat=True))
        elif send_type == 5:
            receivers = User.objects.filter(arbiter__isnull=False)
        elif send_type == 4:
            receivers = self.cleaned_data.get('member_receivers')
        elif send_type == 6:
            receivers = self.cleaned_data.get('arbiter_receivers')
        else:
            receivers = []

        message.receivers = receivers

        is_sms = self.cleaned_data.get('is_sms')
        is_mail = self.cleaned_data.get('is_mail')
        if receivers:
            for user in receivers:
                if is_mail:
                    message_text = MessageServices.get_send_message(
                        self.user, message.title, message.body)
                    MessageServices.send_message(
                        subject=u"پیام دریافتی از مدیریت سیستم",
                        message=message_text,
                        user=user)
                if is_sms:
                    mobile = None
                    if PermissionController.is_supervisor(user):
                        mobile = user.supervisor.mobile
                    elif PermissionController.is_arbiter(user):
                        mobile = user.arbiter.mobile
                    elif PermissionController.is_member(user):
                        mobile = user.member.mobile
                    if mobile:
                        SMSService.send_sms(
                            message.title + '\n' + message.body, [mobile])
        return message
Esempio n. 7
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
Esempio n. 8
0
    def save(self, commit=True):
        message = super(AdminMessageForm, self).save(commit=False)
        message.sender = self.user
        message.save()

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

        if send_type == 1:
            receivers = User.objects.all()
        elif send_type == 2:
            receivers = User.objects.filter(member__isnull=False)
        elif send_type == 3:
            receivers = User.objects.filter(member__id__in=Cluster.objects.filter().values_list('head', flat=True))
        elif send_type == 5:
            receivers = User.objects.filter(arbiter__isnull=False)
        elif send_type == 4:
            receivers = self.cleaned_data.get('member_receivers')
        elif send_type == 6:
            receivers = self.cleaned_data.get('arbiter_receivers')
        else:
            receivers = []

        message.receivers = receivers

        is_sms = self.cleaned_data.get('is_sms')
        is_mail = self.cleaned_data.get('is_mail')
        if receivers:
            for user in receivers:
                if is_mail:
                    message_text = MessageServices.get_send_message(self.user, message.title, message.body)
                    MessageServices.send_message(subject=u"پیام دریافتی از مدیریت سیستم",
                                                 message=message_text, user=user)
                if is_sms:
                    mobile = None
                    if PermissionController.is_supervisor(user):
                        mobile = user.supervisor.mobile
                    elif PermissionController.is_arbiter(user):
                        mobile = user.arbiter.mobile
                    elif PermissionController.is_member(user):
                        mobile = user.member.mobile
                    if mobile:
                        SMSService.send_sms(message.title + '\n' + message.body, [mobile])
        return message