Example #1
0
 def save(self, company, request):
     cd = self.cleaned_data
     profile = super(CreateCompanyCEOForm, self).save(False)
     user = User.objects.create(first_name=cd["first_name"],
                                last_name=cd["last_name"],
                                email=cd["email"],
                                is_staff=True,
                                is_active=True,
                                username=profile.auuid + "_" +
                                company.identifier)
     password = utils.random_string()
     user.set_password(password)
     user.user_permissions.set(Permission.objects.all())
     user.save()
     # utils.send_password_mail(user.email, password)
     profile.company = company
     profile.user = user
     profile.is_ceo = True
     profile.save()
     mail = render_to_string("account/emails/user-creation.html", {
         "user": user,
         "password": password,
         "request": request
     })
     utils.send_mail("Login Credentials", mail, user.email)
     return profile
Example #2
0
 def task_creation_notification(request, task):
     mail = render_to_string("task/emails/creation.html", {
         "user": task.assigned_to.user,
         "request": request
     })
     utils.send_mail("Task Notification", mail, [task.assigned_to.user.email])
     devices = FCMDevice.objects.filter(user=task.assigned_to.user)
     if devices.exists():
         devices.send_message(title="New Task Notification", body="Hi! {0}({1}) just assigned a task to you.".format(task.created_by.user.get_full_name(), task.created_by.auuid))
Example #3
0
 def pip_notification(request, user, pip):
     mail = render_to_string("pip/emails/creation.html", {
         "user": user,
         "request": request,
         'pip': pip
     })
     utils.send_mail("PIP Notification", mail, [user.email])
     devices = FCMDevice.objects.filter(user=user)
     if devices.exists():
         devices.send_message(title="PIP Notification", body="Hi! A PIP has been raised for you.")
Example #4
0
 def task_update_notification(request, task):
     user = task.assigned_to.user if task.assigned_to.user != request.user else task.created_by.user
     mail = render_to_string("task/emails/update.html", {
         "user": user,
         "request": request
     })
     utils.send_mail("Task Notification", mail, [user.email])
     devices = FCMDevice.objects.filter(user=user)
     if devices.exists():
         devices.send_message(title="Task Update Notification", body="Hi! You have an update on one of your tasks.")
Example #5
0
 def kra_setting_notification(request, kra):
     mail = render_to_string("kra/emails/setting.html", {
         "user": request.user.profile.manager.user,
         "kra": kra,
         'request': request
     })
     utils.send_mail('KRA Setting Notification', mail, request.user.profile.manager.user.email)
     devices = FCMDevice.objects.filter(user=request.user.profile.manager.user)
     if devices.exists():
         if request.user.profile.gender.lower() == "female":
             body = "{0}({1}) just submitted her KRA".format(request.user.get_full_name(), request.user.profile.auuid)
         else:
             body = "{0}({1}) just submitted his KRA".format(request.user.get_full_name(), request.user.profile.auuid)
         devices.send_message(title="KRA Notification", body=body)
Example #6
0
 def form_valid(self, form):
     user = form.save()
     password = utils.random_string()
     user.set_password(password)
     user.is_active = True
     user.is_staff = True
     user.is_superuser = True
     user.user_permissions.set(Permission.objects.all())
     user.save()
     # utils.send_password_mail(user.email, password)
     mail = render_to_string("account/emails/user-creation.html", {
         "user": user,
         "password": password,
         "request": self.request
     })
     utils.send_mail("Login Credentials", mail, user.email)
     messages.success(self.request, "User account created successfully")
     return HttpResponseRedirect(self.success_url)
Example #7
0
 def kra_update_notification(request, kra):
     user = kra.user if request.user != kra.user else None
     if user is None and kra.user.profile.manager:
         user = kra.user.profile.manager.user
     if user:
         mail = render_to_string("kra/emails/kra-update.html", {
             "kra": kra,
             "request": request,
             "user": user
         })
         utils.send_mail('KRA Setting Notification', mail, user.email)
         devices = FCMDevice.objects.filter(user=user)
         if devices.exists():
             if user != kra.user:
                 body = "Hi! {0}({1}) just updated {2} KRA setting".format(kra.user.get_full_name(), kra.user.profile.auuid, "his" if kra.user.profile.gender.lower() == "male" else "her")
             else:
                 body = "Hi! You have an update on your KRA setting"
             devices.send_message(title="KRA Notification", body=body)
Example #8
0
    def form_valid(self, form):
        company = self.request.user.profile.company
        if not company.config.subscription.plan.is_flexible:
            count = company.members.count()
            total = count + len(form.forms)
            threshold = company.config.subscription.plan.threshold
            if total > threshold:
                form._non_form_errors = form.error_class([
                    "Sorry, you've exceeded your subscription quota by {}. You have just {} slots left.'"
                    .format(total - threshold, threshold - count)
                ])
                return self.form_invalid(form)
        form.instance = company
        members = form.save(commit=False)
        i = 0

        for f in form.forms:
            cd = f.cleaned_data
            if "auuid" in cd:
                username = cd["auuid"] + "_" + form.instance.identifier
                user = User.objects.create(username=username,
                                           first_name=cd["first_name"],
                                           last_name=cd["last_name"],
                                           email=cd["email"],
                                           is_active=True)
                password = utils.random_string()
                user.set_password(password)
                if cd["permissions"]:
                    user.user_permissions.set(cd["permissions"])
                user.save()
                members[i].user = user
                members[i].save()
                mail = render_to_string("account/emails/user-creation.html", {
                    "user": user,
                    "password": password,
                    "request": self.request
                })
                utils.send_mail("Login Credentials", mail, user.email)
            i += 1
        messages.success(self.request, "Member(s) created successfully")
        return HttpResponseRedirect(self.success_url)