Skip to content
Open
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
13 changes: 9 additions & 4 deletions clatoolkit_project/clatoolkit/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from django.db import models, migrations
import django_pgjson.fields
import django.utils.timezone
from django.conf import settings


Expand Down Expand Up @@ -74,12 +75,13 @@ class Migration(migrations.Migration):
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('xapi', django_pgjson.fields.JsonField()),
('platform', models.CharField(max_length=5000)),
('platform_group_id', models.CharField(max_length=100, blank=True)),
('verb', models.CharField(max_length=5000)),
('platformid', models.CharField(max_length=5000, blank=True)),
('platformparentid', models.CharField(max_length=5000, blank=True)),
('parent_user_external', models.CharField(max_length=5000, null=True, blank=True)),
('message', models.TextField(blank=True)),
('datetimestamp', models.DateTimeField(auto_now_add=True, null=True)),
('datetimestamp', models.DateTimeField(default=django.utils.timezone.now)),
('senttolrs', models.CharField(max_length=5000, blank=True)),
('parent_user', models.ForeignKey(related_name='parent_user', to=settings.AUTH_USER_MODEL, null=True)),
],
Expand Down Expand Up @@ -108,11 +110,13 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('platform', models.CharField(max_length=5000)),
('verb', models.CharField(max_length=5000)),
('platform_group_id', models.CharField(max_length=100, blank=True)),
('type', models.CharField(max_length=100, blank=True)),
('verb', models.CharField(max_length=5000, blank=True)),
('to_external_user', models.CharField(max_length=5000, null=True, blank=True)),
('platformid', models.CharField(max_length=5000, blank=True)),
('message', models.TextField()),
('datetimestamp', models.DateTimeField(blank=True)),
('message', models.TextField(blank=True)),
('datetimestamp', models.DateTimeField(null=True)),
('from_user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
('to_user', models.ForeignKey(related_name='to_user', to=settings.AUTH_USER_MODEL, null=True)),
],
Expand Down Expand Up @@ -180,6 +184,7 @@ class Migration(migrations.Migration):
('blog_id', models.CharField(max_length=255, blank=True)),
('github_account_name', models.CharField(max_length=255, blank=True)),
('trello_account_name', models.CharField(max_length=255, blank=True)),
('accounts', django_pgjson.fields.JsonBField(null=True)),
('user', models.OneToOneField(to=settings.AUTH_USER_MODEL)),
],
),
Expand Down
59 changes: 54 additions & 5 deletions clatoolkit_project/clatoolkit/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from django.db import models
from django.contrib.auth.models import User
from django_pgjson.fields import JsonBField
from django.core.exceptions import ValidationError
from django_pgjson.fields import JsonField
from django.core.exceptions import ObjectDoesNotExist
from django.core.exceptions import ObjectDoesNotExist, SuspiciousOperation
from django.http import Http404
from django.utils import timezone
import os


