Esempio n. 1
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. 2
0
def handle_register_view(request, cluster_id=None):
    try:
        register_handler = ClusterHandler(request, cluster_id)
    except Cluster.DoesNotExist:
        raise Http404
    message = register_handler.has_permission()
    if message:
        messages.error(request, message)
        return render_to_response("show_message.html", {}, context_instance=RequestContext(request))

    register_handler.initial_forms()
    if register_handler.is_valid_forms():
        member = register_handler.save_forms()
        subject = u"ثبت نام شما با موفقیت انجام شد."
        message_body = (
            u"توجه داشته باشید که تا زمان تاییدشدن عضویت شما توسط مدیر سامانه ، نمیتوانید طرحی را در سامانه ثبت کنید ."
        )
        message = MessageServices.get_title_body_message(subject, message_body)
        MessageServices.send_message(u"ثبت نام در سامانه موسسه  نگاه نو", message, member.user)
        SMSService.send_sms(subject + "\n" + message_body, [member.mobile])

        messages.success(request, u"ثبت نام شما با موفقیت انجام شد.")
        if request.user.is_authenticated():
            return HttpResponseRedirect(reverse("edit_accounts"))
        return HttpResponseRedirect(reverse("login"))

    context = register_handler.get_context()
    return render_to_response("registration/register.html", context, context_instance=RequestContext(request))
Esempio n. 3
0
    def action_view(self, http_request, selected_instances):
        if http_request.method == 'POST':
            form = ArbiterInvitationForm(http_request.POST)
            if form.is_valid():
                import random
                import string
                import urllib

                title = form.cleaned_data.get('title')
                email = form.cleaned_data.get('email')
                #message = form.cleaned_data.get('message')

                invitation_key = ''.join(
                    random.choice(string.letters + string.digits + '(_)./,;][=+') for x in range(50))

                Arbiter.objects.create(invited=True, invitation_key=invitation_key, is_confirmed=True)

                message = MessageServices.get_arbiter_invitation_message(title,
                                                                         urllib.quote(invitation_key))
                MessageServices.send_message(u"دعوت از شما برای داوری", message, email=email)

                form = None
                messages.success(http_request, u"دعوت داور با موفقیت انجام شد.")
        else:
            form = ArbiterInvitationForm()

        return render_to_response('manager/actions/add_edit.html', {'form': form, 'title': u"دعوت داور"},
                                  context_instance=RequestContext(http_request))
Esempio n. 4
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. 5
0
def handle_register_view(request, cluster_id=None):
    try:
        register_handler = ClusterHandler(request, cluster_id)
    except Cluster.DoesNotExist:
        raise Http404
    message = register_handler.has_permission()
    if message:
        messages.error(request, message)
        return render_to_response('show_message.html', {},
                                  context_instance=RequestContext(request))

    register_handler.initial_forms()
    if register_handler.is_valid_forms():
        member = register_handler.save_forms()
        subject = u"ثبت نام شما با موفقیت انجام شد."
        message_body = u"توجه داشته باشید که تا زمان تاییدشدن عضویت شما توسط مدیر سامانه ، نمیتوانید طرحی را در سامانه ثبت کنید ."
        message = MessageServices.get_title_body_message(subject, message_body)
        MessageServices.send_message(u"ثبت نام در سامانه موسسه  نگاه نو",
                                     message, member.user)
        SMSService.send_sms(subject + '\n' + message_body, [member.mobile])

        messages.success(request, u"ثبت نام شما با موفقیت انجام شد.")
        if request.user.is_authenticated():
            return HttpResponseRedirect(reverse('edit_accounts'))
        return HttpResponseRedirect(reverse('login'))

    context = register_handler.get_context()
    return render_to_response('registration/register.html',
                              context,
                              context_instance=RequestContext(request))
Esempio n. 6
0
def on_no_cluster_member_confirm_change(instance, confirm):
    if confirm:
        message_body = u"وضعیت عضویت شما به تاییدنشده تغییر یافت."
        message = MessageServices.get_title_body_message(u"تغییر وضعیت عضویت", message_body)
    else:
        message_body = u"وضعیت عضویت شما به تاییدشده تغییر یافت."
        message = MessageServices.get_title_body_message(u"تایید عضویت", message_body)
    MessageServices.send_message(u"تغییر وضعیت خوشه", message, instance.user)
    SMSService.send_sms(message, [instance.mobile])
