def append_order_logistics_info(ctx, extra_ctx, **kwargs): """ :param ctx: :param extra_ctx: :param kwargs: :return: """ l_type = ctx["l_type"] parameter = extra_ctx["parameter"] order = extra_ctx["order"] # type: OrderInfo dmseri = OrderLogisticsInfoSubmitSerializer(data=parameter["loginfo"]) if not dmseri.is_valid(): raise WLException(400, errors_summery(dmseri)) try: logistics = OrderLogisticsInfo.objects.get(oid=order, l_type=l_type) update_instance_from_dict(logistics, dmseri.validated_data, False) except OrderLogisticsInfo.DoesNotExist: logistics = OrderLogisticsInfo(**dmseri.validated_data) logistics.oid = order logistics.l_type = ctx["l_type"] logistics.save()
def validate_serializer(self, serializer, exc_code=None): if not serializer.is_valid(): message = errors_summery(serializer) raise WLException(message=message, code=exc_code if exc_code is not None else self.DEFAULT_VALIDATE_EXC_CODE)
def append_order_protocol_info(extra_ctx, **kwargs): # Create default protocol, but without initialize it. # The initialization is done the same time when seller agree this protocol. parameter = extra_ctx["parameter"] order = extra_ctx["order"] # type: OrderInfo pseri = OrderProtocolSubmitSerializer(data=parameter["protocol"]) if not pseri.is_valid(): raise WLException(400, errors_summery(pseri)) _validate_and_close_existing_protocol(order) new_protocol = OrderProtocol() new_protocol.op_type = pseri.validated_data["op_type"] new_protocol.description = pseri.validated_data["description"] new_protocol.c_price = pseri.validated_data.get("c_price", None) new_protocol.oid = order new_protocol.p_status = p_status_choice.CREATED new_protocol.init_p_operate_status() new_protocol.save()