update for location layer delete

This commit is contained in:
Mohamed Nouffer
2022-06-21 16:32:11 +05:30
parent 44cc4ce0ca
commit 3ec4d108b2
3 changed files with 46 additions and 2 deletions

View File

@ -2,7 +2,7 @@ from django.contrib import admin
from leaflet.admin import LeafletGeoAdmin from leaflet.admin import LeafletGeoAdmin
from leaflet.admin import LeafletGeoAdminMixin from leaflet.admin import LeafletGeoAdminMixin
from leaflet_admin_list.admin import LeafletAdminListMixin from leaflet_admin_list.admin import LeafletAdminListMixin
from .models import RogUser, Location, SystemSettings, JoinedEvent, Favorite, TravelList, TravelPoint, ShapeLayers, Event, Location_line, Location_polygon, JpnAdminMainPerf, JpnAdminPerf, JpnSubPerf, Useractions, CustomUser, GifuAreas, UserTracks from .models import RogUser, Location, SystemSettings, JoinedEvent, Favorite, TravelList, TravelPoint, ShapeLayers, Event, Location_line, Location_polygon, JpnAdminMainPerf, JpnAdminPerf, JpnSubPerf, Useractions, CustomUser, GifuAreas, UserTracks, ShapeFileLocations
from django.contrib.auth.admin import UserAdmin from django.contrib.auth.admin import UserAdmin
class RogAdmin(LeafletAdminListMixin, LeafletGeoAdminMixin, admin.ModelAdmin): class RogAdmin(LeafletAdminListMixin, LeafletGeoAdminMixin, admin.ModelAdmin):
@ -50,5 +50,6 @@ admin.site.register(UserTracks, LeafletGeoAdmin);
admin.site.register(GifuAreas, LeafletGeoAdmin) admin.site.register(GifuAreas, LeafletGeoAdmin)
admin.site.register(JpnSubPerf, LeafletGeoAdmin) admin.site.register(JpnSubPerf, LeafletGeoAdmin)
admin.site.register(ShapeLayers, admin.ModelAdmin) admin.site.register(ShapeLayers, admin.ModelAdmin)
#admin.site.register(ShapeFileLocations, admin.ModelAdmin)
admin.site.register(CustomUser, UserAdminConfig) admin.site.register(CustomUser, UserAdminConfig)

View File

@ -0,0 +1,21 @@
# Generated by Django 3.2.9 on 2022-06-21 09:46
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('rog', '0015_auto_20220619_1611'),
]
operations = [
migrations.CreateModel(
name='ShapeFileLocations',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('shapefile', models.CharField(blank=True, max_length=2048, null=True, verbose_name='Shapelayer')),
('locid', models.IntegerField(blank=True, null=True)),
],
),
]

View File

@ -452,6 +452,10 @@ class ShapeLayers(models.Model):
def __str__(self): def __str__(self):
return self.name return self.name
class ShapeFileLocations(models.Model):
shapefile=models.CharField(_('Shapelayer'), max_length=2048 ,blank=True, null=True)
locid=models.IntegerField(blank=True, null=True)
def remove_bom_inplace(path): def remove_bom_inplace(path):
"""Removes BOM mark, if it exists, from a file and rewrites it in-place""" """Removes BOM mark, if it exists, from a file and rewrites it in-place"""
@ -501,6 +505,17 @@ def deletePrevious(mdl, fields):
mdl.objects.filter(location_id = int(fields[0])).delete(); mdl.objects.filter(location_id = int(fields[0])).delete();
@receiver(post_delete,sender=ShapeLayers)
def deleteShapelocation(sender,instance,*args,**kwargs):
locids = ShapeFileLocations.objects.filter(shapefile=instance.name).values_list('locid')
print("------- name----")
print(locids)
print("------- name----")
Location.objects.filter(location_id__in=locids).delete()
ShapeFileLocations.objects.filter(shapefile=instance.name).delete()
@receiver(post_save, sender=ShapeLayers) @receiver(post_save, sender=ShapeLayers)
def publish_data(sender, instance, created, **kwargs): def publish_data(sender, instance, created, **kwargs):
file = instance.file.path file = instance.file.path
@ -549,6 +564,7 @@ def publish_data(sender, instance, created, **kwargs):
print(fields[0]) print(fields[0])
print("@@@@@@@@@@@@") print("@@@@@@@@@@@@")
if instance.layerof == 1: if instance.layerof == 1:
insertShapeLayerLocation(instance.name, fields)
updateLocation(mdl, fields) updateLocation(mdl, fields)
if instance.layerof == 2: if instance.layerof == 2:
updateLineTable(mdl, fields) updateLineTable(mdl, fields)
@ -559,6 +575,12 @@ def publish_data(sender, instance, created, **kwargs):
print('##################',e) print('##################',e)
def insertShapeLayerLocation(name, fields):
sll = ShapeFileLocations(shapefile=name, locid=fields[0])
sll.save();
def updateLocation(mdl, fields): def updateLocation(mdl, fields):
print(f"Updating {fields[0]} - {fields[1]}") print(f"Updating {fields[0]} - {fields[1]}")
print(mdl.objects.filter(location_id = int(fields[0]))) print(mdl.objects.filter(location_id = int(fields[0])))