Skip to content

Commit

Permalink
remove all link to datasource chart builder component
Browse files Browse the repository at this point in the history
  • Loading branch information
Teccolat committed Oct 31, 2024
1 parent 27623de commit ab634a6
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 196 deletions.
3 changes: 1 addition & 2 deletions dataworkspace/dataworkspace/apps/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
)


class DeletableTimeStampedUserTabularInline(admin.TabularInline):
exclude = ["created_date", "updated_date", "created_by", "updated_by", "deleted"]



class TimeStampedUserAdmin(admin.ModelAdmin):
Expand Down
36 changes: 1 addition & 35 deletions dataworkspace/dataworkspace/apps/datasets/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@
from dataworkspace.apps.applications.utils import get_data_source_id
from dataworkspace.apps.core.admin import (
DeletableTimeStampedUserAdmin,
DeletableTimeStampedUserTabularInline,
CSPRichTextEditorMixin,
)
from dataworkspace.apps.datasets.constants import TagType
from dataworkspace.apps.datasets.models import (
CustomDatasetQuery,
DataCutDataset,
DataSetVisualisation,
DatasetReferenceCode,
MasterDataset,
Pipeline,
Expand All @@ -58,7 +56,6 @@
from dataworkspace.apps.dw_admin.forms import (
CustomDatasetQueryForm,
DataCutDatasetForm,
DataSetVisualisationForm,
MasterDatasetForm,
ReferenceDataFieldInlineForm,
ReferenceDataInlineFormset,
Expand Down Expand Up @@ -145,17 +142,6 @@ class SourceTableInline(admin.TabularInline, SourceReferenceInlineMixin):
extra = 1
manage_unpublished_permission_codename = "datasets.manage_unpublished_master_datasets"


class DataSetVisualisationInline(DeletableTimeStampedUserTabularInline):
model = DataSetVisualisation
form = DataSetVisualisationForm
extra = 1
manage_unpublished_permission_codename = "datasets.manage_unpublished_master_datasets"

def get_queryset(self, request):
return super().get_queryset(request).filter(deleted=False)


class SourceViewInline(admin.TabularInline, SourceReferenceInlineMixin):
model = SourceView
extra = 1
Expand Down Expand Up @@ -381,28 +367,8 @@ def save_model(self, request, obj, form, change):
@admin.register(MasterDataset)
class MasterDatasetAdmin(CSPRichTextEditorMixin, BaseDatasetAdmin):
form = MasterDatasetForm
inlines = [SourceTableInline, DataSetVisualisationInline]
inlines = [SourceTableInline]
manage_unpublished_permission_codename = "datasets.manage_unpublished_master_datasets"

def save_formset(self, request, form, formset, change):
if formset.model != DataSetVisualisation:
super().save_formset(request, form, formset, change)
else:
instances = formset.save(commit=False)
# Save any changes
for instance in instances:
if not instance.pk:
instance.created_by = request.user
instance.updated_by = request.user
instance.save()
# Soft delete any deletions
for instance in formset.deleted_objects:
instance.deleted = True
instance.save()

formset.save_m2m()


@admin.register(DataCutDataset)
class DataCutDatasetAdmin(CSPRichTextEditorMixin, BaseDatasetAdmin):
form = DataCutDatasetForm
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 4.2.16 on 2024-10-31 10:49

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("datasets", "0177_alter_dataset_esda"),
]

operations = [
migrations.DeleteModel(
name="DataSetVisualisation",
),
]
13 changes: 0 additions & 13 deletions dataworkspace/dataworkspace/apps/datasets/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,19 +575,6 @@ def data_is_actively_updated(self):
or self.sourcelink_set.exclude(frequency="No longer updated").count() > 0
)


class DataSetVisualisation(DeletableTimestampedUserModel):
name = models.CharField(max_length=255)
summary = models.TextField()
vega_definition_json = models.TextField()
database = models.ForeignKey(Database, default=None, on_delete=models.CASCADE)
query = models.TextField(null=True, blank=True)

dataset = models.ForeignKey(DataSet, on_delete=models.CASCADE, related_name="visualisations")

gds_phase_name = models.CharField(max_length=25, default="", blank=True)