class UserProfile(models.Model):
'''
Custom user for data integration, uses Django's User class.
Expand Down Expand Up @@ -52,6 +57,27 @@ class UserProfile(models.Model):
#Trello user ID
trello_account_name = models.CharField(max_length=255, blank=True)

# JSON field to store plugin accounts in
accounts = JsonBField(null=True)

def add_platform_account(self, platform, identifier):
try:
up = self.from_platform_identifier(platform, identifier)
if up != self:
raise ValidationError("This account has already been registered by another user")

except self.DoesNotExist:
if platform not in self.accounts:
self.accounts[platform] = []
self.accounts[platform].append(identifier)

self.save()

@classmethod
def from_platform_identifier(cls, platform, identifier):
return cls.objects.get(accounts__jcontains={platform: [identifier]})


class UserTrelloCourseBoardMap(models.Model):
user = models.ForeignKey(User)
course_code = models.CharField(max_length=1000, blank=False)
Expand Down Expand Up @@ -199,6 +225,18 @@ def get_required_platforms(self):

return platforms

@classmethod
def from_get(cls, request):
try:
unit_id = request.GET["unit"]
except:
raise SuspiciousOperation("Unit not specified")
try:
unit = cls.objects.get(id=unit_id)
return unit
except cls.DoesNotExist:
raise Http404


class UnitOfferingMembership(models.Model):
user = models.ForeignKey(User)
Expand All @@ -217,6 +255,7 @@ class LearningRecord(models.Model):
xapi = JsonField()
unit = models.ForeignKey(UnitOffering)
platform = models.CharField(max_length=5000, blank=False)
platform_group_id = models.CharField(max_length=100, blank=True)
verb = models.CharField(max_length=5000, blank=False)
user = models.ForeignKey(User)
platformid = models.CharField(max_length=5000, blank=True)
Expand All @@ -225,20 +264,30 @@ class LearningRecord(models.Model):
parent_user = models.ForeignKey(User, null=True, related_name="parent_user")
parent_user_external = models.CharField(max_length=5000, blank=True, null=True)
message = models.TextField(blank=True)
datetimestamp = models.DateTimeField(auto_now_add=True, null=True)
datetimestamp = models.DateTimeField(default=timezone.now)
senttolrs = models.CharField(max_length=5000, blank=True)


class SocialRelationship(models.Model):
unit = models.ForeignKey(UnitOffering)
platform = models.CharField(max_length=5000, blank=False)
verb = models.CharField(max_length=5000, blank=False)
platform_group_id = models.CharField(max_length=255, blank=True)
type = models.CharField(max_length=100, blank=True)
verb = models.CharField(max_length=5000, blank=True)
from_user = models.ForeignKey(User)
to_user = models.ForeignKey(User, null=True, related_name="to_user")
to_external_user = models.CharField(max_length=5000, blank=True, null=True)
platformid = models.CharField(max_length=5000, blank=True)
message = models.TextField(blank=False)
datetimestamp = models.DateTimeField(blank=True)
message = models.TextField(blank=True)
datetimestamp = models.DateTimeField(null=True)

@classmethod
def relationship_exists(cls, **kwargs):
try:
cls.objects.get(**kwargs)
return True
except cls.DoesNotExist:
return False


class CachedContent(models.Model):
Expand Down
14 changes: 13 additions & 1 deletion clatoolkit_project/clatoolkit/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.shortcuts import render, render_to_response
from django.shortcuts import redirect
from django.core.urlresolvers import reverse

from django.contrib.auth import authenticate, login
from django.http import HttpResponseRedirect, HttpResponse, Http404
Expand Down Expand Up @@ -405,7 +406,18 @@ def update_offering(request, unit_id):
else:
form = CreateOfferingForm(instance=unit)

return render(request, "clatoolkit/createoffering.html", {'verb': 'Update', 'form': form})
all_plugins = settings.DATAINTEGRATION_PLUGINS
excluded = ["Blog", "Diigo", "Forum", "GitHub", "Twitter", "YouTube", "facebook", "trello"]

plugins = []
for plugin in all_plugins:
if plugin not in excluded:
plugins.append({
"a": reverse("{}_config".format(plugin)),
"label": "Configure {}".format(plugin)
})

return render(request, "clatoolkit/createoffering.html", {'verb': 'Update', 'form': form, 'unit': unit, "plugins":plugins})
else:
raise PermissionDenied()

Expand Down
87 changes: 46 additions & 41 deletions clatoolkit_project/clatoolkit_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
import inspect

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Expand Down Expand Up @@ -81,22 +82,6 @@

ROOT_URLCONF = 'clatoolkit_project.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'clatoolkit_project.wsgi.application'


Expand Down Expand Up @@ -148,31 +133,6 @@

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/

# web accessible folder
STATIC_ROOT = BASE_DIR #os.path.join(BASE_DIR, 'static')

# URL prefix for static files.
STATIC_URL = '/static/'

STATIC_PATH = os.path.join(BASE_DIR,'static')

# Additional locations of static files
STATICFILES_DIRS = (
# location of your application, should not be public web accessible
STATIC_PATH,
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

AUTH_PROFILE_MODULE = "account.userprofile"

GA_TRACKING_ID = ''
Expand Down Expand Up @@ -200,3 +160,48 @@
DATAINTEGRATION_PLUGINS_INCLUDEDASHBOARD_PLATFORMS = get_includeindashboardwidgets_platforms()
DATAINTEGRATION_PLUGINS = get_plugins()
DATAINTEGRATION_PLUGINS_INCLUDEAUTHOMATIC = get_includeauthomaticplugins_platforms()

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates'), PLUGIN_PATH],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/

# web accessible folder
STATIC_ROOT = BASE_DIR #os.path.join(BASE_DIR, 'static')

# URL prefix for static files.
STATIC_URL = '/static/'

STATIC_PATH = os.path.join(BASE_DIR,'static')

# Additional locations of static files
STATICFILES_DIRS = [
# location of your application, should not be public web accessible
STATIC_PATH,
]

# Include the static dir for plugins so they can define their own assets
for plugin in pluginModules:
dir = os.path.join(PLUGIN_PATH, plugin, "static")
STATICFILES_DIRS.append((plugin, dir),)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
1 change: 1 addition & 0 deletions clatoolkit_project/common/CLRecipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class CLRecipe(object):
PLATFORM_BLOG = 'Blog'
PLATFORM_GITHUB = 'GitHub'
PLATFORM_TRELLO = 'Trello'
PLATFORM_WORDPRESS = "WordPress"

# Verbs
VERB_CREATED = 'created'
Expand Down
17 changes: 17 additions & 0 deletions clatoolkit_project/dashboard/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from django.shortcuts import render
from django.shortcuts import render_to_response
from django.core.urlresolvers import reverse
from django.template import RequestContext
from django.http import HttpResponse
from django.db import connection
from utils import *
from clatoolkit.models import OfflinePlatformAuthToken, UserProfile, OauthFlowTemp, UnitOffering, UnitOfferingMembership, DashboardReflection, LearningRecord, Classification, UserClassification, GroupMap, UserTrelloCourseBoardMap
from dataintegration.models import PlatformConfig
from django.contrib.auth.decorators import login_required
from django.contrib.auth import logout
from functools import wraps
Expand Down Expand Up @@ -177,6 +179,21 @@ def myunits(request):
# Get a users memberships to unit offerings
memberships = UnitOfferingMembership.objects.filter(user=request.user, unit__enabled=True).select_related('unit')

# Get Plugin details
for i in range(0, len(memberships)):
platform_configs = memberships[i].unit.platformconfig_set.all()
if len(platform_configs) > 0:
memberships[i].plugins = []
for config in platform_configs:
platform = config.platform
groups = settings.DATAINTEGRATION_PLUGINS[platform].get_groups(memberships[i].unit)
memberships[i].plugins.append({
"label": platform,
"platform": platform,
"refresh": reverse("{}_refresh".format(platform)),
"groups": groups
})

role = request.user.userprofile.role

show_dashboardnav = False
Expand Down
2 changes: 1 addition & 1 deletion clatoolkit_project/dataintegration/core/plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class DIBasePlugin(object):

config_json_keys = []

def perform_import(self, retrieval_param, course_code):
def perform_import(self, retrieval_param, unit):
"""Called to start the import from api for a plugin.


Expand Down
Loading