Commit 962c4fdb authored by Janez K's avatar Janez K
Browse files

setupiranje streamov

parent 9aa1b6a9
......@@ -17,6 +17,10 @@ class Stream(models.Model):
period = models.IntegerField(default=60)
active = models.BooleanField(default=False)
@models.permalink
def get_absolute_url(self):
return ('stream', [str(self.id)])
def stream_visualization_widgets(self):
return self.workflow.widgets.all().exclude(abstract_widget__streaming_visualization_view='')
......
{% extends 'website/base.html' %}
{% load url from future %}
{% load date_diff %}
{% block "yourworkflowsactive" %}class="active"{% endblock %}
{% block 'container' %}
<h1>{{stream}}</h1>
<div class="well">
<table class="table table-condensed">
<tbody>
<tr>
<td style="width:20%;"><b>Stream status</b></td>
<td>{% if stream.active %}<span class="label label-success">Active</span>{% else %}<span class="label label-warning">Inactive</span>{% endif %}</td>
</tr>
<tr>
<td><b>Last heartbeat</b></td>
<td>{{ stream.last_executed|date_diff }}</td>
</tr>
<tr>
<td><b>Period</b></td>
<td>{{stream.period}} seconds</td>
</tr>
<tr>
<td><b>Workflow</b></td>
<td><a href="{{stream.workflow.get_absolute_url}}">{{stream.workflow}}</a></td>
</tr>
</tbody>
</table>
</div>
<div class="row">
<div class="span12">
<a href="#" class="btn btn-warning btn-large">Deactivate</a>
<a href="#" class="btn btn-warning btn-danger btn-large">Reset</a>
</div>
</div>
<hr>
<h1>Results widgets</h1>
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Widget title</th>
<th>Results</th>
</tr>
</thead>
<tbody>
{% for w in stream.stream_visualization_widgets %}
<tr>
<td class="name">{{w}}</td>
<td><a href="#" class="btn btn-mini">View results</a></td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
......@@ -19,7 +19,14 @@
<tr>
<td class="name">{{w}}</td>
<td>{% if w.public %}<a href="{{w.get_info_url}}">{{w.get_info_url}}</a>{% else %}This workflow is private.{% endif %}</td>
<td>{% if w.can_be_streaming %}{% if w.stream %}<i class="icon-ok"></i>{% else %}Make into stream{% endif %}{% else %}<span class="label label-info"><i class="icon-remove icon-white"></i> No streaming widgets</span>{% endif %}</td>
<td>
{% if w.can_be_streaming %}
{% if w.stream %}
{% if w.stream.active %}<span class="label label-success"><i class="icon-ok icon-white"></i> Active</span> <a href="{{w.stream.get_absolute_url}}" class="btn btn-mini"><i class="icon-wrench"></i></a>
{% else %}<span class="label label-warning"><i class="icon-remove icon-white"></i> Inactive</span> <a href="{{w.stream.get_absolute_url}}" class="btn btn-mini"><i class="icon-wrench"></i></a>{% endif %}
{% else %}<a href="#" class="btn btn-mini">Start stream mining</a>{% endif %}
{% else %}<span class="label"><i class="icon-remove icon-white"></i> No streaming widgets</span>{% endif %}
</td>
<td><a href="{{w.get_absolute_url}}">Edit</a> | <a href="{{w.get_copy_url}}">Open as new</a> | <a href="javascript:;" rel="{{w.pk}}" class="delete_workflow">Delete</a> | {% if not w.public %}<a href="{% url 'make public' w.pk %}">Make public</a>{% else %}<a href="{% url 'make private' w.pk %}">Make private</a>{% endif %}</td>
</tr>
{% endfor %}
......
from django import template
from django.utils.translation import ungettext, ugettext as _
import datetime
from django.utils.timezone import utc
register = template.Library()
@register.filter
def date_diff(d):
now = datetime.datetime.utcnow().replace(tzinfo=utc)
today = datetime.datetime(now.year, now.month, now.day).replace(tzinfo=utc)
delta = now - d
delta_midnight = today - d
days = delta.days
hours = round(delta.seconds / 3600., 0)
minutes = round(delta.seconds / 60., 0)
seconds = delta.seconds
chunks = (
(365.0, lambda n: ungettext('year', 'years', n)),
(30.0, lambda n: ungettext('month', 'months', n)),
(7.0, lambda n : ungettext('week', 'weeks', n)),
(1.0, lambda n : ungettext('day', 'days', n)),
)
if days == 0:
if hours == 0:
if minutes > 1:
return ungettext('1 minute ago', \
'%(minutes)d minutes ago', minutes) % \
{'minutes': minutes}
else:
return ungettext('1 scond ago', \
'%(seconds)d seconds ago', seconds) % \
{'seconds': seconds}
else:
return ungettext('1 hour ago', '%(hours)d hours ago', hours) \
% {'hours':hours}
if delta_midnight.days == 0:
return _("yesterday at %s") % d.strftime("%H:%M")
count = 0
for i, (chunk, name) in enumerate(chunks):
if days >= chunk:
count = round((delta_midnight.days + 1)/chunk, 0)
break
return _('%(number)d %(type)s ago') % \
{'number': count, 'type': name(count)}
\ No newline at end of file
......@@ -5,6 +5,7 @@ urlpatterns = patterns('',
url(r'^$', 'website.views.index', name='website index'),
url(r'^existing-workflows/', 'website.views.workflows', name='existing workflows'),
url(r'^your-workflows/', 'website.views.your_workflows', name='your workflows'),
url(r'^streams/(?P<stream_id>[0-9]+)/$', 'website.views.stream', name='stream'),
url(r'^make-private/(?P<workflow_id>[0-9]+)/$', 'website.views.make_private', name='make private'),
url(r'^make-public/(?P<workflow_id>[0-9]+)/$', 'website.views.make_public', name='make public'),
......
......@@ -9,6 +9,8 @@ from django.contrib.auth import authenticate, login, logout
from workflows.models import Workflow, Connection
from streams.models import Stream
#settings
from mothra.settings import DEBUG, PROJECT_FOLDER
......@@ -20,6 +22,12 @@ import os
def index(request):
return render(request, 'website/index.html')
def stream(request,stream_id):
stream = get_object_or_404(Stream,pk=stream_id)
if stream.workflow.user != request.user:
raise Http404
return render(request, 'website/stream.html', {'stream':stream})
def workflow_information(request,workflow_id):
w = Workflow.objects.get(pk=workflow_id)
if not w.public:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment