Skip to content
Snippets Groups Projects
Commit 0e08e9aa authored by Nico Vermaas's avatar Nico Vermaas
Browse files

remove staging app

parent fd419c08
No related branches found
No related tags found
1 merge request!112Esap gateway query
Pipeline #16264 passed
Showing
with 7 additions and 217 deletions
No preview for this file type
No preview for this file type
File deleted
......@@ -35,7 +35,6 @@ USE_X_FORWARDED_HOST = True
INSTALLED_APPS = [
'query.apps.MyAppConfig',
'staging',
'accounts',
'rucio',
'ida',
......
......@@ -37,10 +37,6 @@ DATABASES = {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'esap_accounts_config.sqlite3'),
},
'staging': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'esap_staging_config.sqlite3'),
},
'ida': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'esap_ida_config.sqlite3'),
......
......@@ -38,10 +38,6 @@ DATABASES = {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '/shared/esap_accounts_config.sqlite3',
},
'staging': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '/shared/esap_staging_config.sqlite3',
},
'ida': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '/shared/esap_ida_config.sqlite3',
......
......@@ -18,7 +18,6 @@ from django.urls import include, path, re_path
urlpatterns = [
path('esap-api/query/', include('query.api.urls')),
path('esap-api/staging/', include('staging.api.urls')),
path('esap-api/rucio/', include('rucio.api.urls')),
path('esap-api/accounts/', include('accounts.api.urls')),
path('esap-api/ida/', include('ida.api.urls')),
......
class QueryRouter:
route_app_labels = {'query', 'auth', 'contenttypes', 'sessions', 'admin'}
custom_router_app_labels = {'ida', 'rucio', 'accounts', 'staging'}
custom_router_app_labels = {'ida', 'rucio', 'accounts'}
def db_for_read(self, model, **hints):
......
......@@ -70,7 +70,7 @@
</div>
<p class="footer" small>ASTRON - version 12 aug 2021</p>
<p class="footer" small>ASTRON - version 12 aug 2021 - 17:00</p>
{% endblock %}
......@@ -4,20 +4,20 @@ class RucioRouter:
def db_for_read(self, model, **hints):
"""
Attempts to read staging models go to staging database.
Attempts to read rucio models go to rucio database.
"""
if model._meta.app_label in self.route_app_labels:
return 'rucio'
def db_for_write(self, model, **hints):
"""
Writes always go to staging.
Writes always go to rucio.
"""
return 'rucio'
def allow_relation(self, obj1, obj2, **hints):
"""
Allow relations if a model in the staging apps is
Allow relations if a model in the rucio apps is
involved.
"""
if (
......@@ -29,8 +29,8 @@ class RucioRouter:
def allow_migrate(self, db, app_label, model_name=None, **hints):
"""
Make sure the staging apps only appear in the
'staging' database.
Make sure the rucio apps only appear in the
'rucio' database.
"""
if app_label in self.route_app_labels:
return db == 'rucio'
......
from django.contrib import admin
from .models import Staging
admin.site.register(Staging)
class MultiDBModelAdmin(admin.ModelAdmin):
# A handy constant for the name of the alternate database.
using = 'staging'
def save_model(self, request, obj, form, change):
# Tell Django to save objects to the 'other' database.
obj.save(using=self.using)
def delete_model(self, request, obj):
# Tell Django to delete objects from the 'other' database
obj.delete(using=self.using)
def get_queryset(self, request):
# Tell Django to look for objects on the 'other' database.
return super().get_queryset(request).using(self.using)
def formfield_for_foreignkey(self, db_field, request, **kwargs):
# Tell Django to populate ForeignKey widgets using a query
# on the 'other' database.
return super().formfield_for_foreignkey(db_field, request, using=self.using, **kwargs)
def formfield_for_manytomany(self, db_field, request, **kwargs):
# Tell Django to populate ManyToMany widgets using a query
# on the 'other' database.
return super().formfield_for_manytomany(db_field, request, using=self.using, **kwargs)
\ No newline at end of file
from rest_framework import serializers
from ..models import Staging
import logging
logger = logging.getLogger(__name__)
class StagingSerializer(serializers.ModelSerializer):
class Meta():
model = Staging
fields = "__all__"
\ No newline at end of file
from django.urls import path
from django.contrib import admin
from rest_framework import routers
from .views import StagingViewSet
from . import views
router = routers.DefaultRouter()
router.register('staging', StagingViewSet, 'staging')
urlpatterns = router.urls
urlpatterns = [
# path('admin', admin.site.urls, name='admin-view'),
path('', views.IndexView.as_view(), name='index-view'),
path('staging', views.StagingListViewAPI.as_view(), name='staging-view'),
]
from django.views.generic import ListView
from django_filters import rest_framework as filters
from rest_framework import viewsets, permissions
from staging.models import Staging
from rest_framework import generics
from .serializers import StagingSerializer
class StagingViewSet(viewsets.ModelViewSet):
serializer_class = StagingSerializer
permission_classes = [permissions.IsAuthenticated]
def get_queryset(self):
return self.request.user.staging.all()
def perform_create(self, serializer):
serializer.save(owner=self.request.user)
# example: /esap/staging/
class IndexView(ListView):
queryset = Staging.objects.all()
serializer_class = StagingSerializer
template_name = 'staging/index.html'
# by default this returns the list in an object called object_list, so use 'object_list' in the html page.
# but if 'context_object_name' is defined, then this returned list is named and can be accessed that way in html.
context_object_name = 'my_staging'
# example: /esap-api/staging/staging/
class StagingListViewAPI(generics.ListCreateAPIView):
"""
A list of Archives
"""
model = Staging
queryset = Staging.objects.all()
serializer_class = StagingSerializer
# using the Django Filter Backend - https://django-filter.readthedocs.io/en/latest/index.html
# filter_backends = (filters.DjangoFilterBackend,)
# filter_class = StagingFilter
\ No newline at end of file
from django.apps import AppConfig
class StagingConfig(AppConfig):
name = 'staging'
class StagingRouter:
route_app_labels = {'staging'}
def db_for_read(self, model, **hints):
"""
Attempts to read staging models go to staging database.
"""
if model._meta.app_label in self.route_app_labels:
return 'staging'
def db_for_write(self, model, **hints):
"""
Writes always go to staging.
"""
return 'staging'
def allow_relation(self, obj1, obj2, **hints):
"""
Allow relations if a model in the staging apps is
involved.
"""
if (
obj1._meta.app_label in self.route_app_labels or
obj2._meta.app_label in self.route_app_labels
):
return True
return None
def allow_migrate(self, db, app_label, model_name=None, **hints):
"""
Make sure the staging apps only appear in the
'staging' database.
"""
if app_label in self.route_app_labels:
return db == 'staging'
return None
\ No newline at end of file
from django.db import models
class Staging(models.Model):
uri = models.CharField(max_length=40, null=False)
status = models.CharField(max_length=40, null=False)
\ No newline at end of file
<!DOCTYPE html>
{% load static %}
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>{% block myBlockTitle %}ESAP API - Staging{% endblock %}</title>
<!-- loads the path to static files -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="{% static 'query/style.css' %}"/>
<link href='https://fonts.googleapis.com/css?family=Raleway' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.2/css/all.css" integrity="sha384-/rXc/GQVaYpyDdyxK+ecHPVYJSN9bmVFBvjA/9eOB+pb3F2w2N6fc5qB9Ew5yIns" crossorigin="anonymous">
<link rel="icon" href="http://uilennest.net/static/esap_icon.jpg">
{% block extra_js %}{% endblock %}
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<!-- Header -->
<div class="navbar-header">
<a class="navbar-brand mb-0 h1">
<h2>
<img src="{% static 'query/esap_logo.png' %}" alt="">
ESAP API Gateway - Staging
</h2>
</a>
</div>
</div>
</nav>
<!-- to add blocks of code -->
{% block myBlock %}
{% endblock %}
</body>
</html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment