Skip to content

Commit

Permalink
Merge 88954ec into e77728c
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaylorhq committed Oct 9, 2016
2 parents e77728c + 88954ec commit 6834ce8
Show file tree
Hide file tree
Showing 13 changed files with 438 additions and 28 deletions.
28 changes: 21 additions & 7 deletions PyRIGS/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,37 @@
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse

def user_passes_test_with_403(test_func, login_url=None):
from RIGS import models


def user_passes_test_with_403(test_func, login_url=None, oembed_view=None):
"""
Decorator for views that checks that the user passes the given test.
Anonymous users will be redirected to login_url, while users that fail
the test will be given a 403 error.
If embed_view is set, then a JS redirect will be used, and a application/json+oembed
meta tag set with the url of oembed_view
(oembed_view will be passed the kwargs from the main function)
"""
if not login_url:
from django.conf import settings
login_url = settings.LOGIN_URL

def _dec(view_func):
def _checklogin(request, *args, **kwargs):
if test_func(request.user):
return view_func(request, *args, **kwargs)
elif not request.user.is_authenticated():
return HttpResponseRedirect('%s?%s=%s' % (login_url, REDIRECT_FIELD_NAME, request.get_full_path()))
if oembed_view is not None:
extra_context = {}
extra_context['oembed_url'] = "{0}://{1}{2}".format(request.scheme, request.META['HTTP_HOST'], reverse(oembed_view, kwargs=kwargs))
extra_context['login_url'] = "{0}?{1}={2}".format(login_url, REDIRECT_FIELD_NAME, request.get_full_path())
resp = render_to_response('login_redirect.html', extra_context, context_instance=RequestContext(request))
return resp
else:
return HttpResponseRedirect('%s?%s=%s' % (login_url, REDIRECT_FIELD_NAME, request.get_full_path()))
else:
resp = render_to_response('403.html', context_instance=RequestContext(request))
resp.status_code = 403
Expand All @@ -28,14 +42,14 @@ def _checklogin(request, *args, **kwargs):
return _checklogin
return _dec

def permission_required_with_403(perm, login_url=None):

def permission_required_with_403(perm, login_url=None, oembed_view=None):
"""
Decorator for views that checks whether a user has a particular permission
enabled, redirecting to the log-in page or rendering a 403 as necessary.
"""
return user_passes_test_with_403(lambda u: u.has_perm(perm), login_url=login_url)
return user_passes_test_with_403(lambda u: u.has_perm(perm), login_url=login_url, oembed_view=oembed_view)

from RIGS import models

