Пример #1
0
 def serializable_value(self, field_name):
     if field_name == 'business':
         return self.business.serialize(fields=['name'])
     if field_name == 'basicinfo':
         return self.basicinfo.serialize()
     if field_name == 'gallery':
         gallery = self.gallery
         if gallery:
             return gallery.serialize()
         return None
     if field_name == 'category':
         return serialize_query(self.category_set.all())
     if field_name == 'staffservice':
         return serialize_query(self.staffservices_set.all())
     if field_name == 'links':
         return self.links.serialize()
     if field_name == 'contactus':
         return self.contactus.serialize()
     return super(Website, self).serializable_value(field_name)
Пример #2
0
    def get(self, request, *args, **kwargs):
        user = request.user
        business = Business.objects.filter(owner=user).first()

        customers = Customer.objects.list_by_business(business=business)
        id = kwargs.get('id')
        if id:
            custome = Customer.objects.get_one_by_business_and_id(
                business=business, id=id)
            data = custome.serialize()
        else:
            data = serialize_query(customers)

        return JsonResponse(data=data, safe=False)
Пример #3
0
    def get(self, request, *args, **kwargs):
        user = request.user
        business = Business.objects.filter(owner=user).first()

        if kwargs.get('id'):
            id = kwargs.get('id')

            prop = Proposal.objects.get_by_id(id=id, business=business)
            print(prop)
            if prop in Proposal.objects.ERRORS:
                return HttpResponse(status=404)
            data = prop.serialize()
        else:
            proposal = Proposal.objects.get_by_business(business=business)

            data = serialize_query(proposal)

        return JsonResponse(safe=False, data=data)
Пример #4
0
    def get(self, request, *args, **kwargs):
        user = request.user
        business = Business.objects.filter(owner=user).first()
        fields = Event.default_fields + ['proposal']
        if kwargs.get('id'):
            id = kwargs.get('id')

            event = Event.objects.get_event_by(id=id, business=business)

            if event in Event.objects.ERRORS:
                return HttpResponse(status=404)
            data = event.serialize(fields=fields)
        else:
            events = Event.objects.get_events_(business=business)

            data = serialize_query(events, fields=fields)

        return JsonResponse(safe=False, data=data)
Пример #5
0
 def get(self, request, *args, **kwargs):
     model_key = (request.GET.get('model'))
     id = (request.GET.get('id'))
     print(model_key)
     model_id = (request.GET.get('id'))
     model = NOMENCLATOR_CLASS.get(model_key)
     # if model and model_id:
     #     respones = model.objects.get(id = model_id)
     #     return JsonResponse(safe=False, data=respones)
     # try:
     if model:
         if id:
             response = model.objects.get(pk=id)
             respones = response.serialize()
         else:
             # respones = list(model.objects.all().values())
             respones = serialize_query(query_set=model.objects.all())
         return JsonResponse(safe=False, data=respones)
     return HttpResponse(status=400)
Пример #6
0
 def serializable_value(self, field_name):
     if field_name == 'event':
         return self.event.serialize()
     if field_name == 'items':
         return serialize_query(self.item_set.all())
     if field_name == 'can_send':
         cand_send = self.may_send_email() and self.status.id != N_Proposal_Status.PENDING
         return cand_send
     if field_name == 'can_resend':
         can_resend = self.may_send_email() and self.status.id == N_Proposal_Status.PENDING
         return can_resend
     if field_name == 'can_edit':
         can_edit = self.may_be_editted()
         return can_edit
     if field_name == 'invoice':
         invoice = self.invoice_set.first()
         if invoice:
             return invoice.serialize()
         return None
     return super(Proposal, self).serializable_value(field_name)
Пример #7
0
    def get(self, request, *args, **kwargs):
        user = request.user
        business = Business.objects.filter(owner=user).first()

        if kwargs.get('id'):
            id = kwargs.get('id')

            inv = Invoice.objects.get_by_id(id=id, business=business)

            if inv in Invoice.objects.ERRORS:
                return HttpResponse(status=404)
            data = inv.proposal.serialize(fields=Proposal.default_fields + ['invoice'])
        else:
            # proposal = Proposal.objects.annotate(ni=Count('invoice')).filter(ni=1).\
            #     filter(event__customer__business=business).filter(invoice__deleted=True)
            invocies = Proposal.objects.get_invoices_all(business=business)

            data = serialize_query(invocies, fields=Proposal.default_fields + ['invoice'])

        return JsonResponse(safe=False, data=data)
Пример #8
0
    def post(self, request):
        user = request.user
        business = Business.objects.filter(owner=user).first()

        form = CustomerImportForm(request.POST, request.FILES)
        print(request.FILES)
        if form.is_valid():
            # print(request.FILES['excel'])

            data = request.FILES['file']
            params = data.get_params()
            if params.get('file_type') not in ['xls']:
                return HttpResponse(status=400,
                                    content='Tipo de archivo incorrecto')

            result = pyexcel.get_sheet(
                file_type=params.get('file_type'),
                file_content=params.get('file_content'),
                colnames=[
                    'Apellidos', 'Ciudad', 'Codigo Postal', 'Compania',
                    'Correo', 'Estado', 'Fecha de Nacimiento', 'Line 1',
                    'Line 2', 'Nombre', 'Pais', 'Telefono', 'Telefono Casa'
                ])

            # print(result.to_array())
            # print(result.to_dict())
            records = result.to_records()

            result = Customer.objects.import_from_excel(records=records,
                                                        business=business)

            if result in Customer.objects.ERRORS:
                return HttpResponse(
                    status=400,
                    content=
                    "Problema en los datos suministrados. Verfique que existan clientes con "
                    "correo repetido")

            return JsonResponse(safe=False, data=serialize_query(result))  #
        return JsonResponse(status=400, data=form.errors.as_json(), safe=False)
Пример #9
0
    def serializable_value(self, field_name):
        if field_name == 'states':

            return serialize_query(self.n_state_set.all())
        return super(N_Country, self).serializable_value(field_name)
Пример #10
0
 def serializable_value(self, field_name):
     if field_name == 'photo':
         return serialize_query(self.photo_set.all())
     return super(Gallery, self).serializable_value(field_name)
Пример #11
0
 def serializable_value(self, field_name):
     if field_name == 'menuprice':
         return serialize_query(self.menuprice_set.all())
     if field_name == 'image':
             return self.image._get_url()
     return super(Menu, self).serializable_value(field_name)
Пример #12
0
 def serializable_value(self, field_name):
     if field_name == 'menu':
         return serialize_query(self.menu_set.all())
     return super(Category, self).serializable_value(field_name)