def create_restriction(group, external_id, name): model = models.Restriction.objects.create(group=group, external_id=external_id, name=name) restriction = objects.Restriction.from_model(model) restrictions_storage.add_item(restriction.id, restriction) restrictions_storage.update_version() return restriction
def sync_restriction(group, external_id, name): restriction = restrictions_storage.get_restriction(group, external_id) if restriction is None: return create_restriction(group, external_id, name) restriction.name = name models.Restriction.objects.filter(id=restriction.id).update(name=name) restrictions_storage.update_version() return restriction