Esempio n. 7
0
def on_no_cluster_member_confirm_change(instance, confirm):
    if confirm:
        message_body = u"وضعیت عضویت شما به تاییدنشده تغییر یافت."
        message = MessageServices.get_title_body_message(
            u"تغییر وضعیت عضویت", message_body)
    else:
        message_body = u"وضعیت عضویت شما به تاییدشده تغییر یافت."
        message = MessageServices.get_title_body_message(
            u"تایید عضویت", message_body)
    MessageServices.send_message(u"تغییر وضعیت خوشه", message, instance.user)
    SMSService.send_sms(message, [instance.mobile])
Esempio n. 8
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. 9
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)
Esempio n. 10
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)
Esempio n. 11
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. 12
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. 13
0
def member_confirm_change(instance, confirm):
    if confirm is True:
        message_body = u"عضویت شما تایید شد.\n هم اکنون شما میتوانید در سامانه فعالیت داشته باشید."
        message = MessageServices.get_title_body_message(u"تایید عضویت", message_body)
    elif confirm is False:
        if instance.gender == 1:
            message_body = u"آقای "
        else:
            message_body = u"خانم "
        message_body += u"%s ضمن قدردانی از بذل توجه شما به این موسسه و ثبت نام در سامانه، متاسفانه عضویت شما در سامانه مورد موافقت موسسه قرار نگرفته است.  با آرزوی موفقیت و سلامتی برای شما دوست عزیز." % unicode(
            instance)
        message = MessageServices.get_title_body_message(u"رد عضویت", message_body)
    else:
        message_body = u"وضعیت عضویت شما به نامشخص تغییر یافت."
        message = MessageServices.get_title_body_message(u"تغییر وضعیت عضویت", message_body)
    MessageServices.send_message(u"تغییر وضعیت عضویت", message, instance.user)
Esempio n. 14
0
    def action_view(self, http_request, selected_instances):
        if not PermissionController.is_admin(http_request.user):
            raise Http404
        if http_request.method == 'POST':
            form = EmailSendForm(http_request.POST)
            if form.is_valid():
                email = form.cleaned_data.get('email')
                receivers = form.cleaned_data.get('receivers')
                subject = form.cleaned_data.get('subject')
                body = form.cleaned_data.get('body')
                MessageServices.send_mass_message(subject, body, receivers,email)
                form = None
                messages.success(http_request, u"پست الکترونیک ارسال شد.")
        else:
            form = EmailSendForm()

        return render_to_response('manager/actions/add_edit.html', {'form': form, 'title': u"ارسال پیام"},
                                  context_instance=RequestContext(http_request))
Esempio n. 15
0
def member_confirm_change(instance, confirm):
    if confirm is True:
        message_body = u"عضویت شما تایید شد.\n هم اکنون شما میتوانید در سامانه فعالیت داشته باشید."
        message = MessageServices.get_title_body_message(
            u"تایید عضویت", message_body)
    elif confirm is False:
        if instance.gender == 1:
            message_body = u"آقای "
        else:
            message_body = u"خانم "
        message_body += u"%s ضمن قدردانی از بذل توجه شما به این موسسه و ثبت نام در سامانه، متاسفانه عضویت شما در سامانه مورد موافقت موسسه قرار نگرفته است.  با آرزوی موفقیت و سلامتی برای شما دوست عزیز." % unicode(
            instance)
        message = MessageServices.get_title_body_message(
            u"رد عضویت", message_body)
    else:
        message_body = u"وضعیت عضویت شما به نامشخص تغییر یافت."
        message = MessageServices.get_title_body_message(
            u"تغییر وضعیت عضویت", message_body)
    MessageServices.send_message(u"تغییر وضعیت عضویت", message, instance.user)
Esempio n. 16
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. 17
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. 18
0
    def action_view(self, http_request, selected_instances):
        if http_request.method == 'POST':
            form = ArbiterInvitationForm(http_request.POST)
            if form.is_valid():
                import random
                import string
                import urllib

                title = form.cleaned_data.get('title')
                email = form.cleaned_data.get('email')
                #message = form.cleaned_data.get('message')

                invitation_key = ''.join(
                    random.choice(string.letters + string.digits +
                                  '(_)./,;][=+') for x in range(50))

                Arbiter.objects.create(invited=True,
                                       invitation_key=invitation_key,
                                       is_confirmed=True)

                message = MessageServices.get_arbiter_invitation_message(
                    title, urllib.quote(invitation_key))
                MessageServices.send_message(u"دعوت از شما برای داوری",
                                             message,
                                             email=email)

                form = None
                messages.success(http_request,
                                 u"دعوت داور با موفقیت انجام شد.")
        else:
            form = ArbiterInvitationForm()

        return render_to_response(
            'manager/actions/add_edit.html', {
                'form': form,
                'title': u"دعوت داور"
            },
            context_instance=RequestContext(http_request))
