added tem table for location data
This commit is contained in:
117
rog/admin.py
117
rog/admin.py
@ -2,7 +2,7 @@ from django.contrib import admin
|
||||
from leaflet.admin import LeafletGeoAdmin
|
||||
from leaflet.admin import LeafletGeoAdminMixin
|
||||
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, ShapeFileLocations
|
||||
from .models import RogUser, Location, SystemSettings, JoinedEvent, Favorite, TravelList, TravelPoint, ShapeLayers, Event, Location_line, Location_polygon, JpnAdminMainPerf, JpnAdminPerf, JpnSubPerf, Useractions, CustomUser, GifuAreas, UserTracks, ShapeFileLocations, templocation
|
||||
from django.contrib.auth.admin import UserAdmin
|
||||
|
||||
class RogAdmin(LeafletAdminListMixin, LeafletGeoAdminMixin, admin.ModelAdmin):
|
||||
@ -32,10 +32,120 @@ class UserAdminConfig(UserAdmin):
|
||||
(None, {'classes':('wide',), 'fields':('email','password1', 'password2')}),
|
||||
)
|
||||
|
||||
admin.site.register(Useractions)
|
||||
class LocationAdmin(LeafletGeoAdmin):
|
||||
search_fields = ('location_id', 'cp', 'location_name', 'category', 'event_name',)
|
||||
list_filter = ('category', 'event_name',)
|
||||
ordering = ('location_id', 'cp',)
|
||||
list_display = ('location_id','cp', 'location_name', 'category', 'event_name', 'event_active', 'auto_checkin', 'checkin_radius', 'checkin_point', 'buy_point',)
|
||||
|
||||
|
||||
def tranfer_to_location(modeladmin, request, queryset):
|
||||
tmp_locs = templocation.objects.all();
|
||||
for l in tmp_locs :
|
||||
found = Location.objects.filter(location_id = l.location_id).exists()
|
||||
if found:
|
||||
Location.objects.filter(location_id = l.location_id).update(
|
||||
sub_loc_id = l.sub_loc_id,
|
||||
cp = l.cp,
|
||||
location_name = l.location_name,
|
||||
category = l.category,
|
||||
subcategory = l.subcategory,
|
||||
zip = l.zip,
|
||||
address = l.address,
|
||||
prefecture = l.prefecture,
|
||||
area = l.area,
|
||||
city = l.city,
|
||||
latitude = l.latitude,
|
||||
longitude = l.longitude,
|
||||
photos = l.photos,
|
||||
videos = l.videos,
|
||||
webcontents = l.webcontents,
|
||||
status = l.status,
|
||||
portal = l.portal,
|
||||
group = l.group,
|
||||
phone = l.phone,
|
||||
fax = l.fax,
|
||||
email = l.email,
|
||||
facility = l.facility,
|
||||
remark = l.remark,
|
||||
tags = l.tags,
|
||||
hidden_location = l.hidden_location,
|
||||
auto_checkin = l.auto_checkin,
|
||||
checkin_radius = l.checkin_radius,
|
||||
checkin_point = l.checkin_point,
|
||||
buy_point = l.buy_point,
|
||||
evaluation_value = l.evaluation_value,
|
||||
shop_closed = l.shop_closed,
|
||||
shop_shutdown = l.shop_shutdown,
|
||||
opening_hours_mon = l.opening_hours_mon,
|
||||
opening_hours_tue = l.opening_hours_tue,
|
||||
opening_hours_wed = l.opening_hours_wed,
|
||||
opening_hours_thu = l.opening_hours_thu,
|
||||
opening_hours_fri = l.opening_hours_fri,
|
||||
opening_hours_sat = l.opening_hours_sat,
|
||||
opening_hours_sun = l.opening_hours_sun,
|
||||
geom=l.geom
|
||||
)
|
||||
else:
|
||||
loc = Location(
|
||||
location_id=l.location_id,
|
||||
sub_loc_id = l.sub_loc_id,
|
||||
cp = l.cp,
|
||||
location_name = l.location_name,
|
||||
category = l.category,
|
||||
subcategory = l.subcategory,
|
||||
zip = l.zip,
|
||||
address = l.address,
|
||||
prefecture = l.prefecture,
|
||||
area = l.area,
|
||||
city = l.city,
|
||||
latitude = l.latitude,
|
||||
longitude = l.longitude,
|
||||
photos = l.photos,
|
||||
videos = l.videos,
|
||||
webcontents = l.webcontents,
|
||||
status = l.status,
|
||||
portal = l.portal,
|
||||
group = l.group,
|
||||
phone = l.phone,
|
||||
fax = l.fax,
|
||||
email = l.email,
|
||||
facility = l.facility,
|
||||
remark = l.remark,
|
||||
tags = l.tags,
|
||||
hidden_location = l.hidden_location,
|
||||
auto_checkin = l.auto_checkin,
|
||||
checkin_radius = l.checkin_radius,
|
||||
checkin_point = l.checkin_point,
|
||||
buy_point = l.buy_point,
|
||||
evaluation_value = l.evaluation_value,
|
||||
shop_closed = l.shop_closed,
|
||||
shop_shutdown = l.shop_shutdown,
|
||||
opening_hours_mon = l.opening_hours_mon,
|
||||
opening_hours_tue = l.opening_hours_tue,
|
||||
opening_hours_wed = l.opening_hours_wed,
|
||||
opening_hours_thu = l.opening_hours_thu,
|
||||
opening_hours_fri = l.opening_hours_fri,
|
||||
opening_hours_sat = l.opening_hours_sat,
|
||||
opening_hours_sun = l.opening_hours_sun,
|
||||
geom=l.geom
|
||||
)
|
||||
loc.save()
|
||||
tranfer_to_location.short_description = "Transfer all locations in temp table to location table"
|
||||
|
||||
|
||||
class TempLocationAdmin(LeafletGeoAdmin):
|
||||
search_fields = ('location_id', 'cp', 'location_name', 'category', 'event_name',)
|
||||
list_filter = ('category', 'event_name',)
|
||||
ordering = ('location_id', 'cp',)
|
||||
list_display = ('location_id','cp', 'location_name', 'category', 'event_name', 'event_active', 'auto_checkin', 'checkin_radius', 'checkin_point', 'buy_point',)
|
||||
actions = [tranfer_to_location,]
|
||||
|
||||
|
||||
|
||||
admin.site.register(Useractions)
|
||||
admin.site.register(RogUser, admin.ModelAdmin)
|
||||
admin.site.register(Location, LeafletGeoAdmin)
|
||||
admin.site.register(Location, LocationAdmin)
|
||||
admin.site.register(SystemSettings, admin.ModelAdmin)
|
||||
admin.site.register(JoinedEvent, admin.ModelAdmin)
|
||||
admin.site.register(Favorite, admin.ModelAdmin)
|
||||
@ -53,3 +163,4 @@ admin.site.register(ShapeLayers, admin.ModelAdmin)
|
||||
#admin.site.register(ShapeFileLocations, admin.ModelAdmin)
|
||||
|
||||
admin.site.register(CustomUser, UserAdminConfig)
|
||||
admin.site.register(templocation, TempLocationAdmin)
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
LAYER_CHOICES = (
|
||||
(1, _("location")),
|
||||
(1, _("templocation")),
|
||||
(2, _("Location_line")),
|
||||
(3, _("Location_polygon")),
|
||||
)
|
||||
@ -2,26 +2,6 @@ from django.contrib.gis.utils import LayerMapping
|
||||
|
||||
location_mapping = {
|
||||
'location_id' : 'loc_id',
|
||||
# 'location_name' : 'loc_name',
|
||||
# 'category': 'category',
|
||||
# 'zip':'zip',
|
||||
# 'address':'address',
|
||||
# 'prefecture':'prefecture',
|
||||
# 'area':'area',
|
||||
# 'city':'city',
|
||||
# 'photos':'photos',
|
||||
# 'videos':'videos',
|
||||
# 'webcontents':'webcontent',
|
||||
# 'status':'status',
|
||||
# 'portal':'portal',
|
||||
# 'group':'group',
|
||||
# 'phone':'phone',
|
||||
# 'fax':'fax',
|
||||
# 'email':'email',
|
||||
# 'facility':'facility',
|
||||
# 'remark':'remark',
|
||||
# 'parammeters':'params',
|
||||
# 'tags':'tags',
|
||||
'geom': 'POINT',
|
||||
}
|
||||
|
||||
|
||||
69
rog/migrations/0021_templocation.py
Normal file
69
rog/migrations/0021_templocation.py
Normal file
@ -0,0 +1,69 @@
|
||||
# Generated by Django 3.2.9 on 2022-08-17 05:48
|
||||
|
||||
from django.conf import settings
|
||||
import django.contrib.gis.db.models.fields
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('rog', '0020_auto_20220816_1627'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='templocation',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('location_id', models.IntegerField(blank=True, null=True, verbose_name='Location id')),
|
||||
('sub_loc_id', models.IntegerField(blank=True, null=True, verbose_name='Sub location id')),
|
||||
('cp', models.FloatField(blank=True, null=True, verbose_name='Check Point')),
|
||||
('location_name', models.CharField(default='--- 場所をお願いします --', max_length=2048, verbose_name='Location Name')),
|
||||
('category', models.CharField(blank=True, max_length=2048, null=True, verbose_name='Category')),
|
||||
('subcategory', models.CharField(blank=True, max_length=2048, null=True, verbose_name='Sub Category')),
|
||||
('zip', models.CharField(blank=True, max_length=12, null=True, verbose_name='Zip code')),
|
||||
('address', models.CharField(blank=True, max_length=2048, null=True, verbose_name='Address')),
|
||||
('prefecture', models.CharField(blank=True, max_length=2048, null=True, verbose_name='Prefecture')),
|
||||
('area', models.CharField(blank=True, max_length=2048, null=True, verbose_name='Area')),
|
||||
('city', models.CharField(blank=True, max_length=2048, null=True, verbose_name='City')),
|
||||
('latitude', models.FloatField(blank=True, null=True, verbose_name='Latitude')),
|
||||
('longitude', models.FloatField(blank=True, null=True, verbose_name='Latitude')),
|
||||
('photos', models.CharField(blank=True, max_length=2048, null=True, verbose_name='Photos')),
|
||||
('videos', models.CharField(blank=True, max_length=2048, null=True, verbose_name='Videos')),
|
||||
('webcontents', models.CharField(blank=True, max_length=2048, null=True, verbose_name='Web Content')),
|
||||
('status', models.CharField(blank=True, max_length=2048, null=True, verbose_name='Status')),
|
||||
('portal', models.CharField(blank=True, max_length=2048, null=True, verbose_name='Portal')),
|
||||
('group', models.CharField(blank=True, max_length=2048, null=True, verbose_name='Group')),
|
||||
('phone', models.CharField(blank=True, max_length=2048, null=True, verbose_name='Phone')),
|
||||
('fax', models.CharField(blank=True, max_length=2048, null=True, verbose_name='Fax')),
|
||||
('email', models.EmailField(blank=True, max_length=2048, null=True, verbose_name='Email')),
|
||||
('facility', models.CharField(blank=True, max_length=2048, null=True, verbose_name='Facility')),
|
||||
('remark', models.CharField(blank=True, max_length=2048, null=True, verbose_name='Remarks')),
|
||||
('tags', models.CharField(blank=True, max_length=2048, null=True, verbose_name='Tags')),
|
||||
('event_name', models.CharField(blank=True, max_length=2048, null=True, verbose_name='Event name')),
|
||||
('event_active', models.BooleanField(default=True, verbose_name='Is Event active')),
|
||||
('hidden_location', models.BooleanField(default=False, verbose_name='Is Hidden Location')),
|
||||
('auto_checkin', models.BooleanField(default=False, verbose_name='Is AutoCheckin')),
|
||||
('checkin_radius', models.FloatField(blank=True, default=15.0, null=True, verbose_name='Checkin radious')),
|
||||
('checkin_point', models.FloatField(blank=True, default=10, null=True, verbose_name='Checkin Point')),
|
||||
('buy_point', models.FloatField(blank=True, default=0, null=True, verbose_name='buy Point')),
|
||||
('evaluation_value', models.CharField(blank=True, max_length=2048, null=True, verbose_name='Evaluation value (評価)')),
|
||||
('shop_closed', models.BooleanField(default=False, verbose_name='Shop Closed (休業)')),
|
||||
('shop_shutdown', models.BooleanField(default=False, verbose_name='Shop Shutdown (閉業)')),
|
||||
('opening_hours_mon', models.CharField(blank=True, max_length=512, null=True, verbose_name='Opening hours monday (月曜)')),
|
||||
('opening_hours_tue', models.CharField(blank=True, max_length=512, null=True, verbose_name='Opening hours tuesday (火曜)')),
|
||||
('opening_hours_wed', models.CharField(blank=True, max_length=512, null=True, verbose_name='Opening hours wednesday (水曜)')),
|
||||
('opening_hours_thu', models.CharField(blank=True, max_length=512, null=True, verbose_name='Opening hours thursday (木曜)')),
|
||||
('opening_hours_fri', models.CharField(blank=True, max_length=512, null=True, verbose_name='Opening hours frinday (金曜)')),
|
||||
('opening_hours_sat', models.CharField(blank=True, max_length=512, null=True, verbose_name='Opening hours saturday (土曜)')),
|
||||
('opening_hours_sun', models.CharField(blank=True, max_length=512, null=True, verbose_name='Opening hours sunday (日曜)')),
|
||||
('parammeters', models.CharField(blank=True, max_length=2048, null=True, verbose_name='Parameters')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('last_updated_at', models.DateTimeField(auto_now=True)),
|
||||
('geom', django.contrib.gis.db.models.fields.MultiPointField(srid=4326)),
|
||||
('last_updated_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='temp_location_updated_user', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
||||
@ -235,6 +235,58 @@ class Location(models.Model):
|
||||
return self.location_name
|
||||
|
||||
|
||||
class templocation(models.Model):
|
||||
location_id=models.IntegerField(_('Location id'), blank=True, null=True)
|
||||
sub_loc_id=models.IntegerField(_('Sub location id'), blank=True, null=True)
|
||||
cp=models.FloatField(_('Check Point'), blank=True, null=True)
|
||||
location_name=models.CharField(_('Location Name'), max_length=2048, default="--- 場所をお願いします --")
|
||||
category=models.CharField(_('Category'), max_length=2048, blank=True, null=True)
|
||||
subcategory=models.CharField(_('Sub Category'), max_length=2048, blank=True, null=True)
|
||||
zip=models.CharField(_('Zip code'), max_length=12, blank=True, null=True)
|
||||
address = models.CharField(_('Address'), max_length=2048, blank=True, null=True)
|
||||
prefecture = models.CharField(_('Prefecture'), max_length=2048, blank=True, null=True)
|
||||
area= models.CharField(_('Area'), max_length=2048, blank=True, null=True)
|
||||
city= models.CharField(_('City'), max_length=2048, blank=True, null=True)
|
||||
latitude = models.FloatField('Latitude', blank=True, null=True)
|
||||
longitude = models.FloatField('Latitude', blank=True, null=True)
|
||||
photos=models.CharField(_('Photos'), max_length=2048, blank=True, null=True)
|
||||
videos=models.CharField(_('Videos'), max_length=2048, blank=True, null=True)
|
||||
webcontents=models.CharField(_('Web Content'), max_length=2048, blank=True, null=True)
|
||||
status=models.CharField(_('Status'),max_length=2048, blank=True, null=True)
|
||||
portal=models.CharField(_('Portal'), max_length=2048,blank=True, null=True)
|
||||
group=models.CharField(_('Group'), max_length=2048,blank=True, null=True)
|
||||
phone=models.CharField(_('Phone'), max_length=2048,blank=True, null=True)
|
||||
fax=models.CharField(_('Fax'), max_length=2048, blank=True, null=True)
|
||||
email=models.EmailField(_('Email'), max_length=2048,blank=True, null=True)
|
||||
facility=models.CharField(_('Facility'), max_length=2048, blank=True, null=True)
|
||||
remark=models.CharField(_('Remarks'), max_length=2048, blank=True, null=True)
|
||||
tags=models.CharField(_('Tags'), max_length=2048, blank=True, null=True)
|
||||
event_name = models.CharField(_('Event name'), max_length=2048, blank=True, null=True)
|
||||
event_active = models.BooleanField(_("Is Event active"),default=True)
|
||||
hidden_location = models.BooleanField(_("Is Hidden Location"),default=False)
|
||||
auto_checkin = models.BooleanField(_("Is AutoCheckin"),default=False)
|
||||
checkin_radius = models.FloatField(_("Checkin radious"), blank=True, null=True, default=15.0)
|
||||
checkin_point = models.FloatField(_("Checkin Point"), blank=True, null=True, default=10)
|
||||
buy_point = models.FloatField(_("buy Point"), blank=True, null=True, default=0)
|
||||
evaluation_value = models.CharField(_('Evaluation value (評価)'),max_length=2048, blank=True, null=True)
|
||||
shop_closed = models.BooleanField(_("Shop Closed (休業)"),default=False)
|
||||
shop_shutdown = models.BooleanField(_("Shop Shutdown (閉業)"),default=False)
|
||||
opening_hours_mon = models.CharField(_("Opening hours monday (月曜)"),max_length=512, blank=True, null=True)
|
||||
opening_hours_tue = models.CharField(_("Opening hours tuesday (火曜)"), max_length=512,blank=True, null=True)
|
||||
opening_hours_wed = models.CharField(_("Opening hours wednesday (水曜)"), max_length=512,blank=True, null=True)
|
||||
opening_hours_thu = models.CharField(_("Opening hours thursday (木曜)"), max_length=512, blank=True, null=True)
|
||||
opening_hours_fri = models.CharField(_("Opening hours frinday (金曜)"), max_length=512,blank=True, null=True)
|
||||
opening_hours_sat = models.CharField(_("Opening hours saturday (土曜)"), max_length=512,blank=True, null=True)
|
||||
opening_hours_sun = models.CharField(_("Opening hours sunday (日曜)"),max_length=512, blank=True, null=True)
|
||||
parammeters=models.CharField(_('Parameters'), max_length=2048, blank=True, null=True)
|
||||
created_at=models.DateTimeField(auto_now_add=True)
|
||||
last_updated_user=models.ForeignKey(CustomUser, related_name="temp_location_updated_user", on_delete=models.DO_NOTHING,blank=True, null=True)
|
||||
last_updated_at=models.DateTimeField(auto_now=True)
|
||||
geom=models.MultiPointField(srid=4326)
|
||||
|
||||
def __str__(self):
|
||||
return self.location_name
|
||||
|
||||
class Location_line(models.Model):
|
||||
location_id=models.IntegerField(_('Location id'), blank=True, null=True)
|
||||
location_name=models.CharField(_('Location Name'), max_length=255)
|
||||
@ -428,15 +480,15 @@ class TestModel(models.Model):
|
||||
|
||||
def getTableForModel(tbl):
|
||||
if tbl == 1:
|
||||
return Location.objects.model._meta.db_table;
|
||||
return templocation.objects.model._meta.db_table;
|
||||
elif tbl == 2:
|
||||
return Location_line.objects.model._meta.db_table;
|
||||
else:
|
||||
return Location_polygon.objects.model._meta.db_table;
|
||||
|
||||
def getMappingforModel(tbl, shp):
|
||||
def getTempMappingforModel(tbl, shp):
|
||||
if tbl == 1:
|
||||
return LayerMapping(Location, shp, location_mapping, transform=False)
|
||||
return LayerMapping(templocation, shp, location_mapping, transform=False)
|
||||
elif tbl == 2:
|
||||
return LayerMapping(Location_line, shp, location_line_mapping, transform=False)
|
||||
else:
|
||||
@ -488,7 +540,7 @@ def remove_bom_inplace(path):
|
||||
@receiver(pre_save, sender=Location)
|
||||
def location_presave(sender, instance, *args, **kwargs):
|
||||
#print("------############------------", instance.location_id)
|
||||
Location.objects.filter(location_id = instance.location_id).delete()
|
||||
templocation.objects.filter(location_id = instance.location_id).delete()
|
||||
|
||||
|
||||
@receiver(pre_save, sender=Location_line)
|
||||
@ -518,7 +570,7 @@ def deleteShapelocation(sender,instance,*args,**kwargs):
|
||||
print("------- name----")
|
||||
print(locids)
|
||||
print("------- name----")
|
||||
Location.objects.filter(location_id__in=locids).delete()
|
||||
templocation.objects.all().delete()
|
||||
ShapeFileLocations.objects.filter(shapefile=instance.name).delete()
|
||||
|
||||
|
||||
@ -548,7 +600,7 @@ def publish_data(sender, instance, created, **kwargs):
|
||||
if epsg is None:
|
||||
epsg=4326
|
||||
|
||||
lm2 = getMappingforModel(instance.layerof, shp)
|
||||
lm2 = getTempMappingforModel(instance.layerof, shp)
|
||||
print("### shape file is ###")
|
||||
lm2.save(strict=True, verbose=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user