Пример #1
0
    def get(request, vendor_id):
        if 'token' not in request.session:
            return render(request, 'customer/index.html')
        logged_in_user = Session.get_user_by_session(request.session['token'])
        if logged_in_user is None:
            return render(request, 'customer/index.html')

        if logged_in_user.user_type == constants.USER_TYPE_ADMIN:
            '''admin'''
            logged_in_user_object = UserAdmin.objects.get(user=logged_in_user)
            vendor_object = UserServiceProvider.objects.get(pk=vendor_id)
            vendor_services = UserServiceProviderItem.objects.filter(
                user=vendor_object)
            vendor_areas = UserServiceProviderArea.objects.filter(
                user=vendor_object)
            return render(
                request, 'admin_vendor/detail_vendor.html', {
                    'admin': True,
                    'logged_in_user_object': logged_in_user_object,
                    'vendor_object': vendor_object,
                    'vendor_areas': vendor_areas,
                    'vendor_services': vendor_services
                })
        else:
            return render(request, 'customer/index.html')
Пример #2
0
    def get(request, order_id):
        if 'token' not in request.session:
            return render(request, 'customer/index.html')
        logged_in_user = Session.get_user_by_session(request.session['token'])
        if logged_in_user is None:
            return render(request, 'customer/index.html')

        if logged_in_user.user_type == constants.USER_TYPE_ADMIN:
            '''admin'''
            selected_order = Order.objects.get(pk=order_id)
            logged_in_user_object = UserAdmin.objects.get(user=logged_in_user)
            all_orders = Order.objects.all()
            all_vendors = UserServiceProvider.objects.filter(active=True)
            all_items = Item.objects.filter(active=True)
            all_areas = Area.objects.filter(active=True).order_by('area_name')
            return render(
                request, 'admin_vendor/detail_order.html', {
                    'admin': True,
                    'all_vendors': all_vendors,
                    'selected_order': selected_order,
                    'all_areas': all_areas,
                    'all_items': all_items,
                    'logged_in_user_object': logged_in_user_object
                })
        else:
            return render(request, 'customer/index.html')
Пример #3
0
    def get(request):
        if 'token' not in request.session:
            return render(request, 'customer/index.html')
        logged_in_user = Session.get_user_by_session(request.session['token'])
        if logged_in_user is None:
            return render(request, 'customer/index.html')

        if logged_in_user.user_type == constants.USER_TYPE_ADMIN:
            '''admin'''
            logged_in_user_object = UserAdmin.objects.get(user=logged_in_user)
            if 'toggle' in request.GET:
                toggle_vendor = UserServiceProvider.objects.get(
                    pk=request.GET['toggle'])
                toggle_vendor.active = not toggle_vendor.active
                toggle_vendor.save()
                return redirect(reverse('list_vendor'))
            vendors = UserServiceProvider.objects.all()
            return render(
                request, 'admin_vendor/list_vendor.html', {
                    'admin': True,
                    'logged_in_user_object': logged_in_user_object,
                    'vendors': vendors
                })
        else:
            return render(request, 'customer/index.html')
Пример #4
0
 def get(request):
     if 'token' not in request.session:
         return redirect(reverse('home'))
     logged_in_user = Session.get_user_by_session(request.session['token'])
     if logged_in_user is None:
         return redirect(reverse('home'))
     logged_in_user_object = UserClient.objects.get(user=logged_in_user)
     return render(request, 'order/change_password.html',
                   {'logged_in_user_object': logged_in_user_object})
Пример #5
0
 def get(request, oid):
     logged_in_user = Session.get_user_by_session(request.session['token'])
     client = UserClient.objects.get(user=logged_in_user)
     order = Order.objects.get(ok=oid)
     if order.customer == client:
         # change order state
         pass
     else:
         # do not change order state
         pass
     # todo have to add a order taking page with client info and order details
     return redirect(reverse('home'))