Esempio n. 19
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. 20
0
    def action_view(self, http_request, selected_instances):
        if not selected_instances:
            raise Http404()

        instance = selected_instances[0]
        old_state = instance.project_status
        #old_state_display = instance.get_project_status_display()
        milestone_formset = None
        if http_request.method == 'POST':
            form = AdminProjectManagerForm(http_request.POST,
                                           http_request.FILES,
                                           instance=instance,
                                           http_request=http_request)
            arbiter_formset = ProjectArbiterFormset(http_request.POST,
                                                    http_request.FILES,
                                                    instance=instance,
                                                    prefix='project_arbiter')
            if old_state > 1:
                milestone_formset = ProjectMilestoneFormset(
                    http_request.POST,
                    http_request.FILES,
                    instance=instance,
                    prefix='project_milestone')
            milestone_formset_valid = True
            if milestone_formset and not milestone_formset.is_valid():
                milestone_formset_valid = False

            arbiter_formset_valid = True
            if arbiter_formset and not arbiter_formset.is_valid():
                arbiter_formset_valid = False

            if form.is_valid(
            ) and milestone_formset_valid and arbiter_formset_valid:
                if old_state > 1:
                    milestone_formset.save()

                instance = form.save()
                form = None
                new_state = instance.project_status
                project_arbiters = []
                if new_state == 1:
                    project_arbiters = arbiter_formset.save()
                elif new_state < 1:
                    instance.project_arbiters.all().delete()
                #new_state_display = instance.get_project_status_display()

                if old_state != new_state:
                    #message_body = u'وضعیت طرح "%s" از "%s" به "%s" تغییر پیدا کرد.' % (
                    #    instance.title, old_state_display, new_state_display)
                    message = None
                    if instance.single_member:
                        member = instance.single_member
                    else:
                        member = instance.cluster.head
                    if new_state == Project.REJECT_STATE:
                        message_body = u'وضعیت طرح "%s" به رد شده تغییر پیدا کرد.' % (
                            instance.title)
                        message = MessageServices.get_title_body_message(
                            u"ردشدن طرح", message_body)
                        SMSService.send_sms(message_body, [member.mobile])
                    elif new_state == Project.CONFIRM_STATE:
                        message_body = u'وضعیت طرح "%s" به تاییدشده تغییر پیدا کرد.' % (
                            instance.title)
                        message = MessageServices.get_title_body_message(
                            u"تایید طرح", message_body)
                        SMSService.send_sms(message_body, [member.mobile])
                    elif old_state == Project.CONFIRM_STATE:
                        message_body = u'وضعیت طرح "%s" به حالت در حال بررسی تغییر پیدا کرد.' % (
                            instance.title)
                        message = MessageServices.get_title_body_message(
                            u"تغییر طرح به در حال بررسی", message_body)
                        SMSService.send_sms(message_body, [member.mobile])

                    if message:
                        MessageServices.send_message(u"تغییر وضعیت طرح",
                                                     message, member.user)

                for project_arbiter in project_arbiters:
                    arbiter = project_arbiter.arbiter
                    #if old_arbiter != new_arbiter and new_arbiter:
                    message_body = u'%s محترم، مدیریت سامانه موسسه  نگاه نو طرح با عنوان "%s" را برای داوری به شما سپرده است.' % (
                        unicode(arbiter), instance.title)
                    message = MessageServices.get_title_body_message(
                        u"ارسال طرح برای شما جهت داوری", message_body)
                    MessageServices.send_message(
                        u"ارسال طرح برای شما جهت داوری", message, arbiter.user)
                    #    #SMSService.send_sms(message_body, [new_arbiter.mobile])

                messages.success(http_request,
                                 u"بررسی طرح با موفقیت انجام شد.")
        else:
            form = AdminProjectManagerForm(instance=instance,
                                           http_request=http_request)
            if instance.project_status > 1:
                milestone_formset = ProjectMilestoneFormset(
                    instance=instance, prefix='project_milestone')
            arbiter_formset = ProjectArbiterFormset(instance=instance,
                                                    prefix='project_arbiter')
        return render_to_response(
            'project/check_project.html', {
                'form': form,
                'milestone_formset': milestone_formset,
                'title': u"بررسی طرح",
                'project': instance,
                'arbiter_formset': arbiter_formset,
                'project_arbiters': instance.project_arbiters.all(),
            },
            context_instance=RequestContext(http_request))
