Ejemplo n.º 1
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))
Ejemplo 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))
Ejemplo 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))
Ejemplo 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))
Ejemplo n.º 5
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])
Ejemplo 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])
Ejemplo n.º 7
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)
Ejemplo n.º 8
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)
Ejemplo n.º 9
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
Ejemplo n.º 10
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
Ejemplo n.º 11
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))
Ejemplo n.º 12
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))