funzioni di base reimplementate

This commit is contained in:
baz 2020-03-03 18:35:27 +01:00
parent d9f7bcdafa
commit abb27af21a
13 changed files with 262 additions and 120 deletions

View file

@ -1,11 +1,11 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'rxmap.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "rxmap.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
@ -17,5 +17,5 @@ def main():
execute_from_command_line(sys.argv)
if __name__ == '__main__':
if __name__ == "__main__":
main()

View file

@ -20,7 +20,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'o4-qdex8sx_b3i!hu81qtri*-&pztgkolc^p()r0g3vauzk+^b'
SECRET_KEY = "o4-qdex8sx_b3i!hu81qtri*-&pztgkolc^p()r0g3vauzk+^b"
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
@ -31,53 +31,53 @@ ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rxmapp',
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"rxmapp",
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
ROOT_URLCONF = 'rxmap.urls'
ROOT_URLCONF = "rxmap.urls"
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
]
},
},
}
]
WSGI_APPLICATION = 'rxmap.wsgi.application'
WSGI_APPLICATION = "rxmap.wsgi.application"
# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
}
@ -85,29 +85,23 @@ DATABASES = {
# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
AUTH_USER_MODEL = 'rxmapp.User'
AUTH_USER_MODEL = "rxmapp.User"
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"
},
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
]
# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/
LANGUAGE_CODE = 'it-it'
LANGUAGE_CODE = "it-it"
TIME_ZONE = 'Europe/Rome'
TIME_ZONE = "Europe/Rome"
USE_I18N = True
@ -119,5 +113,5 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = 'static'
STATIC_URL = "/static/"
STATIC_ROOT = "static"

View file

@ -16,7 +16,4 @@ Including another URLconf
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('rxmapp.urls')),
]
urlpatterns = [path("admin/", admin.site.urls), path("", include("rxmapp.urls"))]

View file

@ -11,6 +11,6 @@ import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'rxmap.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "rxmap.settings")
application = get_wsgi_application()

View file

@ -1,3 +1,8 @@
from django.contrib import admin
from .models import TipoRadio, User, RapportoRicezione
# Register your models here.
admin.site.register(TipoRadio)
admin.site.register(User)
admin.site.register(RapportoRicezione)

View file

@ -2,4 +2,4 @@ from django.apps import AppConfig
class RxmappConfig(AppConfig):
name = 'rxmapp'
name = "rxmapp"

View file

@ -13,59 +13,171 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('auth', '0011_update_proxy_permissions'),
]
dependencies = [("auth", "0011_update_proxy_permissions")]
operations = [
migrations.CreateModel(
name='User',
name="User",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("password", models.CharField(max_length=128, verbose_name="password")),
(
"last_login",
models.DateTimeField(
blank=True, null=True, verbose_name="last login"
),
),
(
"is_superuser",
models.BooleanField(
default=False,
help_text="Designates that this user has all permissions without explicitly assigning them.",
verbose_name="superuser status",
),
),
(
"username",
models.CharField(
error_messages={
"unique": "A user with that username already exists."
},
help_text="Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.",
max_length=150,
unique=True,
validators=[
django.contrib.auth.validators.UnicodeUsernameValidator()
],
verbose_name="username",
),
),
(
"first_name",
models.CharField(
blank=True, max_length=30, verbose_name="first name"
),
),
(
"last_name",
models.CharField(
blank=True, max_length=150, verbose_name="last name"
),
),
(
"email",
models.EmailField(
blank=True, max_length=254, verbose_name="email address"
),
),
(
"is_staff",
models.BooleanField(
default=False,
help_text="Designates whether the user can log into this admin site.",
verbose_name="staff status",
),
),
(
"is_active",
models.BooleanField(
default=True,
help_text="Designates whether this user should be treated as active. Unselect this instead of deleting accounts.",
verbose_name="active",
),
),
(
"date_joined",
models.DateTimeField(
default=django.utils.timezone.now, verbose_name="date joined"
),
),
(
"groups",
models.ManyToManyField(
blank=True,
help_text="The groups this user belongs to. A user will get all permissions granted to each of their groups.",
related_name="user_set",
related_query_name="user",
to="auth.Group",
verbose_name="groups",
),
),
(
"user_permissions",
models.ManyToManyField(
blank=True,
help_text="Specific permissions for this user.",
related_name="user_set",
related_query_name="user",
to="auth.Permission",
verbose_name="user permissions",
),
),
],
options={
'verbose_name': 'user',
'verbose_name_plural': 'users',
'abstract': False,
"verbose_name": "user",
"verbose_name_plural": "users",
"abstract": False,
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
managers=[("objects", django.contrib.auth.models.UserManager())],
),
migrations.CreateModel(
name="TipoRadio",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("nome", models.CharField(max_length=64, unique=True)),
("descrizione", models.CharField(max_length=1000)),
],
),
migrations.CreateModel(
name='TipoRadio',
name="RapportoRicezione",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('nome', models.CharField(max_length=64, unique=True)),
('descrizione', models.CharField(max_length=1000)),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("date", models.DateField(default=datetime.datetime.now)),
("lat", models.FloatField()),
("lng", models.FloatField()),
("comprensibile", models.IntegerField()),
("stabilita", models.IntegerField()),
(
"author",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
related_name="rapporti",
to=settings.AUTH_USER_MODEL,
),
),
(
"tipo_radio",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
related_name="rapporti",
to="rxmapp.TipoRadio",
),
),
],
),
migrations.CreateModel(
name='RapportoRicezione',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date', models.DateField(default=datetime.datetime.now)),
('lat', models.FloatField()),
('lng', models.FloatField()),
('comprensibile', models.IntegerField()),
('stabilita', models.IntegerField()),
('author', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='rapporti', to=settings.AUTH_USER_MODEL)),
('tipo_radio', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='rapporti', to='rxmapp.TipoRadio')),
],
options={
'verbose_name': 'rapporto ricezione',
},
options={"verbose_name": "rapporto ricezione"},
),
]