class DataSetUserPermission(models.Model):
user = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
dataset = models.ForeignKey(DataSet, on_delete=models.CASCADE)
Expand Down
28 changes: 0 additions & 28 deletions dataworkspace/dataworkspace/apps/datasets/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from dataworkspace.apps.datasets.models import (
ReferenceDataset,
DataSet,
DataSetVisualisation,
VisualisationCatalogueItem,
ToolQueryAuditLog,
)
Expand Down Expand Up @@ -192,8 +191,6 @@ def _get_datasets_data_for_user_matching_query(
datasets = _annotate_data_type(datasets)
datasets = _annotate_is_open_data(datasets)

datasets = _annotate_has_visuals(datasets)

datasets = _annotate_combined_published_date(datasets)

datasets = _annotate_is_owner(datasets, user)
Expand All @@ -218,7 +215,6 @@ def _get_datasets_data_for_user_matching_query(
"data_type",
"published",
"is_open_data",
"has_visuals",
"has_access",
"is_bookmarked",
"table_match",
Expand Down Expand Up @@ -305,30 +301,6 @@ def _annotate_combined_published_date(datasets: QuerySet) -> tuple:
return datasets.annotate(published_date=F("initial_published_at"))

return datasets.annotate(published_date=F("published_at"))


def _annotate_has_visuals(datasets):
"""
Adds a bool annotation to queryset if the dataset has visuals
@param datasets: django queryset
@return: the annotated dataset
"""
if datasets.model is ReferenceDataset or datasets.model is VisualisationCatalogueItem:
datasets = datasets.annotate(has_visuals=Value(False, BooleanField()))
if datasets.model is DataSet:
datasets = datasets.annotate(
has_visuals=Case(
When(
Exists(DataSetVisualisation.objects.filter(dataset_id=OuterRef("id"))),
then=True,
),
default=False,
output_field=BooleanField(),
)
)
return datasets


def _annotate_is_open_data(datasets):
"""
Adds boolean annotation which is True if the dataset is opendata.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
register = template.Library()


@register.simple_tag()
def visualisation_link_or_plain_text(text, condition, dataset_uuid, object_id):
if condition:
url = reverse("datasets:dataset_visualisation", args=[dataset_uuid, object_id])
return mark_safe(f"<a class='govuk-link' href='{url}'>{text}</a>")
# @register.simple_tag()
# def visualisation_link_or_plain_text(text, condition, dataset_uuid, object_id):
# if condition:
# url = reverse("datasets:dataset_visualisation", args=[dataset_uuid, object_id])
# return mark_safe(f"<a class='govuk-link' href='{url}'>{text}</a>")

return text
# return text


@register.simple_tag(takes_context=True)
Expand Down
6 changes: 0 additions & 6 deletions dataworkspace/dataworkspace/apps/datasets/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,6 @@
login_required(views.ReferenceDatasetGridDataView.as_view()),
name="reference_dataset_grid_data",
),
path(
"<uuid:dataset_uuid>/visualisation/<int:object_id>/",
login_required(views.DatasetVisualisationView.as_view()),
{"model_class": models.DataSet},
name="dataset_visualisation",
),
path(
"<uuid:dataset_uuid>/datacut/<int:query_id>/columns",
login_required(views.CustomQueryColumnDetails.as_view()),
Expand Down
35 changes: 0 additions & 35 deletions dataworkspace/dataworkspace/apps/datasets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ def _matches_filters(
)
and (unpublished or data["published"])
and (not opendata or data["is_open_data"])
and (not withvisuals or data["has_visuals"])
and (not data_type or data_type == [None] or data["data_type"] in data_type)
and (not source_ids or source_ids.intersection(set(data["source_tag_ids"])))
and (not topic_ids or topic_ids.intersection(set(data["topic_tag_ids"])))
Expand Down Expand Up @@ -1386,40 +1385,6 @@ def write_metrics_to_eventlog(log_data):
)


class DatasetVisualisationPreview(View):
def _get_vega_definition(self, visualisation):
vega_definition = json.loads(visualisation.vega_definition_json)

if visualisation.query:
with psycopg2.connect(
database_dsn(settings.DATABASES_DATA[visualisation.database.memorable_name])
) as connection:
with connection.cursor(cursor_factory=psycopg2.extras.RealDictCursor) as cursor:
cursor.execute(visualisation.query)
data = cursor.fetchall()
try:
# vega-lite, 'data' is a dictionary
vega_definition["data"]["values"] = data
except TypeError:
# vega, 'data' is a list, and we support setting the query
# results as the first item
vega_definition["data"][0]["values"] = data

return vega_definition

def get(self, request, dataset_uuid, object_id, **kwargs):
model_class = kwargs["model_class"]
dataset = find_dataset(dataset_uuid, request.user, model_class)

if not dataset.user_has_access(request.user):
return HttpResponseForbidden()

visualisation = dataset.visualisations.get(id=object_id)
vega_definition = self._get_vega_definition(visualisation)

return JsonResponse(vega_definition)


class CustomQueryColumnDetails(View):
def get(self, request, dataset_uuid, query_id):
dataset = find_dataset(dataset_uuid, self.request.user, DataCutDataset)
Expand Down
5 changes: 2 additions & 3 deletions dataworkspace/dataworkspace/apps/dw_admin/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
SensitivityType,
SourceLink,
DataSet,
DataSetVisualisation,
ReferenceDataset,
ReferenceDatasetField,
CustomDatasetQuery,
Expand Down Expand Up @@ -631,8 +630,8 @@ def __init__(self, *args, **kwargs):
self.fields["dataset"].queryset = DataCutDataset.objects.live()


class DataSetVisualisationForm(forms.ModelForm):
model = DataSetVisualisation
# class DataSetVisualisationForm(forms.ModelForm):
# model = DataSetVisualisation


class SourceTableForm(forms.ModelForm):
Expand Down
1 change: 0 additions & 1 deletion dataworkspace/dataworkspace/static/vega-lite.min.js.map

This file was deleted.

54 changes: 27 additions & 27 deletions dataworkspace/dataworkspace/tests/datasets/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def expected_search_result(catalogue_item, **kwargs):
"is_bookmarked": False,
"table_match": False,
"is_subscribed": False,
"has_visuals": mock.ANY,
# "has_visuals": mock.ANY,
"is_open_data": getattr(catalogue_item, "user_access_type", None) == UserAccessType.OPEN,
"sources": mock.ANY,
"topics": mock.ANY,
Expand Down Expand Up @@ -1569,25 +1569,25 @@ def _create_related_visualisations(
return visualisations


class TestDatasetVisualisations:
@pytest.mark.parametrize(
"access_type", (UserAccessType.REQUIRES_AUTHENTICATION, UserAccessType.OPEN)
)
@pytest.mark.skip(reason="I am not sure why this fails as the phase name is present in the UI")
@pytest.mark.django_db
def test_prototype_label_is_visible(self, access_type, staff_client):
master_dataset = factories.DataSetFactory.create(
type=DataSetType.MASTER,
published=True,
user_access_type=access_type,
)
expected_gds_phase_name = factory.fuzzy.FuzzyText().fuzz()
factories.VisualisationDatasetFactory.create(
dataset=master_dataset, gds_phase_name=expected_gds_phase_name
)
response = staff_client.get(master_dataset.get_absolute_url())
assert response.status_code == 200
assert expected_gds_phase_name in response.content.decode(response.charset)
# class TestDatasetVisualisations:
# @pytest.mark.parametrize(
# "access_type", (UserAccessType.REQUIRES_AUTHENTICATION, UserAccessType.OPEN)
# )
# @pytest.mark.skip(reason="I am not sure why this fails as the phase name is present in the UI")
# @pytest.mark.django_db
# def test_prototype_label_is_visible(self, access_type, staff_client):
# master_dataset = factories.DataSetFactory.create(
# type=DataSetType.MASTER,
# published=True,
# user_access_type=access_type,
# )
# expected_gds_phase_name = factory.fuzzy.FuzzyText().fuzz()
# factories.VisualisationDatasetFactory.create(
# dataset=master_dataset, gds_phase_name=expected_gds_phase_name
# )
# response = staff_client.get(master_dataset.get_absolute_url())
# assert response.status_code == 200
# assert expected_gds_phase_name in response.content.decode(response.charset)


class TestMasterDatasetDetailView(DatasetsCommon):
Expand Down Expand Up @@ -4269,17 +4269,17 @@ def test_find_datasets_filters_show_datasets_with_visualisations():

assert response.status_code == 200

assert list(response.context["datasets"]) == [
expected_search_result(without_visuals, has_visuals=False),
expected_search_result(with_visuals, has_visuals=True),
]
# assert list(response.context["datasets"]) == [
# expected_search_result(without_visuals, has_visuals=False),
# expected_search_result(with_visuals, has_visuals=True),
# ]

response = client.get(reverse("datasets:find_datasets"), {"admin_filters": "withvisuals"})

assert response.status_code == 200
assert list(response.context["datasets"]) == [
expected_search_result(with_visuals, has_visuals=True)
]
# assert list(response.context["datasets"]) == [
# expected_search_result(with_visuals, has_visuals=True)
# ]


class TestDatasetEditView:
Expand Down
16 changes: 8 additions & 8 deletions dataworkspace/dataworkspace/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ class PublisherTagFactory(TagFactory):
type = TagType.PUBLISHER


class VisualisationDatasetFactory(factory.django.DjangoModelFactory):
name = factory.fuzzy.FuzzyText()
summary = factory.fuzzy.FuzzyText()
gds_phase_name = "prototype"
database = factory.SubFactory(DatabaseFactory)

class Meta:
model = "datasets.DataSetVisualisation"
# class VisualisationDatasetFactory(factory.django.DjangoModelFactory):
# name = factory.fuzzy.FuzzyText()
# summary = factory.fuzzy.FuzzyText()
# gds_phase_name = "prototype"
# database = factory.SubFactory(DatabaseFactory)

# class Meta:
# model = "datasets.DataSetVisualisation"


class DataSetFactory(factory.django.DjangoModelFactory):
Expand Down
Loading

0 comments on commit ab634a6

Please sign in to comment.