MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / _get_sd_changes_remaining

Method _get_sd_changes_remaining

apps/epg/api_views.py:166–190  ·  view source on GitHub ↗

Retrieve stored changesRemaining from EPGSource model field. If a reset timestamp exists and has passed (midnight UTC), clears the lockout automatically so the user can make adds again.

(self, source)

Source from the content-addressed store, hash-verified

164 return reset_at_str
165
166 def _get_sd_changes_remaining(self, source):
167 """
168 Retrieve stored changesRemaining from EPGSource model field.
169 If a reset timestamp exists and has passed (midnight UTC), clears the
170 lockout automatically so the user can make adds again.
171 """
172 from django.utils import timezone
173
174 cp = source.custom_properties or {}
175 changes_remaining = cp.get('sd_changes_remaining')
176 reset_at_str = cp.get('sd_changes_reset_at')
177 from django.utils.dateparse import parse_datetime
178 reset_at = parse_datetime(reset_at_str) if reset_at_str else None
179
180 # If we have a reset timestamp and it has passed, clear the lockout
181 if changes_remaining == 0 and reset_at:
182 if timezone.now() >= reset_at:
183 cp = source.custom_properties or {}
184 cp.pop('sd_changes_remaining', None)
185 cp.pop('sd_changes_reset_at', None)
186 source.custom_properties = cp
187 source.save(update_fields=['custom_properties'])
188 return None
189
190 return changes_remaining
191
192 def _save_sd_changes_remaining(self, source, changes_remaining):
193 """Persist changesRemaining to EPGSource model field."""

Callers 1

sd_lineupsMethod · 0.95

Calls 2

getMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected