def process_var_datum(self, var_datum): pk = str(var_datum["pk"]) deleted = var_datum.get("DELETE") if pk.startswith("$"): # New variable. var = ProductVariationVariable(product=self.parent_product) else: var = ProductVariationVariable.objects.get( product=self.parent_product, pk=pk) if deleted: if var.pk: var.delete() return var.identifier = var_datum.get("identifier") or get_random_string() var.save() for lang_code, name in var_datum["names"].items(): var.set_current_language(lang_code) var.name = name var.save_translations() for val_datum in var_datum["values"]: self.process_val_datum(var, val_datum) if not var.values.exists( ): # All values gone, so delete the skeleton variable too var.delete()
def process_var_datum(self, var_datum, ordering): deleted = var_datum.get("DELETE") var = ProductVariationVariable(product=self.parent_product) if deleted: if var.pk: var.delete() return var.identifier = var_datum.get("identifier") or get_random_string() var.ordering = ordering var.save() for lang_code, name in var_datum["names"].items(): var.set_current_language(lang_code) var.name = name var.save_translations() for ordering, val_datum in enumerate(var_datum["values"]): self.process_val_datum(var, val_datum, ordering) if not var.values.exists(): # All values gone, so delete the skeleton variable too var.delete()
def process_var_datum(self, var_datum): pk = str(var_datum["pk"]) deleted = var_datum.get("DELETE") if pk.startswith("$"): # New variable. var = ProductVariationVariable(product=self.parent_product) else: var = ProductVariationVariable.objects.get(product=self.parent_product, pk=pk) if deleted: if var.pk: var.delete() return var.identifier = var_datum.get("identifier") or get_random_string() var.save() for lang_code, name in var_datum["names"].items(): var.set_current_language(lang_code) var.name = name var.save_translations() for val_datum in var_datum["values"]: self.process_val_datum(var, val_datum) if not var.values.exists(): # All values gone, so delete the skeleton variable too var.delete()