forked from code4romania/seismic-risc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue code4romania#13, Issue code4romania#14
Switch map to run from APIs Add sidebar with building information Add map locations filtering based on seismic risk Additional changes: - Fix an_construire
- Loading branch information
Showing
24 changed files
with
399 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,5 +103,12 @@ venv.bak/ | |
# mypy | ||
.mypy_cache/ | ||
|
||
#Pycharm | ||
.idea | ||
# IDEs | ||
.idea | ||
.vscode | ||
|
||
|
||
*.xlsx | ||
*.csv | ||
# files | ||
seismic_site/media/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from django.contrib import admin | ||
|
||
from .models import Page, Category, Attachment | ||
|
||
|
||
@admin.register(Category) | ||
class CategoryAdmin(admin.ModelAdmin): | ||
list_display = ('name',) | ||
|
||
|
||
class DocumentInline(admin.TabularInline): | ||
model = Attachment | ||
|
||
|
||
@admin.register(Page) | ||
class PageAdmin(admin.ModelAdmin): | ||
list_display = ('title', 'category', 'updated_on', 'is_published') | ||
list_filter = ('is_published',) | ||
# prepopulated_fields = {"slug": ("title",)} | ||
inlines = [ | ||
DocumentInline, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class CmsConfig(AppConfig): | ||
name = 'cms' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Generated by Django 2.2.4 on 2019-09-28 12:30 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Category', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=150, unique=True)), | ||
], | ||
options={ | ||
'verbose_name_plural': 'categories', | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Page', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.CharField(blank=True, help_text='Page title', max_length=150)), | ||
('slug', | ||
models.SlugField(blank=True, help_text='Unique URL slug (leave empty to auto-generate)', unique=True)), | ||
('content', models.TextField(blank=True, help_text='Page content')), | ||
('updated_on', models.DateTimeField(auto_now=True, help_text='Last update time', null=True)), | ||
('publishing_date', | ||
models.DateTimeField(blank=True, help_text='Public page publishing date', null=True)), | ||
('is_published', | ||
models.BooleanField(db_index=True, default=False, help_text='Is this page visible on the website')), | ||
('category', models.ForeignKey(blank=True, help_text='Page category', null=True, | ||
on_delete=django.db.models.deletion.SET_NULL, to='cms.Category')), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Generated by Django 2.2.4 on 2019-09-28 14:07 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('cms', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Attachment', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(help_text='Attachment name', max_length=150)), | ||
('upload_date', models.DateTimeField(auto_now=True, help_text='Attachment upload date')), | ||
('uploaded_file', models.FileField(upload_to='uploads/%Y/%m/%d/')), | ||
('page', | ||
models.ForeignKey(blank=True, help_text='Page attachment', on_delete=django.db.models.deletion.CASCADE, | ||
to='cms.Page')), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 2.2.4 on 2019-09-28 14:54 | ||
|
||
import ckeditor.fields | ||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('cms', '0002_attachment'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='page', | ||
name='content', | ||
field=ckeditor.fields.RichTextField(), | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from ckeditor.fields import RichTextField | ||
from django.db import models | ||
from django.utils import timezone | ||
from django.utils.text import slugify | ||
|
||
|
||
class Category(models.Model): | ||
name = models.CharField( | ||
blank=False, null=False, max_length=150, unique=True) | ||
|
||
def __str__(self): | ||
return "{}".format(self.name) | ||
|
||
class Meta: | ||
verbose_name_plural = "categories" | ||
|
||
|
||
class Page(models.Model): | ||
category = models.ForeignKey( | ||
Category, blank=True, null=True, on_delete=models.SET_NULL, | ||
help_text="Page category") | ||
title = models.CharField( | ||
blank=True, max_length=150, | ||
help_text="Page title") | ||
slug = models.SlugField( | ||
unique=True, blank=True, null=False, | ||
help_text="Unique URL slug (leave empty to auto-generate)") | ||
content = RichTextField() | ||
updated_on = models.DateTimeField( | ||
auto_now=timezone.now, | ||
blank=True, null=True, editable=False, | ||
help_text="Last update time") | ||
publishing_date = models.DateTimeField( | ||
blank=True, null=True, | ||
help_text="Public page publishing date") | ||
is_published = models.BooleanField( | ||
default=False, db_index=True, | ||
help_text="Is this page visible on the website") | ||
|
||
def __str__(self): | ||
return "{}".format(self.title) | ||
|
||
def save(self, *args, **kwargs): | ||
if not self.slug: | ||
self.slug = slugify(self.title) | ||
is_unique = False | ||
suffix = 0 | ||
while not is_unique: | ||
try: | ||
existing_page = Page.objects.get(slug=self.slug) | ||
except Page.DoesNotExist: | ||
is_unique = True | ||
else: | ||
if existing_page.id == self.id: | ||
is_unique = True | ||
else: | ||
suffix += 1 | ||
self.slug = slugify("{} {}".format(self.title, suffix)) | ||
|
||
super().save(*args, **kwargs) | ||
|
||
|
||
class Attachment(models.Model): | ||
page = models.ForeignKey( | ||
Page, blank=True, null=False, on_delete=models.CASCADE, | ||
help_text="Page attachment") | ||
name = models.CharField( | ||
max_length=150, | ||
help_text="Attachment name") | ||
upload_date = models.DateTimeField( | ||
auto_now=timezone.now, | ||
help_text="Attachment upload date") | ||
uploaded_file = models.FileField( | ||
upload_to='uploads/%Y/%m/%d/', max_length=100) | ||
|
||
def __str__(self): | ||
return "{}{}".format( | ||
self.uploaded_file.url, | ||
self.name) | ||
|
||
# class InlineResource(models.Model): | ||
# pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<html> | ||
<head> | ||
<title>{{ page.title }}</title> | ||
</head> | ||
<body> | ||
|
||
<div> | ||
{{ page.content|safe }} | ||
</div> | ||
|
||
<ul> | ||
{% for document in page.attachment_set.all %} | ||
<li>{{ document.uploaded_file.url }}</li> | ||
{% endfor %} | ||
</ul> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.urls import path | ||
|
||
from . import views | ||
|
||
urlpatterns = [ | ||
path('<slug:slug>/', views.view_page, name='view_page') | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.shortcuts import render, get_object_or_404 | ||
|
||
from .models import Page | ||
|
||
|
||
def view_page(request, slug): | ||
page = get_object_or_404(Page, slug=slug, is_published=True) | ||
return render( | ||
request, | ||
'cms/view_page.html', { | ||
'page': page | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,39 @@ | ||
from django.contrib import admin | ||
from .models import CsvFile, Building, CSVFileAdmin | ||
import tablib | ||
from django.contrib import admin, messages | ||
|
||
# Register your models here. | ||
admin.site.register(CsvFile, CSVFileAdmin) | ||
admin.site.register(Building) # ld-l | ||
from . import models | ||
|
||
|
||
@admin.register(models.Building) | ||
class BuildingAdmin(admin.ModelAdmin): | ||
list_filter = ['status', 'clasa_categorie', 'nr_postal'] | ||
list_display = ['adresa', 'clasa_categorie', 'an_expertiza', 'expert_atestat', 'status'] | ||
search_fields = ['adresa'] | ||
|
||
|
||
@admin.register(models.CsvFile) | ||
class CSVFileAdmin(admin.ModelAdmin): | ||
actions = ['import_files'] | ||
list_display = ['name', 'status'] | ||
|
||
def import_files(self, request, query_set): | ||
for q in query_set: | ||
data = tablib.import_set(open(q.file.file.name, 'rb').read()) | ||
changed_headers = [] | ||
for header in data.headers: | ||
changed_headers.append(header.lower().replace(':', '').replace('.', '').strip().replace(' ', '_')) | ||
data.headers = changed_headers | ||
building_res = models.BuildingResource() | ||
res = building_res.import_data(data, False, False) | ||
csv_file = models.CsvFile.objects.get(name=q.__str__()) | ||
if res.has_errors() or res.has_validation_errors(): | ||
csv_file.status = models.CsvFile.UNSUCCESS | ||
else: | ||
csv_file.status = models.CsvFile.SUCCESS | ||
self.message_user(request, "File with name {} {} imported.".format(q.__str__(), | ||
"was" if csv_file.status == models.CsvFile.SUCCESS | ||
else "wasn't"), | ||
messages.WARNING if csv_file.status == models.CsvFile.UNSUCCESS else messages.SUCCESS) | ||
csv_file.save() | ||
|
||
import_files.short_description = "Import selected files" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from crispy_forms.helper import FormHelper | ||
from django import forms | ||
|
||
from . import models | ||
|
||
|
||
class BuildingForm(forms.ModelForm): | ||
class Meta: | ||
model = models.Building | ||
exclude = ['id_general', 'status', 'actualizare_pmb', 'editare_admin', 'lat', 'long'] | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(BuildingForm, self).__init__(*args, **kwargs) | ||
self.helper = FormHelper() | ||
self.helper.form_tag = False | ||
self.helper.error_text_inline = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 2.2.4 on 2019-09-28 13:55 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('map_app', '0009_auto_20190928_1214'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='building', | ||
name='status', | ||
field=models.SmallIntegerField(choices=[(0, 'Alege'), (1, 'Acceptă'), (-1, 'Respinge')], default=0), | ||
), | ||
] |
13 changes: 13 additions & 0 deletions
13
seismic_site/map_app/migrations/0011_merge_20191002_2225.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Generated by Django 2.2.4 on 2019-10-02 22:25 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('map_app', '0010_building_status'), | ||
('map_app', '0010_building_an_construire'), | ||
] | ||
|
||
operations = [ | ||
] |
Oops, something went wrong.