Skip to content

Commit 0826f1a

Browse files
committed
Add gocam_app with a form for GO-CAM viewing
1 parent 36ab02a commit 0826f1a

12 files changed

Lines changed: 111 additions & 0 deletions

File tree

gocam_app/__init__.py

Whitespace-only changes.

gocam_app/admin.py

Whitespace-only changes.

gocam_app/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class GocamAppConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'gocam_app'

gocam_app/forms.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from django import forms
2+
3+
class IdForm(forms.Form):
4+
ids = forms.CharField(label=False, widget=forms.Textarea)

gocam_app/migrations/__init__.py

Whitespace-only changes.

gocam_app/models.py

Whitespace-only changes.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>GO-CAMs</title>
5+
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
6+
7+
<style>
8+
#ids {
9+
width: 50em;
10+
height: 30em;
11+
}
12+
#ids-submit {
13+
margin-top: 1em;
14+
font-size: 110%;
15+
}
16+
</style>
17+
</head>
18+
<body>
19+
<h4>Links:</h4>
20+
21+
<ul>
22+
<li>
23+
<a href="{{app_path}}/view/ALL_CONNECTED:show_models">All connected models</a>
24+
</li>
25+
<li>
26+
<a href="{{app_path}}/view/ALL_MERGED:show_models">All models</a>
27+
</li>
28+
<li>
29+
<a href="{{app_path}}/summary/connected_only">Summary map of connected models</a>
30+
</li>
31+
<li>
32+
<a href="{{app_path}}/summary/all_models">Summary map of all models</a>
33+
</li>
34+
</ul>
35+
36+
<h4>Create a model from IDs:</h4>
37+
38+
<form id="id-lookup" action="" method="post">
39+
{% csrf_token %}
40+
<div>
41+
{{ form }}
42+
</div>
43+
<input id="ids-submit" type="submit" value="View GO-CAM(s)">
44+
</form>
45+
46+
</body>
47+
</html>

gocam_app/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

gocam_app/urls.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django.urls import path
2+
3+
from . import views
4+
5+
urlpatterns = [
6+
path('', views.index, name='index'),
7+
path('lookup_ids', views.index, name='lookup_ids'),
8+
]

gocam_app/views.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from django.http import HttpResponseRedirect
2+
from django.shortcuts import render
3+
4+
import urllib.parse
5+
import re
6+
7+
from .forms import IdForm
8+
9+
def index(request):
10+
app_path = request.GET.get('app_path', '').strip()
11+
12+
context = {
13+
'app_path': app_path,
14+
}
15+
16+
if request.method == "POST":
17+
form = IdForm(request.POST)
18+
if form.is_valid():
19+
ids = form.cleaned_data["ids"].replace("\n", " ")
20+
ids = ids.replace("gomodel:", "");
21+
22+
ids = 'B+' + re.sub(r'(?:\s|[,;])+', '+', ids)
23+
ids = urllib.parse.quote_plus(ids)
24+
25+
url = f"{app_path}/view/{ids}:show_models"
26+
print(app_path)
27+
return HttpResponseRedirect(url)
28+
29+
else:
30+
form = IdForm()
31+
32+
context["form"] = form
33+
34+
return render(request, "gocam_app/index.html", context)

0 commit comments

Comments
 (0)