Пример #6
0
    def get(request):
        if 'token' not in request.session:
            return render(request, 'customer/index.html')

        logged_in_user = Session.get_user_by_session(request.session['token'])
        if logged_in_user is None:
            return render(request, 'customer/index.html')

        if logged_in_user.user_type == constants.USER_TYPE_CLIENT:
            logged_in_user_object = UserClient.objects.get(user=logged_in_user)
            return render(request, 'customer/index.html', {
                'client': True,
                'logged_in_user_object': logged_in_user_object
            })

        elif logged_in_user.user_type == constants.USER_TYPE_SERVICE_PROVIDER:
            '''service provider'''
            return render(request, 'admin_vendor/vendor_index.html')

        elif logged_in_user.user_type == constants.USER_TYPE_ADMIN:
            '''admin'''
            yesterday = datetime.date.today() - datetime.timedelta(days=1)
            total_order = Order.objects.all().count()
            pending_order = Order.objects.filter(
                status=constants.ORDER_STATUS_PENDING).count()
            total_user = UserClient.objects.all().count()
            new_users = UserClient.objects.filter(
                created_at__gt=yesterday).count()
            total_vendor = UserServiceProvider.objects.all().count()
            service_today = Order.objects.filter(
                status=constants.ORDER_STATUS_COMPLETED,
                last_updated__gt=yesterday).count()
            last_5_orders = Order.objects.filter(
                status=constants.ORDER_STATUS_PENDING)[:5]
            last_5_users = UserClient.objects.all()[:5]
            last_5_vendors = UserServiceProvider.objects.all()[:5]
            logged_in_user_object = UserAdmin.objects.get(user=logged_in_user)
            return render(
                request, 'admin_vendor/admin_index.html', {
                    'admin': True,
                    'total_order': total_order,
                    'logged_in_user_object': logged_in_user_object,
                    'pending_order': pending_order,
                    'total_user': total_user,
                    'new_users': new_users,
                    'total_vendor': total_vendor,
                    'service_today': service_today,
                    'last_5_orders': last_5_orders,
                    'last_5_users': last_5_users,
                    'last_5_vendors': last_5_vendors
                })
Пример #7
0
    def get(request):
        if 'token' not in request.session:
            return redirect(reverse('home'))
        logged_in_user = Session.get_user_by_session(request.session['token'])
        if logged_in_user is None:
            return redirect(reverse('home'))

        if logged_in_user.user_type == constants.USER_TYPE_CLIENT:
            '''client'''
            logged_in_user_object = UserClient.objects.get(user=logged_in_user)
            return render(request, 'order/index.html', {
                'admin': True,
                'logged_in_user_object': logged_in_user_object
            })
        return redirect(reverse('home'))
Пример #8
0
    def post(request):
        if 'token' not in request.session:
            return render(request, 'customer/index.html')
        logged_in_user = Session.get_user_by_session(request.session['token'])
        if logged_in_user is None:
            return render(request, 'customer/index.html')

        if logged_in_user.user_type == constants.USER_TYPE_ADMIN:
            '''admin'''
            logged_in_user_object = UserAdmin.objects.get(user=logged_in_user)

            first_name = request.POST['first_name']
            last_name = request.POST['last_name']
            user_name = None
            phone_number = request.POST['phone_number']
            user_email = request.POST['user_email']
            address = request.POST['address']
            password = '******'
            if is_new_user(user_name, phone_number, user_email):
                hash_key = UUID.uuid_generator()
                add_to_login_list(hash_key, user_email, password)
                listed_user = add_to_user_list(user_name, phone_number,
                                               user_email, hash_key,
                                               constants.USER_TYPE_CLIENT)
                new_user = UserClient(user=listed_user,
                                      first_name=first_name,
                                      last_name=last_name,
                                      phone_number=phone_number,
                                      address=address,
                                      user_email=user_email)
                new_user.save()
                return render(
                    request, 'admin_vendor/add_user.html', {
                        'success': True,
                        'admin': True,
                        'logged_in_user_object': logged_in_user_object,
                        'message': 'Successfully Added!'
                    })
            else:
                return render(
                    request, 'admin_vendor/add_user.html', {
                        'alert': True,
                        'admin': True,
                        'logged_in_user_object': logged_in_user_object,
                        'message': 'User Already Registered!'
                    })
        else:
            return render(request, 'customer/index.html')
Пример #9
0
    def get(request):
        if 'token' not in request.session:
            return render(request, 'customer/index.html')
        logged_in_user = Session.get_user_by_session(request.session['token'])
        if logged_in_user is None:
            return render(request, 'customer/index.html')

        if logged_in_user.user_type == constants.USER_TYPE_ADMIN:
            '''admin'''
            logged_in_user_object = UserAdmin.objects.get(user=logged_in_user)
            return render(request, 'admin_vendor/add_user.html', {
                'admin': True,
                'logged_in_user_object': logged_in_user_object
            })
        else:
            return render(request, 'customer/index.html')
