Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin'
Browse files Browse the repository at this point in the history
  • Loading branch information
helgihg committed Jun 17, 2018
2 parents 36af545 + f1c99a2 commit 1d8a307
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 11 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.10.8
0.10.9
10 changes: 10 additions & 0 deletions core/contextprocessors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.conf import settings
from django.utils.translation import ugettext as _


def globals(request):
Expand All @@ -17,3 +18,12 @@ def globals(request):
ctx.update(request.globals)

return ctx


def auto_logged_out(request):
if hasattr(request, 'auto_logged_out') and request.auto_logged_out:
return {
'splash_message': _('For security reasons, you have been automatically logged out due to inactivity.')
}

return {}
2 changes: 1 addition & 1 deletion core/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def process_request(self, request):
last_visit = datetime.strptime(request.session['last_visit'], '%Y-%m-%d %H:%M:%S')
if now - last_visit > timedelta(0, settings.AUTO_LOGOUT_DELAY * 60, 0):
auth.logout(request)
return redirect('/accounts/logout?timeout=1')
request.auto_logged_out = True

request.session['last_visit'] = now.strftime('%Y-%m-%d %H:%M:%S')

Expand Down
3 changes: 2 additions & 1 deletion core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,11 @@ def jsonize_issue(issue):
'name': issue.name,
'polity': issue.polity.slug,
'polity_name': issue.polity.name,
'issue_num': '%d/%d' % (issue.issue_num, issue.issue_year),
'issue_num': ('%d/%d' % (issue.issue_num, issue.issue_year)) if issue.issue_num else None,
'state': issue.issue_state(),
'created': issue.created.strftime(dt_format),
'ended': issue.deadline_votes.strftime(dt_format),
'archived': issue.archived,
}

# We only include this field if the issue has been processed because
Expand Down
19 changes: 15 additions & 4 deletions issue/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@
from django.utils import timezone


class IssueManager(models.Manager):
def get_queryset(self):
return super(IssueManager, self).get_queryset().filter(archived=False)

# A mixin for containing methods that need to be in both the queryset and the
# manager. We need IssueManager.get_queryset to filter out archived issues
# automatically, and since a corresponding default-queryset function does not
# seem to exist in QuerySet, we cannot simply use IssueQuerySet.as_manager()
# as is commonly recommended. Instead, this class is used as an extra
# constructor for both IssueManager and IssueQuerySet.
class IssueMixin():
def recent(self):
return self.filter(deadline_votes__gt=timezone.now() - timezone.timedelta(days=settings.RECENT_ISSUE_DAYS))

class IssueManager(models.Manager, IssueMixin):
def get_queryset(self):
return IssueQuerySet(self.model, using=self._db).filter(archived=False)

# Inherits from IssueMixin.
class IssueQuerySet(models.QuerySet, IssueMixin):
pass


class Issue(models.Model):
objects = IssueManager()
Expand Down
1 change: 1 addition & 0 deletions wasa2il/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.request',
'core.contextprocessors.globals',
'core.contextprocessors.auto_logged_out',
'polity.contextprocessors.polities',
],
},
Expand Down
2 changes: 2 additions & 0 deletions wasa2il/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@

{% block dialog %}{% endblock %}

{% include 'splash-message.html' %}

<div id="content-wrapper">
{% comment %}
{% block breadcrumbs %}
Expand Down
4 changes: 0 additions & 4 deletions wasa2il/templates/registration/logout.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

<h1>{% trans "Logged out" %}</h1>

{% if request.GET.timeout %}
<p>{% trans 'For security reasons, you have been automatically logged out due to inactivity.' %}</p>
{% endif %}

<p>{% trans "We hope you'll be back soon. It'd be fun!" %}</p>

<a class="btn btn-primary" href="/accounts/login/">{% trans "Log in" %}</a>
Expand Down
23 changes: 23 additions & 0 deletions wasa2il/templates/splash-message.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% load i18n %}

{% if splash_message %}

<script language="javascript" type="text/javascript">

var SPLASH_MESSAGE_SECONDS = 10;

function slideup_splash_message() {
$('#splash-message').slideUp();
}

$(document).ready(function() {
setTimeout(slideup_splash_message, SPLASH_MESSAGE_SECONDS * 1000);
});

</script>

<div id="splash-message" class="alert alert-warning" style="margin: 0px;">
<strong>{{ splash_message }}</strong>
</div>

{% endif %}

0 comments on commit 1d8a307

Please sign in to comment.