Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions feature_use_tracker/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (C) 2017 Semester.ly Technologies, LLC
#
# Semester.ly is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Semester.ly is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
15 changes: 15 additions & 0 deletions feature_use_tracker/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (C) 2017 Semester.ly Technologies, LLC
#
# Semester.ly is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Semester.ly is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

from django.contrib import admin

# Register your models here.
18 changes: 18 additions & 0 deletions feature_use_tracker/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (C) 2017 Semester.ly Technologies, LLC
#
# Semester.ly is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Semester.ly is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

from django.apps import AppConfig


class FeatureUseTrackerConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'feature_use_tracker'
Empty file.
35 changes: 35 additions & 0 deletions feature_use_tracker/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (C) 2017 Semester.ly Technologies, LLC
#
# Semester.ly is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Semester.ly is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import gettext_lazy as _

class Feature(models.TextChoices):
COMPARE_TIMETABLES = "CT", _("Compare Timetables")
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more?

SIS_ADD_TO_CART = "SATC", _("SIS Add To Cart")
SCREENSHOT = "SS", _("Screenshot")
CUSTOM_EVENT = "CE", _("Custom Event")
DRAG_SEARCH = "DS", _("Custom Event")
EXPORT_TIMETABLE_TO_CALENDAR = "ETTC", _("Export Timetable to Calendar")
FRIENDS = "F", _("Friends")
ADVANCED_SEARCH = "AS", _("Advanced Search")
COURSE_OPTIMIZER = "CO", _("Course Optimizer")


class FeatureUse(models.Model):
"""Database object containing indicators which provide information about whether
a User has used a certain feature or not
"""
user = models.OneToOneField(User, on_delete=models.deletion.CASCADE)
feature_name = models.CharField(max_length=4, choices=Feature)
time_used = models.DateTimeField(auto_now_add=True)
8 changes: 8 additions & 0 deletions feature_use_tracker/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from rest_framework import serializers
from .models import FeatureUse

class FeatureUseSerializer(serializers.ModelSerializer):
class Meta:
model = FeatureUse
fields = ["id", "user", "feature_name", "time_used"]
read_only_fields = ["time_used"]
15 changes: 15 additions & 0 deletions feature_use_tracker/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (C) 2017 Semester.ly Technologies, LLC
#
# Semester.ly is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Semester.ly is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

from django.test import TestCase

# Create your tests here.
7 changes: 7 additions & 0 deletions feature_use_tracker/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.urls import re_path
from .views import FeatureUseView, csrf_cookie_view

urlpatterns = [
re_path(r"^feature_use/csrf/$", csrf_cookie_view, name="feature_use_get_csrf"),
re_path(r"^feature_use/$", FeatureUseView.as_view(), name="feature_use"),
]
46 changes: 46 additions & 0 deletions feature_use_tracker/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (C) 2017 Semester.ly Technologies, LLC
#
# Semester.ly is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Semester.ly is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

from rest_framework.views import APIView
from rest_framework.response import Response
from feature_use_tracker.models import FeatureUse, Feature
from feature_use_tracker.serializers import FeatureUseSerializer


# Create your views here.
class FeatureUseView(APIView):
"""
List relevant feature use entries (for red-dot rendering logic), or create a new entry
"""

def post(self, request):
# drop the 'user' field if client supplies it (we only want to get User through inference)
data = request.data.copy()
data.pop("user", None)

feature = data.get("feature_name")

# delete duplicates if necessary
exists = FeatureUse.objects.filter(user=request.user, feature_name=feature).exists()
if exists:
return Response(status=204)

serializer = FeatureUseSerializer(data=data)
serializer.is_valid(raise_exception=True)
serializer.save(user=request.user)
return Response(serializer.data)


def get(self, request):
rows = FeatureUse.objects.filter(user=request.user)
serializer = FeatureUseSerializer(rows, many=True)
return Response(serializer.data)
1 change: 1 addition & 0 deletions semesterly/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
re_path("", include("notifications.urls")),
re_path("", include("friends.urls")),
re_path("", include("course_history.urls")),
re_path("", include("feature_use.urls"))
re_path(r"admin/?", admin.site.urls),
# Automatic deployment endpoint
re_path(r"deploy_staging/?", semesterly.views.deploy_staging),
Expand Down
Loading