Esempio n. 21
0
    def action_view(self, http_request, selected_instances):
        if not selected_instances:
            raise Http404()

        field_label = self.field_label
        field_val = selected_instances[0].head.is_confirmed

        degree_initial = selected_instances[0].degree

        class ConfirmForm(forms.Form):
            confirm = forms.NullBooleanField(label=field_label, initial=field_val, required=False)
            confirm.widget.choices = ((u'1', u"نامشخص"),
                                      (u'2', u"بله"),
                                      (u'3', u"خیر"))
            degree = forms.ChoiceField(label=u"درجه", choices=Cluster.CLUSTER_DEGREE, required=True,
                                       initial=degree_initial)

        if http_request.method == 'POST':
            form = ConfirmForm(http_request.POST)
            if form.is_valid():
                confirm = form.cleaned_data.get('confirm')
                degree = form.cleaned_data.get('degree')
                for member in selected_instances[0].members.all():
                    try:
                        member.is_confirmed = confirm
                        member.save()
                    except Member.DoesNotExist:
                        pass
                selected_instances[0].head.is_confirmed = confirm
                selected_instances[0].head.save()
                selected_instances[0].degree = degree
                selected_instances[0].save()

                if confirm is True:
                    message_body = u"وضعیت خوشه شما با نام  %s به تاییدشده تغییر یافت.\n هم اکنون شما میتوانید در سامانه فعالیت داشته باشید." % (
                        selected_instances[0].name)
                    message = MessageServices.get_title_body_message(u"تایید خوشه", message_body)

                elif confirm is False:
                    if selected_instances[0].head.gender == 1:
                        message_body = u"آقای "
                    else:
                        message_body = u"خانم "
                    message_body += u"%s ضمن قدردانی از بذل توجه شما به این موسسه و ثبت نام در سامانه، متاسفانه عضویت شما در سامانه مورد موافقت موسسه قرار نگرفته است.  با آرزوی موفقیت و سلامتی برای شما دوست عزیز." % unicode(
                        selected_instances[0].head)
                    message = MessageServices.get_title_body_message(u"تغییر وضعیت خوشه", message_body)
                else:
                    message_body = u"وضعیت خوشه شما با نام  %s به نامشخص تغییر یافت." % (
                        selected_instances[0].name)
                    message = MessageServices.get_title_body_message(u"تغییر وضعیت خوشه", message_body)

                MessageServices.send_message(u"تغییر وضعیت خوشه", message, selected_instances[0].head.user)
                #SMSService.send_sms(message_body, [selected_instances[0].head.mobile])

                #if confirm is False:
                #    selected_instances[0].delete()

                form = None
                messages.success(http_request, u"%s با موفقیت انجام شد." % self.form_title)
        else:
            form = ConfirmForm()

        return render_to_response('manager/actions/add_edit.html', {'form': form, 'title': self.form_title},
                                  context_instance=RequestContext(http_request))
