-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
295 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
from .base import ViewSite | ||
from .viewform import (Layout, Row, Column, Fieldset, Inline, # NOQA | ||
Field, Span2, Span3, Span4, Span5, Span6, | ||
Span7, Span8, Span9, Span10, Span11, Span12, | ||
LayoutMixin) | ||
|
||
|
||
flowsite = ViewSite() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from django.conf.urls import patterns, url, include | ||
|
||
from . import views | ||
|
||
|
||
class ViewSite(object): | ||
login_view = staticmethod(views.LoginView.as_view()) | ||
logout_view = staticmethod(views.LogoutView.as_view()) | ||
|
||
# all process views | ||
processes_list_view = staticmethod(views.processes_list_view) | ||
tasks_list_view = staticmethod(views.tasks_list_view) | ||
queues_view = staticmethod(views.queues_view) | ||
|
||
# per-process views | ||
process_list_view = staticmethod(views.ProcessListView.as_view()) | ||
process_detail_view = staticmethod(views.process_detail_view) | ||
task_list_view = staticmethod(views.task_list_view) | ||
queue_view = staticmethod(views.queue_view) | ||
|
||
def __init__(self, app_name='viewsite_default'): | ||
self.app_name = app_name | ||
self.flows = [] | ||
|
||
@property | ||
def urls(self): | ||
site_patterns = patterns( | ||
'', | ||
url('^$', self.processes_list_view, {'flow_site': self}, name="index"), | ||
url('^login/$', self.login_view, {'flow_site': self}, name="login"), | ||
url('^logout/$', self.logout_view, {'flow_site': self}, name="logout"), | ||
url('^tasks/$', self.tasks_list_view, {'flow_site': self}, name="tasks"), | ||
url('^queues/$', self.queues_view, {'flow_site': self}, name="queues"), | ||
) | ||
|
||
urls = [ | ||
url('', include(site_patterns, self.app_name, 'viewflow_site')) | ||
] | ||
|
||
for flow_cls in self.flows: | ||
flow_patterns, namespace, app_name = flow_cls.instance.urls | ||
|
||
list_patterns = patterns( | ||
'', | ||
url('^$', self.process_list_view, | ||
{'flow_site': self, 'flow_cls': flow_cls}, name='index'), | ||
url('^tasks/$', self.task_list_view, | ||
{'flow_site': self, 'flow_cls': flow_cls}, name='tasks'), | ||
url('^queues/$', self.queue_view, | ||
{'flow_site': self, 'flow_cls': flow_cls}, name='queue') | ||
) | ||
|
||
urls.append( | ||
url('^{}/'.format(flow_cls._meta.flow_label), | ||
include(list_patterns + flow_patterns, app_name, namespace))) | ||
|
||
return patterns('', *urls) | ||
|
||
def register(self, flow_cls): | ||
if flow_cls not in self.flows: | ||
self.flows.append(flow_cls) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django import forms | ||
|
||
|
||
class LoginForm(forms.Form): | ||
username = forms.CharField(max_length=250) | ||
password = forms.CharField(max_length=250, widget=forms.PasswordInput) | ||
remember = forms.BooleanField(default=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,3 +113,7 @@ body { | |
background: none; | ||
color: #285e8e; | ||
} | ||
|
||
.login-panel { | ||
margin-top: 25%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,3 @@ | |
|
||
{% block title %}Viewflow{% endblock %} | ||
{% block branding %}Viewflow{% endblock %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
viewflow/site/templates/viewflow/form/bootstrap3/widgets/passwordinput.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% extends 'viewflow/form/bootstrap3/widgets/textinput.html' %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{% extends "viewflow/base_site.html" %} | ||
{% load viewform %} | ||
|
||
{% block content %} | ||
<div class="col-md-4 col-md-offset-4"> | ||
<div class="login-panel panel panel-default"> | ||
<div class="panel-heading"> | ||
<h3 class="panel-title">Please Sign In</h3> | ||
</div> | ||
<div class="panel-body"> | ||
<form role="form" method="POST"> | ||
{% csrf_token %} | ||
{% viewform 'viewflow/form/bootstrap3/form.html' form=form layout=view.layout %} {% endviewform %} | ||
<button type="submit" name="start" class="btn btn-lg btn-success btn-block">Login</button> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{% if page.has_other_pages %} | ||
<div class="row text-center"> | ||
<ul class="pagination"> | ||
{% if page.has_previous %} | ||
<li><a href="?page={{ page.previous_page_number }}">«</a></li> | ||
{% else %} | ||
<li class="disabled"><a href="#">«</a></li> | ||
{% endif %} | ||
{% for page_num in page_range %} | ||
{% if page_num != '.' %} | ||
{% if page_num == page.number %} | ||
<li class="active"><a href="#">{{ page_num }} <span class="sr-only">(current)</span></a></li> | ||
{% else %} | ||
<li><a href="?page={{ page_num }}">{{ page_num }}</a></li> | ||
{% endif %} | ||
{% else %} | ||
<li><span>...</span></li> | ||
{% endif %} | ||
{% endfor %} | ||
{% if page.has_next %} | ||
<li><a href="?page={{ page.next_page_number }}">»</a></li> | ||
{% else %} | ||
<li class="disabled"><a href="#">»</a></li> | ||
{% endif %} | ||
</ul> | ||
</div> | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
from django.contrib.auth import login as auth_login | ||
from django.contrib.auth import logout as auth_logout | ||
from django.contrib.auth.forms import AuthenticationForm | ||
from django.core.urlresolvers import reverse | ||
from django.http import HttpResponseRedirect | ||
from django.views import generic | ||
|
||
from viewflow import flow | ||
|
||
|
||
class FlowSiteMixin(object): | ||
flow_site = None | ||
|
||
def dispatch(self, request, *args, **kwargs): | ||
if 'flow_site' in kwargs: | ||
self.flow_site = kwargs['flow_site'] | ||
if 'flow_cls' in kwargs: | ||
self.flow_cls = kwargs['flow_cls'] | ||
|
||
return super(FlowSiteMixin, self).dispatch(request, *args, **kwargs) | ||
|
||
|
||
class LoginView(FlowSiteMixin, generic.FormView): | ||
form_class = AuthenticationForm | ||
template_name = 'viewflow/login.html' | ||
|
||
def get_success_url(self): | ||
return reverse('viewflow_site:index', current_app=self.flow_site.app_name) | ||
|
||
def form_valid(self, form): | ||
auth_login(self.request, form.get_user()) | ||
return HttpResponseRedirect(self.get_success_url()) | ||
|
||
|
||
class LogoutView(FlowSiteMixin, generic.View): | ||
def get_success_url(self): | ||
return reverse('viewflow_site:login', current_app=self.flow_site.app_name) | ||
|
||
def get(self, request, *args, **kwargs): | ||
auth_logout(request) | ||
return HttpResponseRedirect(self.get_success_url()) | ||
|
||
|
||
def processes_list_view(request, flow_site=None): | ||
""" | ||
All process instances list available for current user | ||
""" | ||
pass | ||
|
||
|
||
def tasks_list_view(request, flow_site=None): | ||
""" | ||
All tasks from all processes assigned to current user | ||
""" | ||
pass | ||
|
||
|
||
def queues_view(request, flow_site=None): | ||
""" | ||
All unassigned tasks available for current user | ||
""" | ||
pass | ||
|
||
|
||
class ProcessListView(FlowSiteMixin, generic.ListView): | ||
paginate_by = 3 | ||
paginate_orphans = 0 | ||
context_object_name = 'process_list' | ||
|
||
def get_template_names(self): | ||
return ('{}/flow/index.html'.format(self.flow_cls._meta.app_label), | ||
'viewflow/flow/index.html') | ||
|
||
def available_start_actions(self): | ||
""" | ||
Return list of start flow actions data available for the user | ||
""" | ||
|
||
actions = [] | ||
for node in self.flow_cls._meta.nodes(): | ||
if isinstance(node, flow.Start) and node.has_perm(self.request.user): | ||
node_url = reverse( | ||
'viewflow:{}'.format(node.name), | ||
current_app=self.flow_cls._meta.namespace) | ||
|
||
actions.append((node_url, node.name)) | ||
|
||
return actions | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super(ProcessListView, self).get_context_data(**kwargs) | ||
context['start_actions'] = self.available_start_actions() | ||
context['flow_cls'] = self.flow_cls | ||
return context | ||
|
||
def get_queryset(self): | ||
return self.flow_cls.process_cls.objects \ | ||
.filter(flow_cls=self.flow_cls) \ | ||
.order_by('-created') | ||
|
||
|
||
def process_detail_view(request, flow_site=None, flow_cls=None): | ||
""" | ||
Details for process | ||
""" | ||
|
||
|
||
def task_list_view(request, flow_site=None, flow_cls=None): | ||
""" | ||
List of specific Flow tasks assigned to current user | ||
""" | ||
|
||
|
||
def queue_view(request, flow_site=None, flow_cls=None): | ||
""" | ||
List of specific Flow unassigned tasks available for current user | ||
""" |