Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_last_synchronization(self):
"""
Return the last synchronization.
"""
try:
return Synchronization.objects.latest("time")
except Synchronization.DoesNotExist:
pass
return None
def get_last_synchronization(self):
"""
Return the last synchronization.
"""
try:
return Synchronization.objects.latest("time")
except Synchronization.DoesNotExist:
pass
return None
number_of_changes = (
objects_changes["added"]
+ objects_changes["updated"]
+ objects_changes["deleted"]
)
# Save the last sync time only if objects were retrieved
if number_of_changes > 0:
values = {
"time": time,
"added": objects_changes["added"],
"updated": objects_changes["updated"],
"deleted": objects_changes["deleted"],
}
last_sync = Synchronization(**values)
last_sync.save()
self.logger.debug(
"synchronizated %s objects at %s", number_of_changes, last_sync.time
)
return last_sync
from django.contrib import admin
from .models import Network, NetworkIXLAN, PeerRecord, Prefix, Synchronization
admin.site.register(Network)
admin.site.register(NetworkIXLAN)
admin.site.register(PeerRecord)
admin.site.register(Prefix)
admin.site.register(Synchronization)
# Check whether a new release is available for staff and superuser
new_release = None
if request.user.is_staff or request.user.is_superuser:
latest_release, release_url = get_latest_release()
if isinstance(latest_release, version.Version):
current_version = version.parse(settings.VERSION)
if latest_release > current_version:
new_release = {"version": str(latest_release), "url": release_url}
context = {
"statistics": statistics,
"changelog": ObjectChange.objects.select_related(
"user", "changed_object_type"
)[:50],
"synchronizations": Synchronization.objects.all()[:5],
"new_release": new_release,
}
return render(request, "home.html", context)
class NetworksViewSet(ReadOnlyModelViewSet):
queryset = Network.objects.all()
serializer_class = NetworkSerializer
filterset_class = NetworkFilterSet
class PeerRecordViewSet(ModelViewSet):
queryset = PeerRecord.objects.all()
serializer_class = PeerRecordSerializer
filterset_class = PeerRecordFilterSet
class SynchronizationViewSet(ReadOnlyModelViewSet):
queryset = Synchronization.objects.all()
serializer_class = SynchronizationSerializer
filterset_class = SynchronizationFilterSet