Esempio n. 22
0
    def __save_cluster(self, member):
        if not self.cluster:
            is_cluster = self.cluster_form.cleaned_data.get('is_cluster')
            if is_cluster == 'True':
                name = self.cluster_form.cleaned_data.get('name')
                institute = self.cluster_form.cleaned_data.get('institute')
                cluster = Cluster.objects.create(name=name, institute=institute, head=member)

                member.cluster = cluster

                cluster_domains = []
                for form in self.cluster_domain_formset.forms:
                    domain_choice = form.cleaned_data.get('domain_choice')
                    new_domain_name = form.cleaned_data.get('new_domain_name')
                    if not domain_choice and new_domain_name:
                        domain_choice = Domain.objects.create(name=new_domain_name)
                    if domain_choice:
                        cluster_domains.append(domain_choice)
                        # cluster_domains = self.cluster_domain_formset.save()
                cluster.domains = cluster_domains

                members = []
                for form in self.cluster_member_formset.forms:
                    if form.is_valid():
                        first_name = form.cleaned_data.get('first_name')
                        last_name = form.cleaned_data.get('last_name')
                        email = form.cleaned_data.get('email')
                        domain = form.cleaned_data.get('domain')
                        password = User.objects.make_random_password()
                        user = User.objects.create(first_name=first_name, last_name=last_name, username=email,
                                                   email=email)
                        user.set_password(password)
                        user.save()
                        try:
                            domain = cluster.domains.get(id=int(domain))
                        except (Domain.DoesNotExist, ValueError):
                            try:
                                domain = cluster.domains.get(name=domain)
                            except Domain.DoesNotExist:
                                domain = None
                        temp_member = Member.objects.create(user=user, domain=domain)
                        members.append(temp_member)
                        message = MessageServices.get_registration_message(cluster, user, email, password)
                        MessageServices.send_message(subject=u"ثبت نام خوشه %s" % cluster.name,
                                                     message=message,
                                                     user=user, cluster=cluster)
                members.append(member)

                cluster.members = members
        else:
            member.cluster = self.cluster
            if self.cluster.head == self.member:
                name = self.cluster_form.cleaned_data.get('name')
                institute = self.cluster_form.cleaned_data.get('institute')
                self.cluster.name = name
                self.cluster.institute = institute

                self.cluster.domains.filter(confirmed=False).delete()
                cluster_domains = []
                for form in self.cluster_domain_formset.forms:
                    if form not in self.cluster_domain_formset.deleted_forms:
                        domain_choice = form.cleaned_data.get('domain_choice') or form.fields['domain_choice'].initial
                        new_domain_name = form.cleaned_data.get('new_domain_name') or form.fields[
                            'new_domain_name'].initial
                        if not domain_choice and new_domain_name:
                            domain_choice = Domain.objects.create(name=new_domain_name)
                        if domain_choice:
                            cluster_domains.append(domain_choice)
                self.cluster.domains = cluster_domains

                members = []
                for form in self.cluster_member_formset.forms:
                    if form not in self.cluster_member_formset.deleted_forms:
                        if form.is_valid():
                            first_name = form.cleaned_data.get('first_name')
                            last_name = form.cleaned_data.get('last_name')
                            email = form.cleaned_data.get('email')
                            domain = form.cleaned_data.get('domain')
                            try:
                                domain = self.cluster.domains.get(id=int(domain))
                            except (Domain.DoesNotExist, ValueError, TypeError):
                                try:
                                    domain = self.cluster.domains.get(name=domain)
                                except Domain.DoesNotExist:
                                    domain = None
                            if 'member_id' in form.fields:
                                member_id = form.fields['member_id'].initial
                            else:
                                member_id = None
                            if member_id:
                                try:
                                    member_temp = self.cluster.members.get(id=member_id)
                                    if first_name:
                                        member_temp.user.first_name = first_name
                                    if last_name:
                                        member_temp.user.last_name = last_name
                                    if email:
                                        member_temp.user.email = email
                                    if domain:
                                        member_temp.domain = domain
                                    member_temp.user.save()
                                    member_temp.save()
                                    members.append(member_temp)
                                except Member.DoesNotExist:
                                    pass
                            else:
                                if email:
                                    password = User.objects.make_random_password()
                                    user = User.objects.create(first_name=first_name, last_name=last_name,
                                                               username=email,
                                                               email=email)
                                    user.set_password(password)
                                    user.save()
                                    member_temp = Member.objects.create(user=user, domain=domain)
                                    members.append(member_temp)
                                    message = MessageServices.get_registration_message(self.cluster, user, email,
                                                                                       password)
                                    MessageServices.send_message(subject=u"ثبت نام خوشه %s" % self.cluster.name,
                                                                 message=message,
                                                                 user=user, cluster=self.cluster)

                for form in self.cluster_member_formset.deleted_forms:
                    if form.is_valid():
                        member_id = form.cleaned_data.get('member_id')
                        if member_id:
                            try:
                                member_temp = self.cluster.members.get(id=member_id)
                                message = MessageServices.get_delete_member_message(self.cluster, member_temp.user)
                                MessageServices.send_message(subject=u"حذف از خوشه %s" % self.cluster.name,
                                                             message=message,
                                                             user=member_temp.user, cluster=self.cluster)
                                user = member_temp.user
                                member_temp.delete()
                                user.delete()
                            except Member.DoesNotExist:
                                pass
                members.append(member)

                self.cluster.members = members

                self.cluster.save()
