-
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.
use django_db_views, move models from folder unmanaged to dbview, sql…
…ite view statements, enable some migrations for tests
- Loading branch information
Showing
17 changed files
with
159 additions
and
65 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
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
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
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...rts/migrations/0010_auto_20240619_0559.py → ...rts/migrations/0009_auto_20240812_1918.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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
# Generated by Django 4.2.11 on 2024-06-19 02:59 | ||
# Generated by Django 5.0.7 on 2024-08-12 16:18 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("edc_qareports", "0009_auto_20240619_0546"), | ||
("edc_qareports", "0008_qareportlogsummary"), | ||
] | ||
|
||
operations = [] |
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 @@ | ||
# Generated by Django 5.0.7 on 2024-08-12 16:18 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("edc_qareports", "0009_auto_20240812_1918"), | ||
] | ||
|
||
operations = [] |
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,48 @@ | ||
# Generated by Django 5.0.7 on 2024-08-12 23:19 | ||
|
||
import django_db_views.migration_functions | ||
import django_db_views.operations | ||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("edc_qareports", "0010_auto_20240812_1918"), | ||
] | ||
|
||
operations = [ | ||
django_db_views.operations.ViewRunPython( | ||
code=django_db_views.migration_functions.ForwardViewMigration( | ||
"select *, uuid() as `id`, now() as `created` from (\n select site_id, username, report_model, min(accessed) as `first_accessed`,\n max(accessed) as `last_accessed`, count(*) as `access_count`\n from edc_qareports_qareportlog\n group by username, report_model, site_id\n ) as A\n order by username, report_model", | ||
"qa_report_log_summary_view", | ||
engine="django.db.backends.mysql", | ||
), | ||
reverse_code=django_db_views.migration_functions.BackwardViewMigration( | ||
"", "qa_report_log_summary_view", engine="django.db.backends.mysql" | ||
), | ||
atomic=False, | ||
), | ||
django_db_views.operations.ViewRunPython( | ||
code=django_db_views.migration_functions.ForwardViewMigration( | ||
"select *, get_random_uuid() as id, now() as created (\n select site_id, username, report_model, min(accessed) as first_accessed,\n max(accessed) as last_accessed, count(*) as access_count\n from edc_qareports_qareportlog\n group by username, report_model, site_id\n ) as A\n order by username, report_model", | ||
"qa_report_log_summary_view", | ||
engine="django.db.backends.postgresql", | ||
), | ||
reverse_code=django_db_views.migration_functions.BackwardViewMigration( | ||
"", "qa_report_log_summary_view", engine="django.db.backends.postgresql" | ||
), | ||
atomic=False, | ||
), | ||
django_db_views.operations.ViewRunPython( | ||
code=django_db_views.migration_functions.ForwardViewMigration( | ||
"SELECT *, lower(\n hex(randomblob(4)) || '-' || hex(randomblob(2)) || '-' || '4' ||\n substr(hex( randomblob(2)), 2) || '-' ||\n substr('AB89', 1 + (abs(random()) % 4) , 1) ||\n substr(hex(randomblob(2)), 2) || '-' ||\n hex(randomblob(6))\n ) as id, datetime() as created from (\n select site_id, username, report_model, min(accessed) as first_accessed,\n max(accessed) as last_accessed, count(*) as access_count\n from edc_qareports_qareportlog\n group by username, report_model, site_id\n ) as A\n order by username, report_model", | ||
"qa_report_log_summary_view", | ||
engine="django.db.backends.sqlite3", | ||
), | ||
reverse_code=django_db_views.migration_functions.BackwardViewMigration( | ||
"", "qa_report_log_summary_view", engine="django.db.backends.sqlite3" | ||
), | ||
atomic=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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from .dbviews import QaReportLogSummary | ||
from .edc_permissions import EdcPermissions | ||
from .qa_report_model_mixin import QaReportModelMixin | ||
from .qa_report_note import QaReportNote | ||
from .qa_reports_log import QaReportLog | ||
from .unmanaged import QaReportLogSummary |
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 @@ | ||
from .unmanaged_model import QaReportLogSummary |
9 changes: 8 additions & 1 deletion
9
...models/unmanaged/qa_report_log_summary.py → ...reports/models/dbviews/unmanaged_model.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 |
---|---|---|
@@ -1,17 +1,24 @@ | ||
from django.contrib.sites.models import Site | ||
from django.db import models | ||
from django_db_views.db_view import DBView | ||
|
||
from ..qa_report_model_mixin import qa_reports_permissions | ||
from .view_definition import get_view_definition | ||
|
||
class QaReportLogSummary(models.Model): | ||
|
||
class QaReportLogSummary(DBView): | ||
username = models.CharField(max_length=100) | ||
site = models.ForeignKey(Site, on_delete=models.CASCADE) | ||
report_model = models.CharField(max_length=100) | ||
first_accessed = models.DateTimeField() | ||
last_accessed = models.DateTimeField() | ||
access_count = models.IntegerField() | ||
|
||
view_definition = get_view_definition() | ||
|
||
class Meta: | ||
managed = False | ||
db_table = "qa_report_log_summary_view" | ||
verbose_name = "QA Report Log Summary" | ||
verbose_name_plural = "QA Report Log Summary" | ||
default_permissions = qa_reports_permissions |
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,43 @@ | ||
mysql_view: str = """ | ||
select *, uuid() as `id`, now() as `created` from ( | ||
select site_id, username, report_model, min(accessed) as `first_accessed`, | ||
max(accessed) as `last_accessed`, count(*) as `access_count` | ||
from edc_qareports_qareportlog | ||
group by username, report_model, site_id | ||
) as A | ||
order by username, report_model | ||
""" | ||
|
||
pg_view: str = """ | ||
select *, get_random_uuid() as id, now() as created ( | ||
select site_id, username, report_model, min(accessed) as first_accessed, | ||
max(accessed) as last_accessed, count(*) as access_count | ||
from edc_qareports_qareportlog | ||
group by username, report_model, site_id | ||
) as A | ||
order by username, report_model | ||
""" | ||
|
||
sqlite3_view = """ | ||
SELECT *, lower( | ||
hex(randomblob(4)) || '-' || hex(randomblob(2)) || '-' || '4' || | ||
substr(hex( randomblob(2)), 2) || '-' || | ||
substr('AB89', 1 + (abs(random()) % 4) , 1) || | ||
substr(hex(randomblob(2)), 2) || '-' || | ||
hex(randomblob(6)) | ||
) as id, datetime() as created from ( | ||
select site_id, username, report_model, min(accessed) as first_accessed, | ||
max(accessed) as last_accessed, count(*) as access_count | ||
from edc_qareports_qareportlog | ||
group by username, report_model, site_id | ||
) as A | ||
order by username, report_model | ||
""" | ||
|
||
|
||
def get_view_definition() -> dict: | ||
return { | ||
"django.db.backends.mysql": mysql_view, | ||
"django.db.backends.postgresql": pg_view, | ||
"django.db.backends.sqlite3": sqlite3_view, | ||
} |
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,9 +1,9 @@ | ||
from edc_navbar import NavbarItem | ||
|
||
qa_navbar_item = NavbarItem( | ||
name="qa_reports_home", | ||
title="QA Reports", | ||
label="QA", | ||
codename="edc_qareports.nav_qareports_section", | ||
url_name="meta_reports_admin:index", | ||
) | ||
# from edc_navbar import NavbarItem | ||
# | ||
# qa_navbar_item = NavbarItem( | ||
# name="qa_reports_home", | ||
# title="QA Reports", | ||
# label="QA", | ||
# codename="edc_qareports.nav_qareports_section", | ||
# url_name="meta_reports_admin:index", | ||
# ) |
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
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