def common(request):
    context = {}
    company_info = service_models.service_requested.objects.first()
    if company_info:
        context.update({
            "company_name": company_info.company_name,
        })

    if request.user.is_authenticated:
        if 'crm_branch' not in cache:
            redis.set_crm_branch(request)

        current_branch = cache.get('crm_branch')
        total_branch = helper_manager.user_has_multiple_branch(request.user)
        employee = employee_models.Employee.objects.none()
        data = []
        count = 0
        try:
            employee = employee_models.Employee.objects.get(user=request.user)
            notifications = notification_models.Notifications.objects.filter(
                employee=employee).order_by('-id')
            user_all_branch = helper_manager.get_current_user_branch(
                request.user)
            common_notifications = notification_models.Notifications.objects.filter(
                employee=None,
                for_branch__in=user_all_branch).order_by('-id').distinct()
            for i in notifications:
                count = count + 1
            for i in common_notifications:
                if employee not in i.seen_by.all():
                    count = count + 1
            context.update({"cn_count": count})
        except (Exception, employee_models.Employee.DoesNotExist) as e:
            print("Context 1 ", e)
            pass

        try:
            notify = notification_models.NotificationSettings.objects.get_or_create(
                employee=employee)
            context.update(
                {"show_notify_icon": notify[0].show_notification_icon})
        except (Exception) as e:
            pass

        if total_branch:
            branches = helper_manager.get_current_user_branch(request.user)
            context.update({"total_branch": branches})

        if employee:
            context.update({"context_employee": employee})
        context.update({"current_branch": current_branch})
    return context
Example #2
0
def set_crm_branch(request):
    branch = helper_manager.get_current_user_branch(request.user)
    current_branch = branch[0]
    current_branch_slug = branch[0].slug

    cache.delete('crm_branch_slug')
    cache.set('crm_branch_slug', current_branch_slug, timeout=CACHE_MAX_TTL)

    cache.delete('crm_branch')
    cache.set('crm_branch', current_branch, timeout=CACHE_MAX_TTL)
Example #3
0
def crm_index(request):
    weather_data = get_weather_data()

    current_branch = ''
    if 'crm_branch_slug' in cache:
        current_branch = cache.get('crm_branch_slug')
    else:
        branch = helper_manager.get_current_user_branch(request.user)
        current_branch = branch[0].slug

    return redirect('crm_branch', slug=current_branch)
Example #4
0
def notification_count(request):
    employee = employee_models.Employee.objects.none()
    data = []
    count = 0
    try:
        employee = employee_models.Employee.objects.get(user=request.user)
        notifications = notification_models.Notifications.objects.filter(
            employee=employee).order_by('-id')
        user_all_branch = helper_manager.get_current_user_branch(request.user)
        common_notifications = notification_models.Notifications.objects.filter(
            employee=None,
            for_branch__in=user_all_branch).order_by('-id').distinct()
        for i in notifications:
            count = count + 1
        for i in common_notifications:
            if employee not in i.seen_by.all():
                count = count + 1
        return count
    except (Exception, employee_models.Employee.DoesNotExist) as e:
        print("Context 1 ", e)
        return count
Example #5
0
def notifications(request):
    if 'crm_branch' not in cache:
        redis.set_crm_branch(request)

    try:
        current_branch = cache.get('crm_branch')
        context = {}
        context.update({"current_branch": current_branch})
        user_all_branch = helper_manager.get_current_user_branch(request.user)
        data = []
        count = 0
        employee = employee_models.Employee.objects.get(user=request.user)
        notifications = notification_models.Notifications.objects.filter(
            employee=employee).order_by('-id')
        common_notifications = notification_models.Notifications.objects.filter(
            employee=None,
            for_branch__in=user_all_branch).order_by('-id').distinct()

        for i in notifications:
            symbol = "/static/crmManager/v1/assets/lms.png"
            count = count + 1
            if i.leave:
                if not i.is_read:
                    data.append({
                        'id': i.id,
                        'text': i.text,
                        'leave_id': i.leave.id,
                        'leave_reason': i.leave.reason,
                        'from_date': i.leave.from_date,
                        'to_date': i.leave.to_date,
                        'date': i.date,
                        'time': str(i.time).split('.')[0],
                        'is_read': i.is_read,
                        'leave': True,
                        'tag': i.tag,
                        'reject_reason': i.leave.reject_reason,
                        "symbol": symbol,
                        'url': i.url
                    })
                    if i.tag == "approved":
                        i.is_read = True
            if i.compensation:
                if not i.is_read:
                    data.append({
                        'id': i.id,
                        'text': i.text,
                        'compensation_id': i.compensation.id,
                        'leave_reason': i.compensation.reason,
                        'days': i.compensation.days,
                        'date': i.date,
                        'time': str(i.time).split('.')[0],
                        'is_read': i.is_read,
                        'leave': True,
                        'tag': i.tag,
                        "symbol": symbol
                    })
        for i in common_notifications:
            is_read_commmon_status = False
            if employee in i.seen_by.all():
                is_read_commmon_status = True
            else:
                count = count + 1
                is_read_commmon_status = False

            symbol = "/static/crmManager/v1/assets/"
            if i.holiday:
                symbol += "holiday.png"
                data.append({
                    'id': i.id,
                    'text': 'Holiday Notification of ' + i.holiday.title,
                    'holiday_title': i.holiday.title,
                    'holiday_id': i.holiday.id,
                    'from_date': i.holiday.from_date,
                    'to_date': i.holiday.to_date,
                    'date': i.date,
                    'time': str(i.time).split('.')[0],
                    'is_read': is_read_commmon_status,
                    'holiday': True,
                    'branch': i.for_branch.all(),
                    'tag': i.tag,
                    "symbol": symbol
                })
                i.seen_by.add(employee)
            # if i.notice:
            # symbol += "notice.png"
            #     data.append({
            #         'id':i.id,
            #         'text': i.notice.topic,
            #         'notice_message':i.notice.message,
            #         'date':i.date,
            #         'time':str(i.time).split('.')[0],
            #         'is_read':i.is_read,
            #         'notice':True,
            #         'tag':i.tag,
            # "symbol": symbol
            #     })
        # data = sorted(data, key=lambda i: (i['date'], i['time']), reverse=True)
        context.update({"data": data})
        context.update({"count": count})

        update_notification_settings(employee)
        return render(
            request,
            "notifications/" + template_version + "/notifications.html",
            context)
    except (Exception, employee_models.Employee.DoesNotExist) as e:
        print("Notification API Exception", e)
        return HttpResponseRedirect(reverse('crm_index'))