Skip to content

Commit

Permalink
Activity stream for logins closes #5
Browse files Browse the repository at this point in the history
  • Loading branch information
Conrad Kroone authored and Conrad Kroone committed Aug 28, 2016
1 parent 0ef3ee7 commit fb5de1b
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 51 deletions.
2 changes: 2 additions & 0 deletions bugheist/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TESTING = False

SITE_ID = 1
# Application definition
Expand Down Expand Up @@ -146,3 +147,4 @@
# https://warehouse.python.org/project/whitenoise/
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

LOGIN_REDIRECT_URL = "/"
4 changes: 2 additions & 2 deletions bugheist/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
url(r'^$', website.views.index, name='index'),
url(r'^admin/', include(admin.site.urls)),
url(r'^issue/', login_required(IssueCreate.as_view()), name="issue"),
url(r'^accounts/profile/(?P<slug>[^/]+)/$', UserProfileDetailView.as_view(), name="profile"),
url(r'^profile/(?P<slug>[^/]+)/$', UserProfileDetailView.as_view(), name="profile"),
url(r'^accounts/profile/', website.views.profile),
url(r'^accounts/', include('allauth.urls')),
url('^activity/', include('actstream.urls')),
url(r'^activity/', include('actstream.urls')),
]
10 changes: 10 additions & 0 deletions website/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from django.db import models
from django.contrib.auth.models import User
from django.conf import settings
from allauth.account.signals import user_signed_up, user_logged_in
from actstream import action
from django.dispatch import receiver

class Issue(models.Model):
user = models.ForeignKey(User)
Expand All @@ -8,3 +12,9 @@ class Issue(models.Model):
screenshot = models.ImageField(null=True, blank=True)
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)


@receiver(user_logged_in, dispatch_uid="some.unique.string.id.for.allauth.user_logged_in")
def user_logged_in_(request, user, **kwargs):
if not settings.TESTING:
action.send(user, verb='logged in')
87 changes: 42 additions & 45 deletions website/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
{% if user.is_authenticated %}
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-user fa-fw"></i> <i class="fa fa-caret-down"></i>
<i class="fa fa-user fa-fw"></i>{{user.username}} (20pts) <i class="fa fa-caret-down"></i>
</a>
<ul class="dropdown-menu dropdown-user">
<li><a href="/accounts/profile/"><i class="fa fa-user fa-fw"></i> User Profile</a>
Expand Down Expand Up @@ -278,51 +278,37 @@ <h1 class="page-header">Activity</h1>
<!-- /.panel-heading -->
<div class="panel-body">
<div class="list-group">
<a href="#" class="list-group-item">
<i class="fa fa-comment fa-fw"></i> Amazon.com All of the buttons are the wrong size. See screenshot for more details.
<span class="pull-right text-muted small"><em>Found 1 day ago</em>
{% for activity in activities %}
<div class="list-group-item">
{% if activity.verb == "logged in" %}
<i class="fa fa-sign-in fa-fw"></i>
{% endif %}
{% if activity.actor.get_absolute_url %}
<a href="{{ activity.actor.get_absolute_url }}">{{ activity.actor }}</a>
{% else %}
<a href="{{ activity.actor_url }}">{{ activity.actor }}</a>
{% endif %}
{{ activity.verb }}
{% if activity.action_object %}
{% if activity.action_object.get_absolute_url %}
<a href="{{ activity.action_object.get_absolute_url }}">{{ activity.action_object }}</a>
{% else %}
<a href="{{ activity.action_object_url }}">{{ activity.action_object }}</a>
{% endif %}
{% endif %}
{% if activity.action_object and activity.target %}to{% endif %}
{% if activity.target %}
{% if activity.target.get_absolute_url %}
<a href="{{ activity.target.get_absolute_url }}">{{ activity.target }}</a>
{% else %}
<a href="{{ activity.target_url }}">{{ activity.target }}</a>
{% endif %}
{% endif %}
<span class="pull-right text-muted small"><em>{{ activity.timestamp|timesince }} ago</em>
</span>
</a>
<a href="#" class="list-group-item">
<i class="fa fa-twitter fa-fw"></i> 3 New Followers
<span class="pull-right text-muted small"><em>12 minutes ago</em>
</span>
</a>
<a href="#" class="list-group-item">
<i class="fa fa-envelope fa-fw"></i> Message Sent
<span class="pull-right text-muted small"><em>27 minutes ago</em>
</span>
</a>
<a href="#" class="list-group-item">
<i class="fa fa-tasks fa-fw"></i> New Task
<span class="pull-right text-muted small"><em>43 minutes ago</em>
</span>
</a>
<a href="#" class="list-group-item">
<i class="fa fa-upload fa-fw"></i> Server Rebooted
<span class="pull-right text-muted small"><em>11:32 AM</em>
</span>
</a>
<a href="#" class="list-group-item">
<i class="fa fa-bolt fa-fw"></i> Server Crashed!
<span class="pull-right text-muted small"><em>11:13 AM</em>
</span>
</a>
<a href="#" class="list-group-item">
<i class="fa fa-warning fa-fw"></i> Server Not Responding
<span class="pull-right text-muted small"><em>10:57 AM</em>
</span>
</a>
<a href="#" class="list-group-item">
<i class="fa fa-shopping-cart fa-fw"></i> New Order Placed
<span class="pull-right text-muted small"><em>9:49 AM</em>
</span>
</a>
<a href="#" class="list-group-item">
<i class="fa fa-money fa-fw"></i> Payment Received
<span class="pull-right text-muted small"><em>Yesterday</em>
</span>
</a>
</div>
{% endfor %}

</div>
<!-- /.list-group -->
<a href="#" class="btn btn-default btn-block">View All Activity</a>
Expand All @@ -339,6 +325,17 @@ <h1 class="page-header">Activity</h1>
</div>
<!-- /#wrapper -->

<!-- jQuery -->
<script src="{% static "vendor/jquery/jquery.min.js" %}"></script>

<!-- Bootstrap Core JavaScript -->
<script src="{% static "vendor/bootstrap/js/bootstrap.min.js" %}"></script>

<!-- Metis Menu Plugin JavaScript -->
<script src="{% static "vendor/metisMenu/metisMenu.min.js" %}"></script>



</body>

</html>
16 changes: 12 additions & 4 deletions website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@
from django.views.generic.edit import CreateView
from website.models import Issue
from django.contrib.auth import get_user_model
from django.shortcuts import redirect
from django.shortcuts import redirect, render_to_response, RequestContext
from django.http import HttpResponseRedirect
from django.contrib import messages
from django.http import Http404
from actstream.models import Action, user_stream

def index(request, template="index.html"):
activities = Action.objects.all()[0:10]
context = {
'activities': activities,
}
return render_to_response(template, context, context_instance=RequestContext(request))


def index(request):
return render(request, 'index.html')

class IssueCreate(CreateView):
model = Issue
Expand All @@ -26,7 +34,7 @@ def form_valid(self, form):

def profile(request):
try:
return redirect('/accounts/profile/' + request.user.username)
return redirect('/profile/' + request.user.username)
except Exception:
return redirect('/')

Expand Down

0 comments on commit fb5de1b

Please sign in to comment.