Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add merging of sessions if the connection got lost more then timeout minutes. add deleting links into admin some bugfixes
- Loading branch information
Showing
9 changed files
with
188 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.contrib import admin | ||
from uberclock.db.models import * | ||
|
||
|
||
admin.site.register(Detector) | ||
admin.site.register(WakeupTime) | ||
admin.site.register(Session) |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
try: | ||
from functools import wraps | ||
except ImportError: | ||
from django.utils.functional import wraps | ||
|
||
from django.shortcuts import render_to_response | ||
from django.template import RequestContext | ||
|
||
def confirm_required(template_name, context_creator, key='__confirm__'): | ||
""" | ||
Decorator for views that need confirmation page. For example, delete | ||
object view. Decorated view renders confirmation page defined by template | ||
'template_name'. If request.POST contains confirmation key, defined | ||
by 'key' parameter, then original view is executed. | ||
Context for confirmation page is created by function 'context_creator', | ||
which accepts same arguments as decorated view. | ||
Example | ||
------- | ||
def remove_file_context(request, id): | ||
file = get_object_or_404(Attachment, id=id) | ||
return RequestContext(request, {'file': file}) | ||
@confirm_required('remove_file_confirm.html', remove_file_context) | ||
def remove_file_view(request, id): | ||
file = get_object_or_404(Attachment, id=id) | ||
file.delete() | ||
next_url = request.GET.get('next', '/') | ||
return HttpResponseRedirect(next_url) | ||
Example of HTML template | ||
------------------------ | ||
<h1>Remove file {{ file }}?</h1> | ||
<form method="POST" action=""> | ||
<input type="hidden" name="__confirm__" value="1" /> | ||
<input type="submit" value="delete"/> <a href="{{ file.get_absolute_url }}">cancel</a> | ||
</form> | ||
""" | ||
def decorator(func): | ||
def inner(request, *args, **kwargs): | ||
if request.POST.has_key(key): | ||
return func(request, *args, **kwargs) | ||
else: | ||
context = context_creator and context_creator(request, *args, **kwargs) \ | ||
or RequestContext(request) | ||
return render_to_response(template_name, context) | ||
return wraps(func)(inner) | ||
return decorator |
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,13 @@ | ||
{% extends "base.html" %} | ||
|
||
|
||
{% block content %} | ||
<h1>Are you sure ?</h1> | ||
You will merge session {{ source.id }} into {{ session.id }}. | ||
This will destroy all aditional data known from the source session. | ||
|
||
<form method="POST" action="{% url stats_merge session.id source.id %}"> | ||
<input type="hidden" name="__confirm__" value="1" />{% csrf_token %} | ||
<input type="submit" value="merge"/> <a href="{{ session.get_absolute_url }}">cancel</a> | ||
</form> | ||
{% 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
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