Skip to content

Commit

Permalink
add created_at field for invites #392; add comments stats page for e…
Browse files Browse the repository at this point in the history
…vents #391;  add stats page for events #390
  • Loading branch information
karinakozarova committed May 4, 2019
1 parent caf1db6 commit 8901b34
Show file tree
Hide file tree
Showing 14 changed files with 127 additions and 1 deletion.
1 change: 1 addition & 0 deletions eventmanager/eventmanager/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
'exporting',
'tasks',
'homepage',
'stats',
]

MIDDLEWARE = [
Expand Down
1 change: 1 addition & 0 deletions eventmanager/eventmanager/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('accounts.urls')),
path('events/', include('stats.urls')),
path('', include('exporting.urls')),
path('', include('homepage.urls')),
path('events/', include('events.urls')),
Expand Down
20 changes: 20 additions & 0 deletions eventmanager/events/migrations/0004_invite_created_at.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 2.1.7 on 2019-05-04 14:11

from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
('events', '0003_auto_20190417_1852'),
]

operations = [
migrations.AddField(
model_name='invite',
name='created_at',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now, verbose_name='Created at'),
preserve_default=False,
),
]
5 changes: 5 additions & 0 deletions eventmanager/events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ class Invite(models.Model):
default=False
)

created_at = models.DateTimeField(
verbose_name=_("Created at"),
auto_now_add=True
)

objects = IniviteManager()

def is_invited(user, event):
Expand Down
Empty file added eventmanager/stats/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions eventmanager/stats/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions eventmanager/stats/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class StatsConfig(AppConfig):
name = 'stats'
Empty file.
3 changes: 3 additions & 0 deletions eventmanager/stats/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
24 changes: 24 additions & 0 deletions eventmanager/stats/templates/event_stats.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends 'accounts/base.html' %}

{% load static %}

{% block title %} Event Stats {% endblock %}
{% block head %}
<style type="text/css">
.title{
text-align: center;
}
</style>
{% endblock %}

{% block content %}
<h1 class="title"> Event Stats </h1>

{% if comments_chart %}
<div style="width:600;height:500">
{{ comments_chart|safe }}
</div>
{% endif %}

{% endblock %}

3 changes: 3 additions & 0 deletions eventmanager/stats/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
10 changes: 10 additions & 0 deletions eventmanager/stats/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from . import views

from django.conf.urls import url
from django.contrib.auth import views as auth_views
from django.urls import path


urlpatterns = [
path('<slug:slug>/statistics', views.get_statistics, name='events.statistics'),
]
50 changes: 50 additions & 0 deletions eventmanager/stats/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from django.shortcuts import render

from events.models import Comment
from events.models import Event

import plotly.offline as opy
import plotly.graph_objs as go

import datetime


def get_statistics(request, slug):

event = Event.objects.get(slug=slug)
members = event.team_members.all()

if request.user in members:
event_comments = Comment.objects.filter(event=event)
yesterday = datetime.date.today() - datetime.timedelta(days=1)
alltime_comments = event_comments.count()
daily_comments = event_comments.filter(created_at__gt=yesterday).count()

data = [go.Bar(
x=['Total', 'Daily'],
y=[alltime_comments, daily_comments],
marker=dict(
color=['rgba(50,171,96,1.0)', 'rgba(222,45,38,0.8)'],
line=dict(
color='rgb(8,48,107)',
width=1.5
),
),
textposition = 'auto',
opacity=0.8,
)]

layout=go.Layout(title="Comments compare",font=dict(family='Courier New, monospace', size=20, color='#7f7f7f'))
figure=go.Figure(data=data,layout=layout)
comments_chart = opy.plot(figure, auto_open=False, output_type='div')

context = {
'comments_chart': comments_chart,
}
return render(request, 'event_stats.html', context)
else:
error_message = "Stats are available only\
to team members."
context = {
'error_message': error_message}
return render(request, 'CRUDops/error.html', context)
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ social-auth-app-django==3.1.0
python-social-auth[django]==0.3.6
django-countries==5.3.2
django-import-export
django-tinymce==2.8.0
django-tinymce==2.8.0
plotly==3.8.1

0 comments on commit 8901b34

Please sign in to comment.