Esempio n. 23
0
    def action_view(self, http_request, selected_instances):
        if not selected_instances:
            raise Http404()

        instance = selected_instances[0]
        old_state = instance.project_status
        #old_state_display = instance.get_project_status_display()
        milestone_formset = None
        if http_request.method == 'POST':
            form = AdminProjectManagerForm(http_request.POST, http_request.FILES, instance=instance,
                                           http_request=http_request)
            arbiter_formset = ProjectArbiterFormset(http_request.POST, http_request.FILES, instance=instance,
                                                    prefix='project_arbiter')
            if old_state > 1:
                milestone_formset = ProjectMilestoneFormset(http_request.POST, http_request.FILES, instance=instance,
                                                            prefix='project_milestone')
            milestone_formset_valid = True
            if milestone_formset and not milestone_formset.is_valid():
                milestone_formset_valid = False

            arbiter_formset_valid = True
            if arbiter_formset and not arbiter_formset.is_valid():
                arbiter_formset_valid = False

            if form.is_valid() and milestone_formset_valid and arbiter_formset_valid:
                if old_state > 1:
                    milestone_formset.save()

                instance = form.save()
                form = None
                new_state = instance.project_status
                project_arbiters = []
                if new_state == 1:
                    project_arbiters = arbiter_formset.save()
                elif new_state < 1:
                    instance.project_arbiters.all().delete()
                #new_state_display = instance.get_project_status_display()

                if old_state != new_state:
                    #message_body = u'وضعیت طرح "%s" از "%s" به "%s" تغییر پیدا کرد.' % (
                    #    instance.title, old_state_display, new_state_display)
                    message = None
                    if instance.single_member:
                        member = instance.single_member
                    else:
                        member = instance.cluster.head
                    if new_state == Project.REJECT_STATE:
                        message_body = u'وضعیت طرح "%s" به رد شده تغییر پیدا کرد.' % (
                            instance.title)
                        message = MessageServices.get_title_body_message(u"ردشدن طرح", message_body)
                        SMSService.send_sms(message_body, [member.mobile])
                    elif new_state == Project.CONFIRM_STATE:
                        message_body = u'وضعیت طرح "%s" به تاییدشده تغییر پیدا کرد.' % (
                            instance.title)
                        message = MessageServices.get_title_body_message(u"تایید طرح", message_body)
                        SMSService.send_sms(message_body, [member.mobile])
                    elif old_state == Project.CONFIRM_STATE:
                        message_body = u'وضعیت طرح "%s" به حالت در حال بررسی تغییر پیدا کرد.' % (
                            instance.title)
                        message = MessageServices.get_title_body_message(u"تغییر طرح به در حال بررسی", message_body)
                        SMSService.send_sms(message_body, [member.mobile])

                    if message:
                        MessageServices.send_message(u"تغییر وضعیت طرح", message, member.user)

                for project_arbiter in project_arbiters:
                    arbiter = project_arbiter.arbiter
                    #if old_arbiter != new_arbiter and new_arbiter:
                    message_body = u'%s محترم، مدیریت سامانه موسسه  نگاه نو طرح با عنوان "%s" را برای داوری به شما سپرده است.' % (
                        unicode(arbiter), instance.title)
                    message = MessageServices.get_title_body_message(u"ارسال طرح برای شما جهت داوری", message_body)
                    MessageServices.send_message(u"ارسال طرح برای شما جهت داوری", message, arbiter.user)
                    #    #SMSService.send_sms(message_body, [new_arbiter.mobile])

                messages.success(http_request, u"بررسی طرح با موفقیت انجام شد.")
        else:
            form = AdminProjectManagerForm(instance=instance, http_request=http_request)
            if instance.project_status > 1:
                milestone_formset = ProjectMilestoneFormset(instance=instance, prefix='project_milestone')
            arbiter_formset = ProjectArbiterFormset(instance=instance, prefix='project_arbiter')
        return render_to_response('project/check_project.html',
                                  {'form': form, 'milestone_formset': milestone_formset, 'title': u"بررسی طرح",
                                   'project': instance, 'arbiter_formset': arbiter_formset,
                                   'project_arbiters': instance.project_arbiters.all(), },
                                  context_instance=RequestContext(http_request))