View file

@ -8,21 +8,22 @@ class User(AbstractUser):
class TipoRadio(models.Model):
#tid = db.Column(db.Integer, primary_key=True, nullable=False)
# tid = db.Column(db.Integer, primary_key=True, nullable=False)
nome = models.CharField(max_length=64, unique=True)
descrizione = models.CharField(max_length=1000)
#rapporti = db.relationship("RapportoRicezione")
# rapporti = db.relationship("RapportoRicezione")
class RapportoRicezione(models.Model):
class Meta:
verbose_name = 'rapporto ricezione'
#verbose_plural_name = 'rapporti ricezione'
verbose_name = "rapporto ricezione"
# verbose_plural_name = 'rapporti ricezione'
#rid = db.Column(db.Integer, primary_key=True)
author = models.ForeignKey(User, related_name='rapporti', on_delete=models.PROTECT)
tipo_radio = models.ForeignKey(TipoRadio, on_delete=models.PROTECT, related_name='rapporti')
author = models.ForeignKey(User, related_name="rapporti", on_delete=models.PROTECT)
tipo_radio = models.ForeignKey(
TipoRadio, on_delete=models.PROTECT, related_name="rapporti"
)
date = models.DateField(default=datetime.now)
@ -64,5 +65,4 @@ class RapportoRicezione(models.Model):
)
def __str__(self):
return "<Rapporto %s del %s>" % (self.rid, self.date)
return "<Rapporto %s del %s>" % (self.pk, self.date)

View file

@ -34,6 +34,7 @@ function viewMap () {
lat: $('#pointform input[name=lat]').val(),
lng: $('#pointform input[name=lng]').val(),
stabilita: $('#pointform select[name=stabilita]').val(),
tiporadio:$('#pointform select[name=tiporadio]').val(),
comprensibile: $('#pointform select[name=comprensibile]').val()
})
$('#pointform').addClass('hidden')

View file

@ -25,7 +25,7 @@ function viewMap () {
function onMarkerClicked (evt) {
console.log('T', this)
var data = evt.target.options.originalData
var rid = data.rid
var rid = data.id
$('#dialog').html('<div class="explaination"></div><div class="actions"></div>')
$('#dialog .explaination').text(data.explaination)
$('#dialog .actions').html('<button class="btn-elimina">Elimina</button>')

View file

@ -1,6 +1,7 @@
{% extends 'base.html' %}
{% load static %}
{% block extra_scripts %}
<script src="{{url_for('static', filename='js/addmap.js')}}">
<script src="{% static 'js/addmap.js' %}">
</script>
{% endblock extra_scripts %}
@ -34,7 +35,7 @@
<label for="tiporadio">Osservazione fatta con</label>
<select name="tiporadio">
{% for tr in tipiradio %}
<option value="{{tr.tid}}"><strong>{{tr.nome}}</strong> - {{tr.descrizione|default('', true)}}</option>
<option value="{{tr.pk}}"><strong>{{tr.nome}}</strong> - {{tr.descrizione|default:''}}</option>
{% endfor %}
</select>
</div>

View file

@ -20,10 +20,9 @@ from django.views.generic import TemplateView
from . import views
urlpatterns = [
path('', TemplateView.as_view(template_name='index.html'), name="home"),
path('add', TemplateView.as_view(template_name='add.html'), name="add"),
path('api/rapporti/get', views.rapporti_get),
#path('api/rapporti/add', views.rapporti_add),
#path('api/rapporti/delete', views.rapporti_delete),
path("", TemplateView.as_view(template_name="index.html"), name="home"),
path("add", views.add_page, name="add"),
path("api/rapporti/get", views.rapporti_get),
path("api/rapporti/add", views.rapporto_add),
path("api/rapporti/delete", views.rapporto_delete),
]

View file

@ -1,12 +1,45 @@
from django.shortcuts import render
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from .models import RapportoRicezione
from .models import RapportoRicezione, User, TipoRadio
# Create your views here.
def add_page(request):
# TODO: replace with /api/tipiradio/get etc.
return render(
request,
template_name="add.html",
context=dict(tipiradio=TipoRadio.objects.all()),
)
def rapporti_get(request):
return JsonResponse([
r.serialize()
for r in RapportoRicezione.objects.all()
], safe=False)
return JsonResponse(
dict(rapporti=[r.serialize() for r in RapportoRicezione.objects.all()])
)
@csrf_exempt
def rapporto_add(request):
user = User.objects.filter(is_superuser=True).first()
r = RapportoRicezione(
author=user,
lat=request.POST["lat"],
lng=request.POST["lng"],
comprensibile=request.POST["comprensibile"],
stabilita=request.POST["comprensibile"],
tipo_radio=TipoRadio.objects.get(pk=request.POST["tiporadio"]),
)
r.save()
return JsonResponse(True, safe=False)
@csrf_exempt
def rapporto_delete(request):
RapportoRicezione.objects.get(pk=request.POST["rid"]).delete()
return JsonResponse(True, safe=False)