Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to support Project and Site rule exports #104

Merged
merged 1 commit into from
Nov 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions promgen/templates/promgen/project_detail_configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@

<a href="{% url 'audit-list' %}?project={{project.id}}" class="btn btn-info btn-sm">{% trans "Edit History" %}</a>
<a href="{% url 'project-update' project.id %}" class="btn btn-warning btn-sm">{% trans "Update Project" %}</a>
<a href="{% url 'project-targets' project.id %}" class="btn btn-default btn-sm">{% trans "Export Project" %}</a>

<div class="btn-group btn-group-sm" role="group" aria-label="...">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Export <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li role="presentation"><a href="{% url 'rule-export' 'project' project.id %}">{% trans "Export Rules" %}</a></li>
<li role="presentation"><a href="{% url 'project-targets' project.id %}">{% trans "Export Project" %}</a></li>
</ul>
</div>

<form method="post" action="{% url 'project-delete' project.id %}" onsubmit="return confirm('{% trans "Delete this Project?" %}')" style="display: inline">
{% csrf_token %}
<button class="btn btn-danger btn-sm">{% trans "Delete Project" %}</button>
<button class="btn btn-danger btn-sm pull-right">{% trans "Delete Project" %}</button>
</form>
</div>
</div>
2 changes: 1 addition & 1 deletion promgen/templates/promgen/service_block.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
Export <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li role="presentation"><a href="{% url 'service-rules' service.id %}">{% trans "Export Rules" %}</a></li>
<li role="presentation"><a href="{% url 'rule-export' 'service' service.id %}">{% trans "Export Rules" %}</a></li>
<li role="presentation"><a href="{% url 'service-targets' service.id %}">{% trans "Export Service" %}</a></li>
</ul>
</div>
Expand Down
10 changes: 5 additions & 5 deletions promgen/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls import url
from django.contrib import admin
from django.urls import include, path
from django.views.decorators.csrf import csrf_exempt

from promgen import views

urlpatterns = [
Expand All @@ -36,7 +36,6 @@
url(r'^service/(?P<pk>[0-9]+)/delete$', views.ServiceDelete.as_view(), name='service-delete'),
url(r'^service/(?P<pk>[0-9]+)/new$', views.ProjectRegister.as_view(), name='project-new'),
url(r'^service/(?P<pk>[0-9]+)/targets$', views.ServiceTargets.as_view(), name='service-targets'),
url(r'^service/(?P<pk>[0-9]+)/rules$', views.ServiceRules.as_view(), name='service-rules'),
url(r'^service/(?P<pk>[0-9]+)/update$', views.ServiceUpdate.as_view(), name='service-update'),
url(r'^service/(?P<pk>[0-9]+)/notifier$', views.ServiceNotifierRegister.as_view(), name='service-notifier'),

Expand All @@ -49,7 +48,6 @@
url(r'^project/(?P<pk>[0-9]+)/scrape$', views.ExporterScrape.as_view(), name='exporter-scrape'),
url(r'^project/(?P<pk>[0-9]+)/exporter$', views.ExporterRegister.as_view(), name='project-exporter'),
url(r'^project/(?P<pk>[0-9]+)/targets$', views.ProjectTargets.as_view(), name='project-targets'),
url(r'^project/(?P<pk>[0-9]+)/rules$', views.ProjectRules.as_view(), name='project-rules'),
url(r'^project/(?P<pk>[0-9]+)/notifier$', views.ProjectNotifierRegister.as_view(), name='project-notifier'),

url(r'^exporter/(?P<pk>[0-9]+)/delete$', views.ExporterDelete.as_view(), name='exporter-delete'),
Expand All @@ -76,13 +74,15 @@

url(r'^rules/$', views.RulesList.as_view(), name='rules-list'),
url(r'^rule/import$', views.RuleImport.as_view(), name='rule-import'),
url(r'^(?P<content_type>(site|service|project))/(?P<object_id>[0-9]+)/rule$', views.RuleRegister.as_view(), name='rule-new'),
url(r'^rule/(?P<pk>[0-9]+)/edit$', views.RuleUpdate.as_view(), name='rule-edit'),
url(r'^rule/(?P<pk>[0-9]+)/delete$', views.RuleDelete.as_view(), name='rule-delete'),
url(r'^rule/(?P<pk>[0-9]+)/toggle$', views.RuleToggle.as_view(), name='rule-toggle'),
url(r'^rule/(?P<pk>[0-9]+)/test$', csrf_exempt(views.RuleTest.as_view()), name='rule-test'),
url(r'^rule/(?P<pk>[0-9]+)/duplicate$', views.RulesCopy.as_view(), name='rule-overwrite'),

path('<content_type>/<object_id>/rule', views.RuleRegister.as_view(), name='rule-new'),
path('<content_type>/<object_id>/rules', views.RuleExport.as_view(), name='rule-export'),

url(r'^audit/$', views.AuditList.as_view(), name='audit-list'),
url(r'^status/$', views.Status.as_view(), name='status'),
url(r'^import/$', views.Import.as_view(), name='import'),
Expand Down
17 changes: 5 additions & 12 deletions promgen/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,18 +935,11 @@ def get(self, request):
return self.format()


class ServiceRules(_ExportRules):
def get(self, request, pk):
service = get_object_or_404(models.Service, id=pk)
rules = models.Rule.filter(obj=service)
return self.format(rules, service.name)


class ProjectRules(_ExportRules):
def get(self, request, pk):
project = get_object_or_404(models.Project, id=pk)
rules = models.Rule.filter(obj=project)
return self.format(rules, project.name)
class RuleExport(_ExportRules):
def get(self, request, content_type, object_id):
ct = ContentType.objects.get(app_label="promgen", model=content_type).get_object_for_this_type(pk=object_id)
rules = models.Rule.filter(obj=ct)
return self.format(rules)


class URLConfig(View):
Expand Down