Skip to content

Commit

Permalink
rename to project and use neapolitan
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokant committed Jun 6, 2024
1 parent efa3dc2 commit 6744aa9
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 104 deletions.
8 changes: 4 additions & 4 deletions src/genlab_bestilling/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
EquimentOrderQuantity,
EquipmentOrder,
EquipmentType,
GenLabProject,
Location,
Marker,
Order,
Organization,
Project,
Sample,
SampleType,
Species,
Expand Down Expand Up @@ -67,11 +67,11 @@ class LocationAdmin(ModelAdmin):
search_fields = ["name"]


@admin.register(GenLabProject)
class GenLabProjectAdmin(ModelAdmin):
@admin.register(Project)
class ProjectAdmin(ModelAdmin):
list_display = [
"name",
"project",
"number",
"verified",
"samples_owner",
"area",
Expand Down
116 changes: 58 additions & 58 deletions src/genlab_bestilling/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0.6 on 2024-05-21 12:50
# Generated by Django 5.0.6 on 2024-06-06 08:36

import django.contrib.postgres.fields.ranges
import django.db.models.deletion
Expand Down Expand Up @@ -88,43 +88,6 @@ class Migration(migrations.Migration):
("unit", models.CharField(max_length=50)),
],
),
migrations.CreateModel(
name="GenLabProject",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(blank=True, max_length=255, null=True)),
("project", models.BigIntegerField(verbose_name="Project number")),
("verified", models.BooleanField(default=False)),
("expected_total_samples", models.IntegerField(blank=True, null=True)),
(
"analysis_timerange",
django.contrib.postgres.fields.ranges.DateRangeField(
blank=True, null=True
),
),
(
"analysis_types",
models.ManyToManyField(
blank=True, to="genlab_bestilling.analysistype"
),
),
(
"area",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
to="genlab_bestilling.area",
),
),
],
),
migrations.CreateModel(
name="Location",
fields=[
Expand Down Expand Up @@ -228,34 +191,71 @@ class Migration(migrations.Migration):
},
bases=("genlab_bestilling.order",),
),
migrations.CreateModel(
name="Project",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(blank=True, max_length=255, null=True)),
("number", models.BigIntegerField(verbose_name="Project number")),
("verified", models.BooleanField(default=False)),
("expected_total_samples", models.IntegerField(blank=True, null=True)),
(
"analysis_timerange",
django.contrib.postgres.fields.ranges.DateRangeField(
blank=True, null=True
),
),
(
"analysis_types",
models.ManyToManyField(
blank=True, to="genlab_bestilling.analysistype"
),
),
(
"area",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
to="genlab_bestilling.area",
),
),
(
"samples_owner",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.PROTECT,
to="genlab_bestilling.organization",
),
),
(
"sample_types",
models.ManyToManyField(
blank=True, to="genlab_bestilling.sampletype"
),
),
],
),
migrations.AddField(
model_name="order",
name="project",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="genlab_bestilling.genlabproject",
),
),
migrations.AddField(
model_name="genlabproject",
name="samples_owner",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.PROTECT,
to="genlab_bestilling.organization",
to="genlab_bestilling.project",
),
),
migrations.AddField(
model_name="order",
name="sample_types",
field=models.ManyToManyField(to="genlab_bestilling.sampletype"),
),
migrations.AddField(
model_name="genlabproject",
name="sample_types",
field=models.ManyToManyField(blank=True, to="genlab_bestilling.sampletype"),
),
migrations.CreateModel(
name="Species",
fields=[
Expand All @@ -280,14 +280,14 @@ class Migration(migrations.Migration):
],
),
migrations.AddField(
model_name="order",
model_name="project",
name="species",
field=models.ManyToManyField(to="genlab_bestilling.species"),
field=models.ManyToManyField(blank=True, to="genlab_bestilling.species"),
),
migrations.AddField(
model_name="genlabproject",
model_name="order",
name="species",
field=models.ManyToManyField(blank=True, to="genlab_bestilling.species"),
field=models.ManyToManyField(to="genlab_bestilling.species"),
),
migrations.CreateModel(
name="Sample",
Expand Down
6 changes: 3 additions & 3 deletions src/genlab_bestilling/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ class Location(models.Model):
station_id = models.CharField(max_length=20)


class GenLabProject(models.Model):
class Project(models.Model):
"""
A GenLab project, multiple GenLab projects can have the same NINA project code
"""

name = models.CharField(max_length=255, null=True, blank=True)
# external projects without project code? how to handle them?
project = models.BigIntegerField(verbose_name=_("Project number"))
number = models.BigIntegerField(verbose_name=_("Project number"))
verified = models.BooleanField(default=False)
samples_owner = models.ForeignKey(
"Organization", on_delete=models.PROTECT, blank=True, null=True
Expand All @@ -88,7 +88,7 @@ def __str__(self):


class Order(PolymorphicModel):
project = models.ForeignKey("GenLabProject", on_delete=models.CASCADE)
project = models.ForeignKey("Project", on_delete=models.CASCADE)
species = models.ManyToManyField("Species")
sample_types = models.ManyToManyField("SampleType")
notes = models.TextField()
Expand Down
22 changes: 2 additions & 20 deletions src/genlab_bestilling/urls.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
from django.urls import path

from .views import (
GenLabProjectCreateView,
GenLabProjectDetailView,
GenLabProjectsListView,
OrdersListView,
)
from .views import ProjectsView

appname = "genlab_bestilling"
urlpatterns = [
path("projects/", GenLabProjectsListView.as_view(), name="projects-list"),
path("projects/create/", GenLabProjectCreateView.as_view(), name="projects-create"),
path(
"projects/<int:pk>/", GenLabProjectDetailView.as_view(), name="projects-detail"
),
path(
"projects/<int:project_id>/orders/",
OrdersListView.as_view(),
name="orders-list",
),
]
urlpatterns = [*ProjectsView.get_urls()]
27 changes: 8 additions & 19 deletions src/genlab_bestilling/views.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
from apps.ui.views import UICreateView, UIDetailView, UIListView
from django.urls import reverse_lazy
from django.contrib.auth.mixins import LoginRequiredMixin
from neapolitan.views import CRUDView

from .models import GenLabProject, Order
from .models import Order, Project


class GenLabProjectsListView(UIListView):
model = GenLabProject
filterset_fields = ("name",)
create_path = "projects-create"


class GenLabProjectCreateView(UICreateView):
model = GenLabProject
class ProjectsView(LoginRequiredMixin, CRUDView):
model = Project
fields = (
"project",
"number",
"name",
"area",
"species",
Expand All @@ -22,14 +16,9 @@ class GenLabProjectCreateView(UICreateView):
"expected_total_samples",
"analysis_timerange",
)
success_url = reverse_lazy("projects-list")


class GenLabProjectDetailView(UIDetailView):
model = GenLabProject
filterset_fields = ["name"]


class OrdersListView(UIListView):
class OrdersView(CRUDView):
model = Order
filterset_fields = ("polymorphic_ctype",)
create_path = "projects-create"

0 comments on commit 6744aa9

Please sign in to comment.