added use load from external
This commit is contained in:
53
rog/admin.py
53
rog/admin.py
@ -1,9 +1,15 @@
|
||||
import email
|
||||
from django.contrib import admin
|
||||
from django.shortcuts import render
|
||||
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, templocation, UserUpload, UserUploadUser, EventUser
|
||||
from django.contrib.auth.admin import UserAdmin
|
||||
from django.urls import path
|
||||
from django.shortcuts import render
|
||||
from django import forms;
|
||||
import requests
|
||||
|
||||
class RogAdmin(LeafletAdminListMixin, LeafletGeoAdminMixin, admin.ModelAdmin):
|
||||
list_display=['title', 'venue', 'at_date',]
|
||||
@ -17,19 +23,58 @@ class EventRouteAdmin(LeafletAdminListMixin, LeafletGeoAdminMixin, admin.ModelAd
|
||||
class ShopRouteAdmin(LeafletAdminListMixin, LeafletGeoAdminMixin, admin.ModelAdmin):
|
||||
list_display=['name',]
|
||||
|
||||
class loadUserForm(forms.Form):
|
||||
server_url = forms.CharField(label="Load Data from *" ,initial='https://natnats.mobilous.com/get_team_list', widget=forms.Textarea(attrs={"rows":2, "cols":95}))
|
||||
|
||||
|
||||
class UserAdminConfig(UserAdmin):
|
||||
search_fields = ('email', 'group', 'is_rogaining')
|
||||
search_fields = ('email', 'group', 'zekken_number', 'event_code', 'team_name', 'is_rogaining')
|
||||
list_filter = ('email', 'group', 'is_rogaining')
|
||||
ordering = ('email',)
|
||||
list_display = ('email', 'group', 'is_active', 'is_staff', 'is_rogaining')
|
||||
list_display = ('email', 'group','zekken_number', 'event_code', 'team_name', 'is_active', 'is_staff', 'is_rogaining')
|
||||
|
||||
def get_urls(self):
|
||||
urls = super().get_urls()
|
||||
new_url = [path('load-users/', self.loadUsers),]
|
||||
return new_url + urls
|
||||
|
||||
def loadUsers(self, request):
|
||||
|
||||
if request.method == "POST":
|
||||
frm = loadUserForm(request.POST)
|
||||
if frm.is_valid():
|
||||
print(frm.cleaned_data['server_url'])
|
||||
#load json from server
|
||||
url = frm.cleaned_data['server_url']
|
||||
response = requests.get(url)
|
||||
data = response.json()
|
||||
print("-------Event code--------")
|
||||
print(data)
|
||||
print("-------Event code--------")
|
||||
for i in data:
|
||||
_exist = CustomUser.objects.filter(email=i["zekken_number"]).delete()
|
||||
usr = CustomUser.objects.create_user(
|
||||
email=i["zekken_number"],
|
||||
zekken_number=i['zekken_number'],
|
||||
is_rogaining=True,
|
||||
event_code=i['event_code'],
|
||||
team_name=i['team_name'],
|
||||
group='大垣-初心者',
|
||||
password=i['password'],
|
||||
is_staff= True
|
||||
)
|
||||
|
||||
form = loadUserForm()
|
||||
data = {'form': form}
|
||||
return render(request, 'admin/load_users.html', data)
|
||||
|
||||
fieldsets = (
|
||||
(None, {'fields':('email', 'group')}),
|
||||
(None, {'fields':('email', 'group', 'zekken_number', 'event_code', 'team_name',)}),
|
||||
('Permissions', {'fields':('is_staff', 'is_active', 'is_rogaining')}),
|
||||
)
|
||||
|
||||
add_fieldsets = (
|
||||
(None, {'classes':('wide',), 'fields':('email', 'group', 'password1', 'password2')}),
|
||||
(None, {'classes':('wide',), 'fields':('email', 'group','zekken_number', 'event_code', 'team_name', 'password1', 'password2')}),
|
||||
)
|
||||
|
||||
class JpnSubPerfAdmin(LeafletGeoAdmin):
|
||||
|
||||
Reference in New Issue
Block a user