Esempio n. 24
0
    def action_view(self, http_request, selected_instances):
        if not selected_instances:
            raise Http404()

        field_label = self.field_label
        field_val = selected_instances[0].head.is_confirmed

        degree_initial = selected_instances[0].degree

        class ConfirmForm(forms.Form):
            confirm = forms.NullBooleanField(label=field_label,
                                             initial=field_val,
                                             required=False)
            confirm.widget.choices = ((u'1', u"نامشخص"), (u'2', u"بله"),
                                      (u'3', u"خیر"))
            degree = forms.ChoiceField(label=u"درجه",
                                       choices=Cluster.CLUSTER_DEGREE,
                                       required=True,
                                       initial=degree_initial)

        if http_request.method == 'POST':
            form = ConfirmForm(http_request.POST)
            if form.is_valid():
                confirm = form.cleaned_data.get('confirm')
                degree = form.cleaned_data.get('degree')
                for member in selected_instances[0].members.all():
                    try:
                        member.is_confirmed = confirm
                        member.save()
                    except Member.DoesNotExist:
                        pass
                selected_instances[0].head.is_confirmed = confirm
                selected_instances[0].head.save()
                selected_instances[0].degree = degree
                selected_instances[0].save()

                if confirm is True:
                    message_body = u"وضعیت خوشه شما با نام  %s به تاییدشده تغییر یافت.\n هم اکنون شما میتوانید در سامانه فعالیت داشته باشید." % (
                        selected_instances[0].name)
                    message = MessageServices.get_title_body_message(
                        u"تایید خوشه", message_body)

                elif confirm is False:
                    if selected_instances[0].head.gender == 1:
                        message_body = u"آقای "
                    else:
                        message_body = u"خانم "
                    message_body += u"%s ضمن قدردانی از بذل توجه شما به این موسسه و ثبت نام در سامانه، متاسفانه عضویت شما در سامانه مورد موافقت موسسه قرار نگرفته است.  با آرزوی موفقیت و سلامتی برای شما دوست عزیز." % unicode(
                        selected_instances[0].head)
                    message = MessageServices.get_title_body_message(
                        u"تغییر وضعیت خوشه", message_body)
                else:
                    message_body = u"وضعیت خوشه شما با نام  %s به نامشخص تغییر یافت." % (
                        selected_instances[0].name)
                    message = MessageServices.get_title_body_message(
                        u"تغییر وضعیت خوشه", message_body)

                MessageServices.send_message(u"تغییر وضعیت خوشه", message,
                                             selected_instances[0].head.user)
                #SMSService.send_sms(message_body, [selected_instances[0].head.mobile])

                #if confirm is False:
                #    selected_instances[0].delete()

                form = None
                messages.success(http_request,
                                 u"%s با موفقیت انجام شد." % self.form_title)
        else:
            form = ConfirmForm()

        return render_to_response(
            'manager/actions/add_edit.html', {
                'form': form,
                'title': self.form_title
            },
            context_instance=RequestContext(http_request))
