mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
FEAT: Add oembed for assets
Don't see the worth in doing supplier currently...we don't OEmbed Org/Venue etc after all...
This commit is contained in:
45
assets/templates/asset_embed.html
Normal file
45
assets/templates/asset_embed.html
Normal file
@@ -0,0 +1,45 @@
|
||||
{% extends 'base_embed.html' %}
|
||||
{% load static from staticfiles %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<a href="/assets">
|
||||
<span class="source"> TEC Asset Database</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-12">
|
||||
<h3>
|
||||
<a href="{% url 'asset_detail' object.asset_id %}">Asset: {{ object.asset_id }} | {{ object.description }} </a>
|
||||
<small class="label label-default">
|
||||
<strong>Category:</strong>
|
||||
{{ object.category }}
|
||||
</small>
|
||||
|
||||
<small class="label label-{{ object.status.display_class|default:'default' }}">
|
||||
<strong>Status:</strong>
|
||||
{{ object.status }}
|
||||
</small>
|
||||
</h3>
|
||||
<br>
|
||||
{% if object.serial_number %}
|
||||
<p>
|
||||
<strong>Serial Number: </strong>
|
||||
{{ object.serial_number }}
|
||||
</p>
|
||||
{% endif %}
|
||||
{% if object.comments %}
|
||||
<p>
|
||||
<strong>Comments: </strong>
|
||||
{{ object.comments|linebreaksbr }}
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
@@ -3,12 +3,15 @@ from django.urls import path
|
||||
from assets import views, models
|
||||
from RIGS import versioning
|
||||
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.views.decorators.clickjacking import xframe_options_exempt
|
||||
from PyRIGS.decorators import permission_required_with_403
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.AssetList.as_view(), name='asset_index'),
|
||||
path('asset/list/', views.AssetList.as_view(), name='asset_list'),
|
||||
path('asset/id/<str:pk>/', views.AssetDetail.as_view(), name='asset_detail'),
|
||||
# Lazy way to enable the oembed redirect...
|
||||
path('asset/id/<str:pk>/', permission_required_with_403('', oembed_view="asset_oembed")(views.AssetDetail.as_view()), name='asset_detail'),
|
||||
path('asset/create/', permission_required_with_403('assets.add_asset')
|
||||
(views.AssetCreate.as_view()), name='asset_create'),
|
||||
path('asset/id/<str:pk>/edit/', permission_required_with_403('assets.change_asset')
|
||||
@@ -21,6 +24,13 @@ urlpatterns = [
|
||||
(views.ActivityTable.as_view()), name='asset_activity_table'),
|
||||
|
||||
path('asset/search/', views.AssetSearch.as_view(), name='asset_search_json'),
|
||||
path('asset/id/<str:pk>/embed/',
|
||||
xframe_options_exempt(
|
||||
login_required(login_url='/user/login/embed/')(views.AssetEmbed.as_view())),
|
||||
name='asset_embed'),
|
||||
path('asset/id/<str:pk>/oembed_json/',
|
||||
views.AssetOembed.as_view(),
|
||||
name='asset_oembed'),
|
||||
|
||||
path('supplier/list', views.SupplierList.as_view(), name='supplier_list'),
|
||||
path('supplier/<int:pk>', views.SupplierDetail.as_view(), name='supplier_detail'),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.http import JsonResponse
|
||||
from django.http import HttpResponse
|
||||
from django.views import generic
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.utils.decorators import method_decorator
|
||||
@@ -9,6 +10,8 @@ from django.shortcuts import get_object_or_404
|
||||
from assets import models, forms
|
||||
from RIGS import versioning
|
||||
|
||||
import simplejson
|
||||
|
||||
|
||||
@method_decorator(csrf_exempt, name='dispatch')
|
||||
class AssetList(LoginRequiredMixin, generic.ListView):
|
||||
@@ -149,6 +152,28 @@ class AssetDuplicate(DuplicateMixin, AssetIDUrlMixin, AssetCreate):
|
||||
return context
|
||||
|
||||
|
||||
class AssetOembed(generic.View):
|
||||
model = models.Asset
|
||||
|
||||
def get(self, request, pk=None):
|
||||
embed_url = reverse('event_embed', args=[pk])
|
||||
full_url = "{0}://{1}{2}".format(request.scheme, request.META['HTTP_HOST'], embed_url)
|
||||
|
||||
data = {
|
||||
'html': '<iframe src="{0}" frameborder="0" width="100%" height="250"></iframe>'.format(full_url),
|
||||
'version': '1.0',
|
||||
'type': 'rich',
|
||||
'height': '250'
|
||||
}
|
||||
|
||||
json = simplejson.JSONEncoderForHTML().encode(data)
|
||||
return HttpResponse(json, content_type="application/json")
|
||||
|
||||
|
||||
class AssetEmbed(AssetDetail):
|
||||
template_name = 'asset_embed.html'
|
||||
|
||||
|
||||
class SupplierList(generic.ListView):
|
||||
model = models.Supplier
|
||||
template_name = 'supplier_list.html'
|
||||
|
||||
Reference in New Issue
Block a user