Example #1
0
 def get_user_details(self, username, base_url):
     user = User.objects.get(username=username)
     business = Utilities.get_user_business(user)
     profile = UserProfile.objects.get(user__id=user.id)
     return {
         'id': user.id,
         'username': user.username,
         'isStaff': user.is_staff,
         'isSuperuser': user.is_superuser,
         'firstName': user.first_name,
         'lastName': user.last_name,
         'businessId': business.bp_id,
         'currency': business.app_profile.currency,
         'businessName': business.bp_name,
         'businessAdmin': business.bp_admin,
         'smallProfilePic': profile.get_profile_pic(base_url),
         'notify': {
             'newTransaction': profile.notify_new_transaction,
             'shipmentArrival': profile.notify_shipment_arrival,
             'messages': profile.notify_messages,
             'monthlyReports': profile.notify_monthly_reports,
             'weeklyReports': profile.notify_weekly_reports,
             'dailyReports': profile.notify_daily_reports
         },
         'rights': {
             'businessAnalytics': profile.right_business_analytics,
             'userManagement': profile.right_user_management,
             'warehouseModule': profile.right_warehouse_module,
             'businessCommission': profile.right_business_commission
         }
     }
Example #2
0
 def post(self, request, *args, **kwargs):
     user = request.user
     business = Utilities.get_user_business(user)
     name = request.data.get('name')
     drop_down_obj = self.model.objects.create(name=name,
                                               created_at=timezone.now(),
                                               created_by=user,
                                               updated_at=None,
                                               business=business)
     return Response({'obj': drop_down_obj.get_list_obj()},
                     status=status.HTTP_200_OK)
Example #3
0
 def get(self, request, *args, **kwargs):
     user = request.user
     business = Utilities.get_user_business(user)
     q = request.GET.get('q')
     if q == 'all' or q == 'drop_down':
         result_objects = self.model.objects.filter(created_by__profile__business=business).order_by('name')
         if q == 'all':
             results = [res.drop_down_obj() if not hasattr(res, 'get_list_obj') else res.get_list_obj() for res in result_objects]
         else:
             results = [res.drop_down_obj() for res in result_objects]
         return Response({'list': results}, status=status.HTTP_200_OK)
     else:
         result_object = self.model.objects.get(id=int(q))
         return Response({'object': result_object.get_list_obj()}, status=status.HTTP_200_OK)
Example #4
0
 def get_user_details(self, username, base_url):
     user = User.objects.get(username=username)
     business = Utilities.get_user_business(user)
     profile = UserProfile.objects.get(user__id=user.id)
     return {
         'id': user.id,
         'username': user.username,
         'isStaff': user.is_staff,
         'isSuperuser': user.is_superuser,
         'firstName': user.first_name,
         'lastName': user.last_name,
         'businessId': business.bp_id,
         'businessName': business.bp_name,
         'smallProfilePic': profile.get_profile_pic(base_url)
     }
Example #5
0
 def get(self, request, *args, **kwargs):
     user = request.user
     business = Utilities.get_user_business(user)
     print request.GET
     q = request.GET.get('q')
     if q == 'all' or q == 'drop_down':
         result_objects = self.model.objects.filter(business=business)
         if q == 'all':
             results = [res.get_list_obj() for res in result_objects]
         else:
             results = [res.drop_down_obj() for res in result_objects]
         return Response({'list': results}, status=status.HTTP_200_OK)
     else:
         result_object = self.model.objects.get(id=int(q))
         return Response({'object': result_object.get_list_obj()},
                         status=status.HTTP_200_OK)
 def get(self, request, *args, **kwargs):
     user = request.user
     business = Utilities.get_user_business(user)
     q = request.GET.get('q')
     if q == 'all' or q == 'drop_down':
         if q == 'all':
             locations = BpLocation.objects.filter(bp=business)
             locations = [loc.get_obj() for loc in locations]
         else:
             locations = BpLocation.drop_down_obj(business)
             print locations
         return Response({'locations': locations}, status=status.HTTP_200_OK)
     else:
         location = BpLocation.objects.get(id=q)
         location = location.get_obj()
         return Response({'location': location}, status=status.HTTP_200_OK)
Example #7
0
 def get(self, request, *args, **kwargs):
     user = request.user
     q = request.GET.get('q')
     base_url = request.META.get('HTTP_HOST')
     business = Utilities.get_user_business(user)
     if q == self.ALL_QUERY or q == self.DROP_DOWN_QUERY:
         all_users = UserProfile.objects.filter(business=business)
         return Response(
             {
                 'list':
                 [user.get_list_obj(request.user.id) for user in all_users]
             },
             status=status.HTTP_200_OK)
     else:
         profile = UserProfile.objects.get(user__id=int(q))
         return Response({'user': profile.complete_profile(base_url)},
                         status=status.HTTP_200_OK)