0002-add-user-profile-journal-20695.patch
src/authentic2/forms/__init__.py | ||
---|---|---|
8 | 8 | |
9 | 9 |
from authentic2.compat import get_user_model |
10 | 10 |
from authentic2.forms.fields import PasswordField |
11 |
from authentic2.forms.widgets import DateTimeWidget |
|
11 | 12 | |
12 | 13 |
from .. import app_settings |
13 | 14 |
from ..exponential_retry_timeout import ExponentialRetryTimeout |
... | ... | |
220 | 221 | |
221 | 222 |
class SiteImportForm(forms.Form): |
222 | 223 |
site_json = forms.FileField(label=_('Site Export File')) |
224 | ||
225 | ||
226 |
class EventTimewindowForm(forms.Form): |
|
227 |
after = forms.DateTimeField(label=_('After'), widget=DateTimeWidget) |
|
228 |
before = forms.DateTimeField(label=_('Before'), widget=DateTimeWidget) |
src/authentic2/profile_urls.py | ||
---|---|---|
9 | 9 | |
10 | 10 |
from authentic2.utils import import_module_or_class, redirect |
11 | 11 |
from . import app_settings, decorators, profile_views, hooks |
12 |
from .views import (logged_in, edit_profile, email_change, email_change_verify, profile) |
|
12 |
from .views import (logged_in, edit_profile, email_change, email_change_verify, profile, |
|
13 |
user_profile_journal) |
|
13 | 14 | |
14 | 15 |
SET_PASSWORD_FORM_CLASS = import_module_or_class( |
15 | 16 |
app_settings.A2_REGISTRATION_SET_PASSWORD_FORM_CLASS) |
... | ... | |
94 | 95 |
auth_views.password_reset_done, |
95 | 96 |
name='auth_password_reset_done'), |
96 | 97 |
url(r'^switch-back/$', profile_views.switch_back, name='a2-switch-back'), |
98 |
url('^journal/$', user_profile_journal, name='user-profile-journal'), |
|
97 | 99 |
] |
src/authentic2/templates/authentic2/user_profile_journal.html | ||
---|---|---|
1 |
{% extends "authentic2/base-page.html" %} |
|
2 |
{% load i18n %} |
|
3 |
{% load authentic2_journal %} |
|
4 | ||
5 |
{% block content %} |
|
6 |
<h1>{% trans "User journal" %}</h1> |
|
7 |
<ul> |
|
8 |
{% for line in object_list %} |
|
9 |
<li>{{ line.timestamp }} - {{ line|to_representation }}</li> |
|
10 |
{% empty %} |
|
11 |
<li>{% trans "No journal entry yet." %}</li> |
|
12 |
{% endfor %} |
|
13 |
</ul> |
|
14 |
{% block pagination %} |
|
15 |
{% include "gadjo/pagination.html" %} |
|
16 |
{% endblock %} |
|
17 |
<form action="{% url 'user-profile-journal' %}" method="get"> |
|
18 |
{% csrf_token %} |
|
19 |
{{ form }} |
|
20 |
<input type="submit" value="Submit"> |
|
21 |
</form> |
|
22 |
{% endblock %} |
src/authentic2/views.py | ||
---|---|---|
7 | 7 |
import collections |
8 | 8 | |
9 | 9 | |
10 |
from datetime import datetime |
|
10 | 11 |
from django.conf import settings |
11 | 12 |
from django.shortcuts import render_to_response, render |
12 | 13 |
from django.template.loader import render_to_string, select_template |
13 | 14 |
from django.views.generic.edit import UpdateView, FormView |
14 | 15 |
from django.views.generic import RedirectView, TemplateView |
15 | 16 |
from django.views.generic.base import View |
17 |
from django.views.generic.list import ListView |
|
16 | 18 |
from django.contrib.auth import SESSION_KEY |
17 | 19 |
from django import http, shortcuts |
18 | 20 |
from django.core import mail, signing |
... | ... | |
21 | 23 |
from django.contrib import messages |
22 | 24 |
from django.utils.translation import ugettext as _ |
23 | 25 |
from django.contrib.auth import logout as auth_logout |
24 |
from django.contrib.auth import REDIRECT_FIELD_NAME |
|
26 |
from django.contrib.auth import REDIRECT_FIELD_NAME, get_user_model |
|
27 |
from django.contrib.contenttypes.models import ContentType |
|
25 | 28 |
from django.http import (HttpResponseRedirect, HttpResponseForbidden, |
26 | 29 |
HttpResponse) |
27 | 30 |
from django.core.exceptions import PermissionDenied |
... | ... | |
37 | 40 | |
38 | 41 | |
39 | 42 |
from . import (utils, app_settings, forms, compat, decorators, constants, models, cbv, hooks) |
43 |
from authentic2_journal.models import Reference, Line |
|
40 | 44 | |
41 | 45 | |
42 | 46 |
logger = logging.getLogger(__name__) |
... | ... | |
613 | 617 | |
614 | 618 |
logged_in = never_cache(LoggedInView.as_view()) |
615 | 619 | |
620 | ||
621 |
class UserProfileJournal(ListView, FormView): |
|
622 |
model = Line |
|
623 |
form_class = forms.EventTimewindowForm |
|
624 |
paginate_by = 10 |
|
625 | ||
626 |
def get_queryset(self): |
|
627 |
timewindow = {} |
|
628 |
for qs_param, qs_suffix in {'after': 'gte', 'before': 'lte'}.items(): |
|
629 |
delimiter = self.request.GET.get(qs_param) |
|
630 |
if delimiter: |
|
631 |
try: |
|
632 |
dt = datetime.strptime(delimiter, '%d/%m/%Y %H:%M:%S') |
|
633 |
except: |
|
634 |
logger.info('UserProfileJournal wrong %s timestamp query ' |
|
635 |
'string parameter: %s' % (qs_param, delimiter)) |
|
636 |
else: |
|
637 |
timewindow.update({'timestamp__%s' % qs_suffix: dt}) |
|
638 |
""" |
|
639 |
Timestamp consistency allows for time window filtering on Reference |
|
640 |
objects directly |
|
641 |
""" |
|
642 |
return [ref.line for ref in Reference.objects.filter( |
|
643 |
target_id=self.request.user.pk, |
|
644 |
target_ct=ContentType.objects.get_for_model(get_user_model()), |
|
645 |
**timewindow)] |
|
646 | ||
647 |
def get_template_names(self): |
|
648 |
return [ |
|
649 |
'profiles/user_profile_journal.html', |
|
650 |
'authentic2/user_profile_journal.html', |
|
651 |
] |
|
652 | ||
653 |
user_profile_journal = login_required(UserProfileJournal.as_view()) |
|
654 | ||
655 | ||
616 | 656 |
def csrf_failure_view(request, reason=""): |
617 | 657 |
messages.warning(request, _('The page is out of date, it was reloaded for you')) |
618 | 658 |
return HttpResponseRedirect(request.get_full_path()) |
619 |
- |