Esempio n. 25
0
    def __save_cluster(self, member):
        if not self.cluster:
            is_cluster = self.cluster_form.cleaned_data.get('is_cluster')
            if is_cluster == 'True':
                name = self.cluster_form.cleaned_data.get('name')
                institute = self.cluster_form.cleaned_data.get('institute')
                cluster = Cluster.objects.create(name=name,
                                                 institute=institute,
                                                 head=member)

                member.cluster = cluster

                cluster_domains = []
                for form in self.cluster_domain_formset.forms:
                    domain_choice = form.cleaned_data.get('domain_choice')
                    new_domain_name = form.cleaned_data.get('new_domain_name')
                    if not domain_choice and new_domain_name:
                        domain_choice = Domain.objects.create(
                            name=new_domain_name)
                    if domain_choice:
                        cluster_domains.append(domain_choice)
                        # cluster_domains = self.cluster_domain_formset.save()
                cluster.domains = cluster_domains

                members = []
                for form in self.cluster_member_formset.forms:
                    if form.is_valid():
                        first_name = form.cleaned_data.get('first_name')
                        last_name = form.cleaned_data.get('last_name')
                        email = form.cleaned_data.get('email')
                        domain = form.cleaned_data.get('domain')
                        password = User.objects.make_random_password()
                        user = User.objects.create(first_name=first_name,
                                                   last_name=last_name,
                                                   username=email,
                                                   email=email)
                        user.set_password(password)
                        user.save()
                        try:
                            domain = cluster.domains.get(id=int(domain))
                        except (Domain.DoesNotExist, ValueError):
                            try:
                                domain = cluster.domains.get(name=domain)
                            except Domain.DoesNotExist:
                                domain = None
                        temp_member = Member.objects.create(user=user,
                                                            domain=domain)
                        members.append(temp_member)
                        message = MessageServices.get_registration_message(
                            cluster, user, email, password)
                        MessageServices.send_message(
                            subject=u"ثبت نام خوشه %s" % cluster.name,
                            message=message,
                            user=user,
                            cluster=cluster)
                members.append(member)

                cluster.members = members
        else:
            member.cluster = self.cluster
            if self.cluster.head == self.member:
                name = self.cluster_form.cleaned_data.get('name')
                institute = self.cluster_form.cleaned_data.get('institute')
                self.cluster.name = name
                self.cluster.institute = institute

                self.cluster.domains.filter(confirmed=False).delete()
                cluster_domains = []
                for form in self.cluster_domain_formset.forms:
                    if form not in self.cluster_domain_formset.deleted_forms:
                        domain_choice = form.cleaned_data.get(
                            'domain_choice'
                        ) or form.fields['domain_choice'].initial
                        new_domain_name = form.cleaned_data.get(
                            'new_domain_name'
                        ) or form.fields['new_domain_name'].initial
                        if not domain_choice and new_domain_name:
                            domain_choice = Domain.objects.create(
                                name=new_domain_name)
                        if domain_choice:
                            cluster_domains.append(domain_choice)
                self.cluster.domains = cluster_domains

                members = []
                for form in self.cluster_member_formset.forms:
                    if form not in self.cluster_member_formset.deleted_forms:
                        if form.is_valid():
                            first_name = form.cleaned_data.get('first_name')
                            last_name = form.cleaned_data.get('last_name')
                            email = form.cleaned_data.get('email')
                            domain = form.cleaned_data.get('domain')
                            try:
                                domain = self.cluster.domains.get(
                                    id=int(domain))
                            except (Domain.DoesNotExist, ValueError,
                                    TypeError):
                                try:
                                    domain = self.cluster.domains.get(
                                        name=domain)
                                except Domain.DoesNotExist:
                                    domain = None
                            if 'member_id' in form.fields:
                                member_id = form.fields['member_id'].initial
                            else:
                                member_id = None
                            if member_id:
                                try:
                                    member_temp = self.cluster.members.get(
                                        id=member_id)
                                    if first_name:
                                        member_temp.user.first_name = first_name
                                    if last_name:
                                        member_temp.user.last_name = last_name
                                    if email:
                                        member_temp.user.email = email
                                    if domain:
                                        member_temp.domain = domain
                                    member_temp.user.save()
                                    member_temp.save()
                                    members.append(member_temp)
                                except Member.DoesNotExist:
                                    pass
                            else:
                                if email:
                                    password = User.objects.make_random_password(
                                    )
                                    user = User.objects.create(
                                        first_name=first_name,
                                        last_name=last_name,
                                        username=email,
                                        email=email)
                                    user.set_password(password)
                                    user.save()
                                    member_temp = Member.objects.create(
                                        user=user, domain=domain)
                                    members.append(member_temp)
                                    message = MessageServices.get_registration_message(
                                        self.cluster, user, email, password)
                                    MessageServices.send_message(
                                        subject=u"ثبت نام خوشه %s" %
                                        self.cluster.name,
                                        message=message,
                                        user=user,
                                        cluster=self.cluster)

                for form in self.cluster_member_formset.deleted_forms:
                    if form.is_valid():
                        member_id = form.cleaned_data.get('member_id')
                        if member_id:
                            try:
                                member_temp = self.cluster.members.get(
                                    id=member_id)
                                message = MessageServices.get_delete_member_message(
                                    self.cluster, member_temp.user)
                                MessageServices.send_message(
                                    subject=u"حذف از خوشه %s" %
                                    self.cluster.name,
                                    message=message,
                                    user=member_temp.user,
                                    cluster=self.cluster)
                                user = member_temp.user
                                member_temp.delete()
                                user.delete()
                            except Member.DoesNotExist:
                                pass
                members.append(member)

                self.cluster.members = members

                self.cluster.save()