def api_key_required(function):
"""
Expand Down Expand Up @@ -64,4 +78,4 @@ def wrap(request, *args, **kwargs):
if user_object.api_key != key:
return error_resp
return function(request, *args, **kwargs)
return wrap
return wrap
26 changes: 25 additions & 1 deletion RIGS/rigboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
from django.template import RequestContext
from django.template.loader import get_template
from django.conf import settings
from django.core.urlresolvers import reverse
from django.http import HttpResponse
from django.db.models import Q
from django.contrib import messages
from z3c.rml import rml2pdf
from PyPDF2 import PdfFileMerger, PdfFileReader
import simplejson

from RIGS import models, forms
import datetime
Expand Down Expand Up @@ -47,6 +49,28 @@ class EventDetail(generic.DetailView):
model = models.Event


class EventOembed(generic.View):
model = models.Event

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',
}

json = simplejson.JSONEncoderForHTML().encode(data)
return HttpResponse(json, content_type="application/json")


class EventEmbed(EventDetail):
template_name = 'RIGS/event_embed.html'


class EventCreate(generic.CreateView):
model = models.Event
form_class = forms.EventForm
Expand All @@ -59,7 +83,7 @@ def get_context_data(self, **kwargs):
form = context['form']
if re.search('"-\d+"', form['items_json'].value()):
messages.info(self.request, "Your item changes have been saved. Please fix the errors and save the event.")


# Get some other objects to include in the form. Used when there are errors but also nice and quick.
for field, model in form.related_models.iteritems():
Expand Down
2 changes: 1 addition & 1 deletion RIGS/static/css/screen.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions RIGS/static/scss/screen.scss
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,43 @@ ins {
};
}
}

html.embedded{
min-height:100%;
display: table;
width: 100%;

body{
padding:0;
display: table-cell;
vertical-align: middle;
width:100%;
}

.embed_container{
border:5px solid #e9e9e9;
padding:12px 0px;
min-height:100%;
width:100%;
}

.source{
background: url('/static/imgs/pyrigs-avatar.png') no-repeat;
background-size: 16px 16px;
padding-left: 20px;
}

h3{
margin-top:10px;
margin-bottom:5px;
}

p{
margin-bottom:2px;
font-size: 11px;
}

.event-mic-photo{
max-width: 3em;
}
}
104 changes: 104 additions & 0 deletions RIGS/templates/RIGS/event_embed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{% extends 'base_embed.html' %}
{% load static from staticfiles %}

{% block content %}

<div class="row">
<div class="col-sm-12">
<span class="source"> R<small>ig</small> I<small>nformation</small> G<small>athering</small> S<small>ystem</small></span>
</div>

<div class="col-sm-12">
<span class="pull-right">
{% if object.mic %}
<div class="text-center">
<img src="{{ object.mic.profile_picture }}" class="event-mic-photo"/>
</div>
{% elif object.is_rig %}
<span class="glyphicon glyphicon-exclamation-sign"></span>
{% endif %}
</span>

<h3>
<a {% if perms.RIGS.view_event %}href="{% url 'event_detail' object.pk %}" target="_top"{% endif %}>
{% if object.is_rig %}N{{ object.pk|stringformat:"05d" }}{% else %}{{ object.pk }}{% endif %}
| {{ object.name }} </a>
{% if object.venue %}
<small>at {{ object.venue }}</small>
{% endif %}
<br/><small>
{{ object.start_date|date:"D d/m/Y" }}
{% if object.has_start_time %}
{{ object.start_time|date:"H:i" }}
{% endif %}
{% if object.end_date or object.has_end_time %}
&ndash;
{% endif %}
{% if object.end_date and object.end_date != object.start_date %}
{{ object.end_date|date:"D d/m/Y" }}
{% endif %}
{% if object.has_end_time %}
{{ object.end_time|date:"H:i" }}
{% endif %}
</small>
</h3>

<div class="row">
<div class="col-xs-6">
<p>
<strong>Status:</strong>
{{ object.get_status_display }}
</p>
<p>
{% if object.is_rig %}
<strong>Client:</strong> {{ object.person.name }}
{% if object.organisation %}
for {{ object.organisation.name }}
{% endif %}
{% if object.dry_hire %}(Dry Hire){% endif %}
{% else %}
<strong>Non-Rig</strong>
{% endif %}
</p>
<p>
<strong>MIC:</strong>
{% if object.mic %}
{{object.mic.name}}
{% else %}
None
{% endif %}
</p>
</div>
<div class="col-xs-6">

{% if object.meet_at %}
<p>
<strong>Crew meet:</strong>
{{ object.meet_at|date:"H:i" }} {{ object.meet_at|date:"(Y-m-d)" }}
</p>
{% endif %}
{% if object.access_at %}
<p>
<strong>Access at:</strong>
{{ object.access_at|date:"H:i" }} {{ object.access_at|date:"(Y-m-d)" }}
</p>
{% endif %}
<p>
<strong>Last updated:</strong>
{{ object.last_edited_at }} by "{{ object.last_edited_by.initials }}"
</p>
</div>
</div>
{% if object.description %}
<p>
<strong>Description: </strong>
{{ object.description|linebreaksbr }}
</p>
{% endif %}

</table>
</div>
</div>


{% endblock %}
Loading

0 comments on commit 6834ce8

Please sign in to comment.