def workflow_approve_callback(self, flow_instance): from cloud.tasks import allocate_floating_task try: allocate_floating_task.delay(self) self.status = FLOATING_ALLOCATE self.save() content = title = _('Your application for %(bandwidth)d Mbps floating IP is approved! ') \ % {'bandwidth': self.bandwidth} Notification.info(flow_instance.owner, title, content, is_auto=True) except: self.status = FLOATING_ERROR self.save() title = _('Error happened to your application for floating IP') content = _( 'Your application for %(bandwidth)d Mbps floating ip is approved, ' 'but an error happened when creating it.') % { 'bandwidth': self.bandwidth } Notification.error(flow_instance.owner, title, content, is_auto=True)
def workflow_approve_callback(self, flow_instance): from cloud.volume_task import volume_create_task try: self.status = VOLUME_STATE_CREATING self.save() volume_create_task.delay(self) content = title = _('Your application for %(size)d GB volume named %(name)s is approved! ') \ % {'size': self.size, 'name': self.name} Notification.info(flow_instance.owner, title, content, is_auto=True) except: self.status = VOLUME_STATE_ERROR self.save() title = _('Error happened to your application for volume') content = _( 'Your application for %(size)d GB volume named %(name)s is approved, ' 'but an error happened when creating it.') % { 'size': self.size, 'name': self.name } Notification.error(flow_instance.owner, title, content, is_auto=True)
def post(self, request): form = AuthenticationForm(data=request.POST) if not form.is_valid(): return self.response(request, form) user = form.get_user() auth_login(request, user) # Retrieve user to use some methods of UserProxy user = UserProxy.objects.get(pk=user.pk) if user.is_superuser or user.is_system_user or user.is_audit_user or user.is_safety_user: return redirect('management') udc_set = UDC.objects.filter(user=user) if udc_set.exists(): request.session["UDC_ID"] = udc_set[0].id elif user.is_approver: request.session["UDC_ID"] = -1 else: return redirect('no_udc') Notification.pull_announcements(user) return HttpResponseRedirect(reverse("cld"))
def workflow_approve_callback(self, flow_instance): from cloud.instance_task import instance_create_task try: instance_create_task.delay(self, password=flow_instance.extra_data) self.status = INSTANCE_STATE_WAITING self.save() content = title = _('Your application for instance "%(instance_name)s" is approved! ') \ % {'instance_name': self.name} Notification.info(flow_instance.owner, title, content, is_auto=True) except: self.status = INSTANCE_STATE_ERROR self.save() title = _('Error happened to your application for %(instance_name)s') \ % {'instance_name': self.name} content = _( 'Your application for instance "%(instance_name)s" is approved, ' 'but an error happened when creating instance.') % { 'instance_name': self.name } Notification.error(flow_instance.owner, title, content, is_auto=True)
def post(self, request): form = AuthenticationForm(data=request.POST) if not form.is_valid(): return self.response(request, form) user = form.get_user() auth_login(request, user) # Retrieve user to use some methods of UserProxy user = UserProxy.objects.get(pk=user.pk) if user.is_superuser or user.is_system_user or user.is_audit_user or user.is_safety_user: return redirect('management') udc_set = UDC.objects.filter(user=user) if udc_set.exists(): request.session["UDC_ID"] = udc_set[0].id elif user.is_approver: request.session["UDC_ID"] = -1 else: return redirect('no_udc') Notification.pull_announcements(user) return HttpResponseRedirect(reverse("cloud"))
def _broadcast(title, content, level, receivers): Notification.broadcast(receivers, title, content, level) mails = [(title, content, DEFAULT_SENDER, [receiver.email]) for receiver in receivers if receiver.email] send_mass_mail(mails)
def workflow_reject_callback(self, flow_instance): self.status = INSTANCE_STATE_REJECTED self.save() content = title = _('Your application for instance "%(instance_name)s" is rejected! ') \ % {'instance_name': self.name} Notification.error(flow_instance.owner, title, content, is_auto=True)
def workflow_reject_callback(self, flow_instance): self.status = VOLUME_STATE_REJECTED self.save() content = title = _('Your application for %(disk_size)d GB volume named %(name)s is rejected! ') \ % {'disk_size': self.size, 'name': self.name} Notification.error(flow_instance.owner, title, content, is_auto=True)
def workflow_reject_callback(self, flow_instance): self.status = FLOATING_REJECTED self.save() content = title = _('Your application for %(bandwidth)d floating IP is rejected! ') \ % {'bandwidth': self.bandwidth} Notification.error(flow_instance.owner, title, content, is_auto=True)
def data_center_broadcast(request): dc_id, level, title, content = retrieve_params( request.data, 'data_center', 'level', 'title', 'content') for receiver in UserProxy.normal_users. \ filter(userdatacenter__data_center__pk=dc_id, is_active=True): Notification.create(receiver, title, content, level) return Response({"success": True, "msg": _('Notification is sent successfully!')})
def broadcast(request): receiver_ids = request.data.getlist('receiver_ids[]') level, title, content = retrieve_params(request.data, 'level', 'title', 'content') receivers = UserProxy.normal_users.filter(is_active=True) if receiver_ids: receivers = UserProxy.normal_users.filter(pk__in=receiver_ids) for receiver in receivers: Notification.create(receiver, title, content, level) return Response({"success": True, "msg": _('Notification is sent successfully!')})
def workflow_approve_callback(self, flow_instance): from cloud.volume_task import volume_create_task try: self.status = VOLUME_STATE_CREATING self.save() volume_create_task.delay(self) content = title = _('Your application for %(size)d GB volume named %(name)s is approved! ') \ % {'size': self.size, 'name': self.name} Notification.info(flow_instance.owner, title, content, is_auto=True) except: self.status = VOLUME_STATE_ERROR self.save() title = _('Error happened to your application for volume') content = _('Your application for %(size)d GB volume named %(name)s is approved, ' 'but an error happened when creating it.') % {'size': self.size, 'name': self.name} Notification.error(flow_instance.owner, title, content, is_auto=True)
def workflow_approve_callback(self, flow_instance): from cloud.tasks import allocate_floating_task try: allocate_floating_task.delay(self) self.status = FLOATING_ALLOCATE self.save() content = title = _('Your application for %(bandwidth)d Mbps floating IP is approved! ') \ % {'bandwidth': self.bandwidth} Notification.info(flow_instance.owner, title, content, is_auto=True) except: self.status = FLOATING_ERROR self.save() title = _('Error happened to your application for floating IP') content = _('Your application for %(bandwidth)d Mbps floating ip is approved, ' 'but an error happened when creating it.') % {'bandwidth': self.bandwidth} Notification.error(flow_instance.owner, title, content, is_auto=True)
def workflow_approve_callback(self, flow_instance): from cloud.instance_task import instance_create_task try: instance_create_task.delay(self, password=flow_instance.extra_data) self.status = INSTANCE_STATE_WAITING self.save() content = title = _('Your application for instance "%(instance_name)s" is approved! ') \ % {'instance_name': self.name} Notification.info(flow_instance.owner, title, content, is_auto=True) except: self.status = INSTANCE_STATE_ERROR self.save() title = _('Error happened to your application for %(instance_name)s') \ % {'instance_name': self.name} content = _('Your application for instance "%(instance_name)s" is approved, ' 'but an error happened when creating instance.') % {'instance_name': self.name} Notification.error(flow_instance.owner, title, content, is_auto=True)
def post(self, request): form = AuthenticationForm(data=request.POST) login_type = request.POST.get('type') or None if not form.is_valid(): return self.response(request, form) user = form.get_user() auth_login(request, user) # Retrieve user to use some methods of UserProxy user = UserProxy.objects.get(pk=user.pk) role = "" if not user.is_superuser: udc_id = 0 udc_set = UDC.objects.filter(user=user) if udc_set.exists(): request.session["UDC_ID"] = udc_set[0].id udc_id = udc_set[0].id elif user.is_approver: request.session["UDC_ID"] = -1 else: return redirect('no_udc') role = user_role_member(request, udc_id) if user.is_superuser or role: #add session["UDC_ID"] for surperuser if UDC.objects.filter(user=user).exists(): udc_set = UDC.objects.filter(user=user) request.session["UDC_ID"] = udc_set[0].id try: Operation.objects.create(user=user, udc=udc_set[0], resource="登录", resource_id=1, resource_name="登录", action="login", result=0) except Exception as e: pass return redirect('management') elif login_type == "vdi_client": return HttpResponseRedirect(reverse("cloud")) else: try: Operation.objects.create(user=user, udc='-1', resource="普通用户登录web", resource_id=1, resource_name="登录", action="login", result=0) except Exception as e: pass auth_logout(request) return HttpResponseForbidden() udc_set = UDC.objects.filter(user=user) if udc_set.exists(): request.session["UDC_ID"] = udc_set[0].id elif user.is_approver: request.session["UDC_ID"] = -1 else: return redirect('no_udc') Notification.pull_announcements(user) return HttpResponseRedirect(reverse("cloud"))
def feed_status(request): Notification.pull_announcements(request.user) num = Feed.living.filter(receiver=request.user, is_read=False).count() return Response({"num": num})