-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp_views.py
More file actions
55 lines (42 loc) · 1.66 KB
/
app_views.py
File metadata and controls
55 lines (42 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import requests
from django import forms
from django.contrib import messages
from django.http import HttpResponse
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from app.plugins import logger
from .pipelines import get_json, get_all
import json
class SettingsForm(forms.Form):
pipelines_url = forms.CharField(label='Custom pipelines repo URL(s) (comma-separated)', required=False, max_length=1024, widget=forms.TextInput(attrs={'placeholder': 'Pipelines Url'}))
def HomeView(plugin):
@login_required
def home(request):
ds = plugin.get_user_data_store(request.user)
# if this is a POST request we need to process the form data
if request.method == 'POST':
form = SettingsForm(request.POST)
if form.is_valid():
ds.set_string('pipelines_url', form.cleaned_data['pipelines_url'])
messages.success(request, 'Settings updated.')
form = SettingsForm(initial={'pipelines_url': ds.get_string('pipelines_url', default="")})
return render(request, plugin.template_path("app.html"), {
'title': 'ASDC',
'form': form
})
return home
def LoadButtonsView(plugin):
def view(request):
pipelines = []
if request.user.is_authenticated:
pipelines = get_all(request.user)
return render(
request,
plugin.template_path("load_buttons.js"),
{
"api_url": "/api" + plugin.public_url("").rstrip("/"),
"pipelines": json.dumps(pipelines),
},
content_type="text/javascript",
)
return view