-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
188 lines (171 loc) · 4.91 KB
/
views.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
from django.shortcuts import render, get_object_or_404, reverse, redirect
from django.contrib import messages
from django.contrib.admin.views.decorators import staff_member_required
from plugins.customstyling import forms, models, security, plugin_settings
from journal import models as jm
from repository import models as rm
from utils import setting_handler
from core.forms import GeneratedSettingForm
@security.user_is_staff_or_journal_editor
def manager(request):
cjs_list = models.CrossJournalStylesheet.objects.all()
template = 'customstyling/manager.html'
context = {
'journals': jm.Journal.objects.all(),
'repositories': rm.Repository.objects.all(),
'cjs_list': cjs_list,
}
return render(request, template, context)
@staff_member_required
def settings(request):
form_settings = [
{
'name': 'enable_editor_access',
'object': setting_handler.get_setting(
plugin_settings.CustomstylingPlugin.plugin_group_name,
'enable_editor_access',
request.journal,
),
},
]
form = GeneratedSettingForm(
settings=form_settings,
)
if request.POST:
form = GeneratedSettingForm(
request.POST,
settings=form_settings,
)
if form.is_valid():
form.save(
journal=request.journal,
group=plugin_settings.CustomstylingPlugin.plugin_group_name,
)
return redirect(
reverse(
'customstyling_settings'
)
)
template = 'customstyling/settings.html'
context = {
'form': form,
}
return render(
request,
template,
context,
)
@security.staff_or_editor_access_enabled
def manage_css(request, journal_id=None, repository_id=None):
journal = repository = None
if journal_id:
journal = get_object_or_404(
jm.Journal,
pk=journal_id,
)
elif repository_id:
repository = get_object_or_404(
rm.Repository,
pk=repository_id
)
form = forms.StylingForm(
journal=journal,
repository=repository,
)
if request.POST:
form = forms.StylingForm(
request.POST,
journal=journal,
repository=repository,
)
if form.is_valid():
form.save()
messages.add_message(
request,
messages.SUCCESS,
'Saved.',
)
if journal:
reversed_url = reverse(
'customstyling_manage_css_journal',
kwargs={
'journal_id': journal.pk,
}
)
elif repository:
reversed_url = reverse(
'customstyling_manage_css_repository',
kwargs={
'repository_id': repository.pk,
}
)
return redirect(
reversed_url
)
template = 'customstyling/manage_css.html'
context = {
'journal': journal,
'form': form,
}
return render(request, template, context)
@staff_member_required
def manage_press_css(request):
form = forms.StylingForm()
if request.POST:
form = forms.StylingForm(
request.POST,
)
if form.is_valid():
form.save()
messages.add_message(
request,
messages.SUCCESS,
'Saved.',
)
return redirect(
reverse(
'customstyling_manage_press_css',
)
)
template = 'customstyling/manage_css.html'
context = {
'form': form,
}
return render(request, template, context)
@staff_member_required
def manage_cross_journal_stylesheets(request, stylesheet_id=None):
stylesheet = None
if stylesheet_id:
stylesheet = get_object_or_404(
models.CrossJournalStylesheet,
pk=stylesheet_id,
)
form = forms.CrossJournalStylingForm(
instance=stylesheet,
)
if request.POST:
form = forms.CrossJournalStylingForm(
request.POST,
instance=stylesheet,
)
if form.is_valid():
stylesheet = form.save()
form.save_m2m()
return redirect(
reverse(
'customstyling_edit_lcjsc',
kwargs={
'stylesheet_id': stylesheet.pk,
}
)
)
template = 'customstyling/manage_cross_journal_stylesheet.html'
context = {
'stylesheet': stylesheet,
'form': form,
}
return render(
request,
template,
context,
)