Пример #10
0
    def get(request):
        if 'token' not in request.session:
            return redirect(reverse('home'))
        logged_in_user = Session.get_user_by_session(request.session['token'])
        if logged_in_user is None:
            return redirect(reverse('home'))

        if logged_in_user.user_type == constants.USER_TYPE_CLIENT:
            '''client'''
            logged_in_user_object = UserClient.objects.get(user=logged_in_user)
            all_orders = Order.objects.filter(customer=logged_in_user_object)
            return render(
                request, 'customer/service_list.html', {
                    'admin': True,
                    'all_orders': all_orders,
                    'logged_in_user_object': logged_in_user_object
                })
        return redirect(reverse('home'))
Пример #11
0
    def get(request, client_id):
        if 'token' not in request.session:
            return render(request, 'customer/index.html')
        logged_in_user = Session.get_user_by_session(request.session['token'])
        if logged_in_user is None:
            return render(request, 'customer/index.html')

        if logged_in_user.user_type == constants.USER_TYPE_ADMIN:
            '''admin'''
            logged_in_user_object = UserAdmin.objects.get(user=logged_in_user)
            client_object = UserClient.objects.get(pk=client_id)
            client_orders = Order.objects.filter(customer=client_object)
            return render(
                request, 'admin_vendor/detail_user.html', {
                    'admin': True,
                    'logged_in_user_object': logged_in_user_object,
                    'client_object': client_object,
                    'client_orders': client_orders
                })
        else:
            return render(request, 'customer/index.html')
Пример #12
0
    def get(request):
        if 'token' not in request.session:
            return render(request, 'customer/index.html')
        logged_in_user = Session.get_user_by_session(request.session['token'])
        if logged_in_user is None:
            return render(request, 'customer/index.html')

        if logged_in_user.user_type == constants.USER_TYPE_ADMIN:
            '''admin'''
            logged_in_user_object = UserAdmin.objects.get(user=logged_in_user)
            all_items = Item.objects.filter(active=True)
            all_areas = Area.objects.filter(active=True).order_by('area_name')
            return render(
                request, 'admin_vendor/add_vendor.html', {
                    'admin': True,
                    'all_areas': all_areas,
                    'all_items': all_items,
                    'logged_in_user_object': logged_in_user_object
                })
        else:
            return render(request, 'customer/index.html')
Пример #13
0
    def get(request):
        if 'token' not in request.session:
            return redirect(reverse('home'))
        logged_in_user = Session.get_user_by_session(request.session['token'])
        if logged_in_user is None:
            return redirect(reverse('home'))

        if logged_in_user.user_type == constants.USER_TYPE_CLIENT:
            '''client'''
            logged_in_user_object = UserClient.objects.get(user=logged_in_user)
            electric_items = Item.objects.filter(
                service_type=constants.SERVICE_TYPE_VEHICLE)
            areas = Area.objects.all()
            return render(
                request, 'order/vehicle.html', {
                    'admin': True,
                    'electric_items': electric_items,
                    'areas': areas,
                    'logged_in_user_object': logged_in_user_object
                })
        return redirect(reverse('home'))
Пример #14
0
 def post(request):
     logged_in_user = Session.get_user_by_session(request.session['token'])
     client = UserClient.objects.get(user=logged_in_user)
     area = Area.objects.get(area_name=request.POST['area'])
     item = Item.objects.get(item_name=request.POST['item'])
     new_order = Order(customer=client,
                       area=area,
                       item=item,
                       brand=request.POST['brand'],
                       model=request.POST['model'],
                       service_type=int(request.POST['service_type']),
                       date=request.POST['date'],
                       address=request.POST['address'],
                       instruction=request.POST['instruction'],
                       description=request.POST['description'])
     new_order.save()
     greeting_text = 'We received your order. Allow us some time, and we will contact you as soon as possible.' \
                     ' Happy Fixing!'
     send_now(client.phone_number, greeting_text)
     send_now('01737233902', 'New order! Please check fixkori!')
     return redirect(reverse('home'))
Пример #15
0
    def get(request, order_id):
        print(order_id)
        if 'token' not in request.session:
            return redirect(reverse('home'))
        logged_in_user = Session.get_user_by_session(request.session['token'])
        if logged_in_user is None:
            return redirect(reverse('home'))

        if logged_in_user.user_type == constants.USER_TYPE_CLIENT:
            '''client'''
            logged_in_user_object = UserClient.objects.get(user=logged_in_user)
            selected_order = Order.objects.get(pk=order_id)
            if selected_order.customer == logged_in_user_object:

                return render(
                    request, 'customer/service_detail.html', {
                        'admin': True,
                        'selected_order': selected_order,
                        'logged_in_user_object': logged_in_user_object
                    })
            else:
                return redirect(reverse('service_list'))
        return redirect(reverse('home'))
