Update auto channel sync settings for M3U account groups
(self, request, pk=None)
| 494 | |
| 495 | @action(detail=True, methods=["patch"], url_path="group-settings") |
| 496 | def update_group_settings(self, request, pk=None): |
| 497 | """Update auto channel sync settings for M3U account groups""" |
| 498 | account = self.get_object() |
| 499 | group_settings = request.data.get("group_settings", []) |
| 500 | category_settings = request.data.get("category_settings", []) |
| 501 | |
| 502 | try: |
| 503 | for setting in group_settings: |
| 504 | start = setting.get("auto_sync_channel_start") |
| 505 | end = setting.get("auto_sync_channel_end") |
| 506 | if (start is not None and start < 1) or ( |
| 507 | end is not None and end < 1 |
| 508 | ): |
| 509 | return Response( |
| 510 | { |
| 511 | "error": ( |
| 512 | f"Channel group {setting.get('channel_group')}: " |
| 513 | f"channel range must be >= 1." |
| 514 | ) |
| 515 | }, |
| 516 | status=status.HTTP_400_BAD_REQUEST, |
| 517 | ) |
| 518 | if start is not None and end is not None and end < start: |
| 519 | return Response( |
| 520 | { |
| 521 | "error": ( |
| 522 | f"Channel group {setting.get('channel_group')}: " |
| 523 | f"auto_sync_channel_end must be >= " |
| 524 | f"auto_sync_channel_start." |
| 525 | ) |
| 526 | }, |
| 527 | status=status.HTTP_400_BAD_REQUEST, |
| 528 | ) |
| 529 | |
| 530 | with transaction.atomic(): |
| 531 | group_objects = [ |
| 532 | ChannelGroupM3UAccount( |
| 533 | channel_group_id=setting["channel_group"], |
| 534 | m3u_account=account, |
| 535 | enabled=setting.get("enabled", True), |
| 536 | auto_channel_sync=setting.get("auto_channel_sync", False), |
| 537 | auto_sync_channel_start=setting.get("auto_sync_channel_start"), |
| 538 | auto_sync_channel_end=setting.get("auto_sync_channel_end"), |
| 539 | custom_properties=ensure_custom_properties_dict( |
| 540 | setting.get("custom_properties") |
| 541 | ), |
| 542 | ) |
| 543 | for setting in group_settings |
| 544 | if setting.get("channel_group") |
| 545 | ] |
| 546 | |
| 547 | if group_objects: |
| 548 | ChannelGroupM3UAccount.objects.bulk_create( |
| 549 | group_objects, |
| 550 | update_conflicts=True, |
| 551 | unique_fields=["channel_group", "m3u_account"], |
| 552 | update_fields=[ |
| 553 | "enabled", |
nothing calls this directly
no test coverage detected