Пример #16
0
    def post(request):
        logged_in_user = Session.get_user_by_session(request.session['token'])
        logged_in_user_object = UserClient.objects.get(user=logged_in_user)
        if 'csrfmiddlewaretoken' in request.POST:

            u = User.objects.get(username=logged_in_user.user_id)
            u.set_password(request.POST['password'])
            u.save()
            update_session_auth_hash(request, u)
            return render(
                request, 'order/change_password.html', {
                    'page_title': 'CHANGE PASSWORD',
                    'success': True,
                    'message': 'Password Successfully Changed',
                    'logged_in_user_object': logged_in_user_object
                })

        else:
            return render(
                request, 'order/change_password.html', {
                    'page_title': 'CHANGE PASSWORD',
                    'logged_in_user_object': logged_in_user_object
                })
Пример #17
0
 def get(request):
     logged_in_user = Session.get_user_by_session(request.session['token'])
     client = UserClient.objects.get(user=logged_in_user)
     # todo have to add a order taking page with client info
     return redirect(reverse('home'))
Пример #18
0
    def post(request):
        if 'token' not in request.session:
            return render(request, 'customer/index.html')
        logged_in_user = Session.get_user_by_session(request.session['token'])
        if logged_in_user is None:
            return render(request, 'customer/index.html')

        if logged_in_user.user_type == constants.USER_TYPE_ADMIN:
            '''admin'''
            logged_in_user_object = UserAdmin.objects.get(user=logged_in_user)
            first_name = request.POST['first_name']
            last_name = request.POST['last_name']
            user_name = request.POST['user_name']
            phone_number = request.POST['phone_number']
            email = request.POST['email']
            address = request.POST['address']
            service_point_name = request.POST['service_point_name']
            image_1 = request.FILES['image_1']
            image_2 = request.FILES['image_2']
            image_3 = request.FILES['image_3']
            image_4 = request.FILES['image_4']
            image_5 = request.FILES['image_5']
            about = request.POST['about']
            services = request.POST['services']
            facebook_url = request.POST['facebook_url']
            google_map_url = request.POST['google_map_url']

            password = '******'
            all_items = Item.objects.filter(active=True)
            all_areas = Area.objects.filter(
                active=True).order_by('area_name').reverse()
            # todo have to add random number and send it to user via SMS
            if is_new_user(user_name, phone_number, email):
                hash_key = UUID.uuid_generator()
                add_to_login_list(hash_key, email, password)
                listed_user = add_to_user_list(
                    user_name, phone_number, email, hash_key,
                    constants.USER_TYPE_SERVICE_PROVIDER)
                new_user = UserServiceProvider(
                    user=listed_user,
                    first_name=first_name,
                    last_name=last_name,
                    address=address,
                    phone_number=phone_number,
                    service_point_name=service_point_name,
                    image_1=image_1,
                    image_2=image_2,
                    image_3=image_3,
                    image_4=image_4,
                    image_5=image_5,
                    about=about,
                    services=services,
                    facebook_url=facebook_url,
                    google_map_url=google_map_url,
                    email=email)
                new_user.save()
                areas = request.POST.getlist('area')
                items = request.POST.getlist('item')
                for area in areas:
                    selected_area = Area.objects.get(id=area)
                    new_assigned_area = UserServiceProviderArea(
                        user=new_user, area=selected_area)
                    new_assigned_area.save()

                for item in items:
                    selected_item = Item.objects.get(id=item)
                    new_assigned_item = UserServiceProviderItem(
                        user=new_user, item=selected_item)
                    new_assigned_item.save()

                return render(
                    request, 'admin_vendor/add_vendor.html', {
                        'admin': True,
                        'success': True,
                        'message': 'Successfully Added!',
                        'all_areas': all_areas,
                        'all_items': all_items,
                        'logged_in_user_object': logged_in_user_object
                    })
            else:
                return render(
                    request, 'admin_vendor/add_vendor.html', {
                        'admin': True,
                        'alert': True,
                        'message': 'User Already Registered!',
                        'all_areas': all_areas,
                        'all_items': all_items,
                        'logged_in_user_object': logged_in_user_object
                    })
Пример #19
0
 def get(request, oid):
     logged_in_user = Session.get_user_by_session(request.session['token'])
     client = UserClient.objects.get(user=logged_in_user)
     # todo have to send user object
     return redirect(reverse('home'))
Пример #20
0
 def get(request):
     logged_in_user = Session.get_user_by_session(request.session['token'])
     client = UserClient.objects.get(user=logged_in_user)
     all_orders = Order.objects.filter(customer=client)
     # todo have to add a order taking page with client info and all_order List
     return redirect(reverse('home'))