def register_existing(request, course_code): unit = UnitOffering.objects.get(code=course_code) if not unit.users.filter(user=request.user).exists(): membership = UnitOfferingMembership(user=request.user, unit=unit, admin=False) membership.save() return redirect("myunits")
def register_existing(request, unit_id): try: unit = UnitOffering.objects.get(id=unit_id) except UnitOffering.DoesNotExist: raise Http404 if not unit.users.filter(id=request.user.id).exists(): membership = UnitOfferingMembership(user=request.user, unit=unit, admin=False) membership.save() return redirect("myunits")
def create_offering(request): # if this is a POST request we need to process the form data if request.method == 'POST': # create a form instance and populate it with data from the request: form = CreateOfferingForm(request.POST) # check whether it's valid: if form.is_valid(): unit = form.save(commit=False) # Get provider ID and set it to unit post_data = request.POST.copy() provider = post_data.pop("provider")[0] app = ClientApp.objects.get(provider=provider) unit.lrs_provider = app # Start & end date start_date = post_data.pop("start_date")[0] end_date = post_data.pop("end_date")[0] from datetime import datetime as dt client_format = '%d / %m / %Y' database_format = '%Y-%m-%d' # Create a Date object start_date = dt.strptime(start_date, client_format) end_date = dt.strptime(end_date, client_format) # Get formatted date string start_date = start_date.strftime(database_format) end_date = end_date.strftime(database_format) # Create a Date object whose format suits database column format start_date = dt.strptime(start_date, database_format) end_date = dt.strptime(end_date, database_format) unit.start_date = start_date unit.end_date = end_date unit.save() m = UnitOfferingMembership(user=request.user, unit=unit, admin=True) m.save() return render(request, 'clatoolkit/createoffering_success.html', { 'verb': 'created', 'unit': unit }) # if a GET (or any other method) we'll create a blank form else: form = CreateOfferingForm(initial={'provider': 'default_lrs'}) return render(request, 'clatoolkit/createoffering.html', { 'verb': 'Create', 'form': form })
def snadashboard(request): context = RequestContext(request) course_code = request.GET.get('course_code') if UnitOfferingMembership.is_admin(request.user, course_code): platform = request.GET.get('platform') title = "SNA Dashboard: %s (Platform: %s)" % (course_code, platform) show_dashboardnav = True posts_timeline = get_timeseries('created', platform, course_code) shares_timeline = get_timeseries('shared', platform, course_code) likes_timeline = get_timeseries('liked', platform, course_code) comments_timeline = get_timeseries('commented', platform, course_code) sna_json = sna_buildjson(platform, course_code, relationshipstoinclude="'mentioned','liked','shared','commented'") #sna_neighbours = getNeighbours(sna_json) centrality = getCentrality(sna_json) context_dict = { 'show_dashboardnav':show_dashboardnav,'course_code':course_code, 'platform':platform, 'title': title, 'sna_json': sna_json, 'posts_timeline': posts_timeline, 'shares_timeline': shares_timeline, 'likes_timeline': likes_timeline, 'comments_timeline': comments_timeline, 'centrality': centrality } return render_to_response('dashboard/snadashboard.html', context_dict, context) else: raise PermissionDenied
def snadashboard(request): context = RequestContext(request) unit_id = request.GET.get('unit') unit = UnitOffering.objects.get(id=unit_id) if UnitOfferingMembership.is_admin(request.user, unit): platform = request.GET.get('platform') title = "SNA Dashboard: {} {} (Platform: {})".format( unit.code, unit.name, platform) # Activity Time line data (verbs and platform) timeline_data = get_verb_timeline_data(unit, platform, None) sna_json = sna_buildjson(platform, unit, relationshipstoinclude = "'%s', '%s', '%s', '%s'" % (xapi_settings.VERB_MENTIONED, xapi_settings.VERB_LIKED, \ xapi_settings.VERB_SHARED, xapi_settings.VERB_COMMENTED)) #sna_neighbours = getNeighbours(sna_json) centrality = get_centrality(sna_json) context_dict = { 'show_dashboardnav': True, 'unit': unit, 'platform': platform, 'title': title, 'sna_json': sna_json, 'centrality': centrality, 'course_id': unit.id, 'posts_timeline': timeline_data['posts'], 'shares_timeline': timeline_data['shares'], 'likes_timeline': timeline_data['likes'], 'comments_timeline': timeline_data['comments'] } return render_to_response('dashboard/snadashboard.html', context_dict, context) # platform = request.GET.get('platform') # title = "SNA Dashboard: {} {} (Platform: {})".format(unit.code, unit.name, platform) # show_dashboardnav = True # posts_timeline = get_timeseries('created', platform, unit) # shares_timeline = get_timeseries('shared', platform, unit) # likes_timeline = get_timeseries('liked', platform, unit) # comments_timeline = get_timeseries('commented', platform, unit) # sna_json = sna_buildjson(platform, unit, relationshipstoinclude="'mentioned','liked','shared','commented'") # #sna_neighbours = getNeighbours(sna_json) # centrality = get_centrality(sna_json) # context_dict = {'show_dashboardnav': show_dashboardnav, 'unit': unit, 'platform': platform, 'title': title, # 'sna_json': sna_json, 'posts_timeline': posts_timeline, 'shares_timeline': shares_timeline, # 'likes_timeline': likes_timeline, 'comments_timeline': comments_timeline, # 'centrality': centrality} # return render_to_response('dashboard/snadashboard.html', context_dict, context) else: raise PermissionDenied
def offering_members(request, course_code): if UnitOfferingMembership.is_admin(request.user, course_code): unit = UnitOffering.objects.get(code=course_code) members = unit.users.all() return render(request, "clatoolkit/offering_members.html", {"unit": unit, "members": members}) else: raise PermissionDenied()
def cadashboard(request): context = RequestContext(request) platform = None no_topics = 3 if request.method == 'POST': unit_id = request.POST['unit'] platform = request.POST['platform'] no_topics = int(request.POST['no_topics']) else: unit_id = request.GET.get('unit') platform = request.GET.get('platform') unit = UnitOffering.objects.get(id=unit_id) if UnitOfferingMembership.is_admin(request.user, unit): title = "Content Analysis Dashboard: %s (Platform: %s)" % (unit.code, platform) # timeline_data = get_verb_timeline_data(unit, None) timeline_data = get_verb_timeline_data(unit, platform, None) # Word Cloud tags = get_wordcloud(platform, unit) # Sentiments pie chart sentiments = getClassifiedCounts(platform, unit, classifier="VaderSentiment") # Community of Inquiry coi = getClassifiedCounts(platform, unit, classifier="NaiveBayes_t1.model") topic_model_output, sentimenttopic_piebubblesdataset = nmf( platform, no_topics, unit, start_date=None, end_date=None) context_dict = { 'show_dashboardnav': True, 'unit': unit, 'platform': platform, 'title': title, 'posts_timeline': timeline_data['posts'], 'shares_timeline': timeline_data['shares'], 'likes_timeline': timeline_data['likes'], 'comments_timeline': timeline_data['comments'], 'sentiments': sentiments, 'coi': coi, 'tags': tags, 'no_topics': no_topics, 'topic_model_output': topic_model_output, 'sentimenttopic_piebubblesdataset': sentimenttopic_piebubblesdataset } return render_to_response('dashboard/cadashboard.html', context_dict, context) else: raise PermissionDenied
def create_offering(request): # if this is a POST request we need to process the form data if request.method == 'POST': # create a form instance and populate it with data from the request: form = CreateOfferingForm(request.POST) # check whether it's valid: if form.is_valid(): unit = form.save(commit=False) # Get provider ID and set it to unit post_data = request.POST.copy() provider = post_data.pop("provider")[0] app = ClientApp.objects.get(provider = provider) unit.lrs_provider = app # Start & end date start_date = post_data.pop("start_date")[0] end_date = post_data.pop("end_date")[0] from datetime import datetime as dt client_format = '%d / %m / %Y' database_format = '%Y-%m-%d' # Create a Date object start_date = dt.strptime(start_date, client_format) end_date = dt.strptime(end_date, client_format) # Get formatted date string start_date = start_date.strftime(database_format) end_date = end_date.strftime(database_format) # Create a Date object whose format suits database column format start_date = dt.strptime(start_date, database_format) end_date = dt.strptime(end_date, database_format) unit.start_date = start_date unit.end_date = end_date unit.save() m = UnitOfferingMembership(user=request.user, unit=unit, admin=True) m.save() return render(request, 'clatoolkit/createoffering_success.html', {'verb': 'created', 'unit': unit}) # if a GET (or any other method) we'll create a blank form else: form = CreateOfferingForm(initial = {'provider': 'default_lrs'}) return render(request, 'clatoolkit/createoffering.html', {'verb': 'Create', 'form': form})
def update_offering(request, unit_id): try: unit = UnitOffering.objects.get(id=unit_id) except UnitOffering.DoesNotExist: raise Http404 if UnitOfferingMembership.is_admin(request.user, unit): if request.method == "POST": form = CreateOfferingForm(request.POST, instance=unit) if form.is_valid(): # Get provider ID and set it to unit post_data = request.POST.copy() provider = post_data.pop("provider")[0] app = ClientApp.objects.get(provider=provider) unit.lrs_provider = app # Start & end date start_date = post_data.pop("start_date")[0] end_date = post_data.pop("end_date")[0] from datetime import datetime as dt client_format = '%d / %m / %Y' database_format = '%Y-%m-%d' # Create a Date object start_date = dt.strptime(start_date, client_format) end_date = dt.strptime(end_date, client_format) # Get formatted date string start_date = start_date.strftime(database_format) end_date = end_date.strftime(database_format) # Create a Date object whose format suits database column format start_date = dt.strptime(start_date, database_format) end_date = dt.strptime(end_date, database_format) unit.start_date = start_date unit.end_date = end_date unit = form.save() return render(request, 'clatoolkit/createoffering_success.html', { 'verb': 'updated', 'unit': unit }) else: # Get LRS provider and set it form = CreateOfferingForm( instance=unit, initial={'provider': unit.lrs_provider.provider}) return render(request, "clatoolkit/createoffering.html", { 'verb': 'Update', 'form': form }) else: raise PermissionDenied()
def create_offering(request): # if this is a POST request we need to process the form data if request.method == 'POST': # create a form instance and populate it with data from the request: form = CreateOfferingForm(request.POST) # check whether it's valid: if form.is_valid(): unit = form.save(commit=False) unit.save() m = UnitOfferingMembership(user=request.user, unit=unit, admin=True) m.save() return render(request, 'clatoolkit/createoffering_success.html', {'verb': 'created', 'unit': unit}) # if a GET (or any other method) we'll create a blank form else: form = CreateOfferingForm() return render(request, 'clatoolkit/createoffering.html', {'verb': 'Create', 'form': form})
def offering_members(request, unit_id): try: unit = UnitOffering.objects.get(id=unit_id) except UnitOffering.DoesNotExist: raise Http404 if UnitOfferingMembership.is_admin(request.user, unit): members = unit.users.all() return render(request, "clatoolkit/offering_members.html", {"unit": unit, "members": members}) else: raise PermissionDenied()
def offering_members(request, unit_id): try: unit = UnitOffering.objects.get(id=unit_id) except UnitOffering.DoesNotExist: raise Http404 if UnitOfferingMembership.is_admin(request.user, unit): members = unit.users.all() return render(request, "clatoolkit/offering_members.html", { "unit": unit, "members": members }) else: raise PermissionDenied()
def update_offering(request, course_code): if UnitOfferingMembership.is_admin(request.user, course_code): unit = UnitOffering.objects.get(code=course_code) if request.method == "POST": form = CreateOfferingForm(request.POST, instance=unit) if form.is_valid(): unit = form.save() return render(request, 'clatoolkit/createoffering_success.html', {'verb': 'updated', 'unit': unit}) else: form = CreateOfferingForm(instance=unit) return render(request, "clatoolkit/createoffering.html", {'verb': 'Update', 'form': form}) else: raise PermissionDenied()
def update_offering(request, unit_id): try: unit = UnitOffering.objects.get(id=unit_id) except UnitOffering.DoesNotExist: raise Http404 if UnitOfferingMembership.is_admin(request.user, unit): if request.method == "POST": form = CreateOfferingForm(request.POST, instance=unit) if form.is_valid(): # Get provider ID and set it to unit post_data = request.POST.copy() provider = post_data.pop("provider")[0] app = ClientApp.objects.get(provider = provider) unit.lrs_provider = app # Start & end date start_date = post_data.pop("start_date")[0] end_date = post_data.pop("end_date")[0] from datetime import datetime as dt client_format = '%d / %m / %Y' database_format = '%Y-%m-%d' # Create a Date object start_date = dt.strptime(start_date, client_format) end_date = dt.strptime(end_date, client_format) # Get formatted date string start_date = start_date.strftime(database_format) end_date = end_date.strftime(database_format) # Create a Date object whose format suits database column format start_date = dt.strptime(start_date, database_format) end_date = dt.strptime(end_date, database_format) unit.start_date = start_date unit.end_date = end_date unit = form.save() return render(request, 'clatoolkit/createoffering_success.html', {'verb': 'updated', 'unit': unit}) else: # Get LRS provider and set it form = CreateOfferingForm(instance=unit, initial = {'provider': unit.lrs_provider.provider}) return render(request, "clatoolkit/createoffering.html", {'verb': 'Update', 'form': form}) else: raise PermissionDenied()
def cadashboard(request): context = RequestContext(request) course_code = None platform = None no_topics = 3 if request.method == 'POST': course_code = request.POST['course_code'] platform = request.POST['platform'] no_topics = int(request.POST['no_topics']) else: course_code = request.GET.get('course_code') platform = request.GET.get('platform') if UnitOfferingMembership.is_admin(request.user, course_code): title = "Content Analysis Dashboard: %s (Platform: %s)" % (course_code, platform) show_dashboardnav = True posts_timeline = get_timeseries('created', platform, course_code) shares_timeline = get_timeseries('shared', platform, course_code) likes_timeline = get_timeseries('liked', platform, course_code) comments_timeline = get_timeseries('commented', platform, course_code) tags = get_wordcloud(platform, course_code) sentiments = getClassifiedCounts(platform, course_code, classifier="VaderSentiment") coi = getClassifiedCounts(platform, course_code, classifier="NaiveBayes_t1.model") topic_model_output, sentimenttopic_piebubblesdataset = nmf(platform, no_topics, course_code, start_date=None, end_date=None) context_dict = {'show_dashboardnav':show_dashboardnav, 'course_code':course_code, 'platform':platform, 'title': title, 'course_code':course_code, 'platform':platform, 'sentiments': sentiments, 'coi': coi, 'tags': tags, 'posts_timeline': posts_timeline, 'shares_timeline': shares_timeline, 'likes_timeline': likes_timeline, 'comments_timeline': comments_timeline, 'no_topics': no_topics, 'topic_model_output': topic_model_output, 'sentimenttopic_piebubblesdataset':sentimenttopic_piebubblesdataset } return render_to_response('dashboard/cadashboard.html', context_dict, context) else: raise PermissionDenied
def register(request, course_code): # Like before, get the request's context. context = RequestContext(request) # A boolean value for telling the template whether the registration was successful. # Set to False initially. Code changes value to True when registration succeeds. registered = False unit = UnitOffering.objects.get(code=course_code) platforms = unit.get_required_platforms() u = None if request.user.is_authenticated(): u = request.user # If it's a HTTP POST, we're interested in processing form data. if request.method == 'POST': # Attempt to grab information from the raw form information. # Note that we make use of both UserForm and UserProfileForm. user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) # If the two forms are valid... if user_form.is_valid() and profile_form.is_valid(): # Save the user's form data to the database. user = user_form.save() # Now we hash the password with the set_password method. # Once hashed, we can update the user object. user.set_password(user.password) user.save() m = UnitOfferingMembership(user=user, unit=unit, admin=False) m.save() # Now sort out the UserProfile instance. # Since we need to set the user attribute ourselves, we set commit=False. # This delays saving the model until we're ready to avoid integrity problems. profile = profile_form.save(commit=False) profile.user = user profile.role = "Student" # Now we save the UserProfile model instance. profile.save() # Log in as the newly signed up user u = authenticate(username=user_form.cleaned_data["username"], password=user_form.cleaned_data["password"]) login(request, u) return HttpResponseRedirect("/") # Not a HTTP POST, so we render our form using two ModelForm instances. # These forms will be blank, ready for user input. else: user_form = UserForm() profile_form = UserProfileForm() # Render the template depending on the context. return render_to_response( 'clatoolkit/register.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered, "course": unit, "req_platforms": platforms, "user": u}, context)
def dashboard(request): context = RequestContext(request) unit_id = request.GET.get('unit') unit = UnitOffering.objects.get(id=unit_id) # If the user is an admin for the course if UnitOfferingMembership.is_admin(request.user, unit): # user = request.user platform = request.GET.get('platform') title = "Activity Dashboard: %s (Platform: %s)" % (unit.code, platform) show_dashboardnav = True # A flag for showing a platform activity time series and pie chart show_allplatforms_widgets = True if platform != "all": show_allplatforms_widgets = False activity_pie_series = get_verb_pie_data(unit, platform=platform) platformactivity_pie_series = get_platform_pie_data(unit) # Activity Time line data (verbs and platform) timeline_data = get_verb_timeline_data(unit, platform, None) platform_timeline_data = get_platform_timeline_data( unit, platform, None) # p = platform if platform != "all" else None activememberstable = get_active_members_table(unit, platform) topcontenttable = get_cached_top_content(platform, unit) context_dict = { 'title': title, 'course_code': unit.code, 'platform': platform, 'show_dashboardnav': show_dashboardnav, 'activememberstable': activememberstable, 'unit': unit, 'topcontenttable': topcontenttable, 'show_allplatforms_widgets': show_allplatforms_widgets, 'posts_timeline': timeline_data['posts'], 'shares_timeline': timeline_data['shares'], 'likes_timeline': timeline_data['likes'], 'comments_timeline': timeline_data['comments'], 'twitter_timeline': platform_timeline_data[xapi_settings.PLATFORM_TWITTER], 'facebook_timeline': platform_timeline_data[xapi_settings.PLATFORM_FACEBOOK], 'youtube_timeline': platform_timeline_data[xapi_settings.PLATFORM_YOUTUBE], 'blog_timeline': platform_timeline_data[xapi_settings.PLATFORM_BLOG], 'trello_timeline': platform_timeline_data[xapi_settings.PLATFORM_TRELLO], 'github_timeline': platform_timeline_data[xapi_settings.PLATFORM_GITHUB], 'forum_timeline': [], 'diigo_timeline': [], 'activity_pie_series': activity_pie_series, 'platformactivity_pie_series': platformactivity_pie_series } return render_to_response('dashboard/dashboard.html', context_dict, context) else: raise PermissionDenied
def register(request, unit_id): import requests # Like before, get the request's context. context = RequestContext(request) # A boolean value for telling the template whether the registration was successful. # Set to False initially. Code changes value to True when registration succeeds. registered = False try: unit = UnitOffering.objects.get(id=unit_id) except UnitOffering.DoesNotExist: raise Http404 platforms = unit.get_required_platforms() u = None if request.user.is_authenticated(): u = request.user # If it's a HTTP POST, we're interested in processing form data. if request.method == 'POST': # Attempt to grab information from the raw form information. # Note that we make use of both UserForm and UserProfileForm. user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) # If the two forms are valid... if user_form.is_valid() and profile_form.is_valid(): # Generate LRS Account user = user_form.cleaned_data['username'] email = user_form.cleaned_data['email'] lrs = unit.get_lrs() # Create a signature to authorise lrs account creation. # We don't want randoms creating accounts arbitrarly! hash = hmac.new(str(lrs.get_secret()), lrs.get_key(), sha1) # Return ascii formatted signature in base64 signature = binascii.b2a_base64(hash.digest())[:-1] payload = { "user": user, "mailbox": email, "client": lrs.app_name, "signature": signature } # TODO: Remove hardwired url (probs from client app model?) # print lrs.get_reg_lrs_account_url() r = requests.post(lrs.get_reg_lrs_account_url(), data=payload) if not (str(r.status_code) == '200' and r.content == 'success'): print 'Error: LRS account could not be created.' return HttpResponse(r.content) ### When an LRS account has been created, create the toolkit account. # Save the user's form data to the database. user = user_form.save() # Now we hash the password with the set_password method. # Once hashed, we can update the user object. user.set_password(user.password) user.save() m = UnitOfferingMembership(user=user, unit=unit, admin=False) m.save() # Now sort out the UserProfile instance. # Since we need to set the user attribute ourselves, we set commit=False. # This delays saving the model until we're ready to avoid integrity problems. profile = profile_form.save(commit=False) profile.user = user profile.role = "Student" # Now we save the UserProfile model instance. profile.save() # Log in as the newly signed up user u = authenticate(username=user_form.cleaned_data["username"], password=user_form.cleaned_data["password"]) login(request, u) return HttpResponseRedirect("/") # Not a HTTP POST, so we render our form using two ModelForm instances. # These forms will be blank, ready for user input. else: user_form = UserForm() profile_form = UserProfileForm() # Render the template depending on the context. return render_to_response( 'clatoolkit/register.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered, "course": unit, "req_platforms": platforms, "user": u}, context)
def register(request, unit_id): import requests # Like before, get the request's context. context = RequestContext(request) # A boolean value for telling the template whether the registration was successful. # Set to False initially. Code changes value to True when registration succeeds. registered = False try: unit = UnitOffering.objects.get(id=unit_id) except UnitOffering.DoesNotExist: raise Http404 platforms = unit.get_required_platforms() u = None if request.user.is_authenticated(): u = request.user # If it's a HTTP POST, we're interested in processing form data. if request.method == 'POST': # Attempt to grab information from the raw form information. # Note that we make use of both UserForm and UserProfileForm. user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) # If the two forms are valid... if user_form.is_valid() and profile_form.is_valid(): # Generate LRS Account user = user_form.cleaned_data['username'] email = user_form.cleaned_data['email'] lrs = unit.get_lrs() # Create a signature to authorise lrs account creation. # We don't want randoms creating accounts arbitrarly! hash = hmac.new(str(lrs.get_secret()), lrs.get_key(), sha1) # Return ascii formatted signature in base64 signature = binascii.b2a_base64(hash.digest())[:-1] payload = { "user": user, "mailbox": email, "client": lrs.app_name, "signature": signature } # TODO: Remove hardwired url (probs from client app model?) # print lrs.get_reg_lrs_account_url() r = requests.post(lrs.get_reg_lrs_account_url(), data=payload) if not (str(r.status_code) == '200' and r.content == 'success'): print 'Error: LRS account could not be created.' return HttpResponse(r.content) ### When an LRS account has been created, create the toolkit account. # Save the user's form data to the database. user = user_form.save() # Now we hash the password with the set_password method. # Once hashed, we can update the user object. user.set_password(user.password) user.save() m = UnitOfferingMembership(user=user, unit=unit, admin=False) m.save() # Now sort out the UserProfile instance. # Since we need to set the user attribute ourselves, we set commit=False. # This delays saving the model until we're ready to avoid integrity problems. profile = profile_form.save(commit=False) profile.user = user profile.role = "Student" # Now we save the UserProfile model instance. profile.save() # Log in as the newly signed up user u = authenticate(username=user_form.cleaned_data["username"], password=user_form.cleaned_data["password"]) login(request, u) return HttpResponseRedirect("/") # Not a HTTP POST, so we render our form using two ModelForm instances. # These forms will be blank, ready for user input. else: user_form = UserForm() profile_form = UserProfileForm() # Render the template depending on the context. return render_to_response( 'clatoolkit/register.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered, "course": unit, "req_platforms": platforms, "user": u }, context)
def dashboard(request): context = RequestContext(request) course_code = request.GET.get('course_code') # If the user is an admin for the course if UnitOfferingMembership.is_admin(request.user, course_code): platform = request.GET.get('platform') title = "Activity Dashboard: %s (Platform: %s)" % (course_code, platform) show_dashboardnav = True profiling = "" profiling = profiling + "| Verb Timelines %s" % (str(datetime.datetime.now())) posts_timeline = get_timeseries('created', platform, course_code) shares_timeline = get_timeseries('shared', platform, course_code) likes_timeline = get_timeseries('liked', platform, course_code) comments_timeline = get_timeseries('commented', platform, course_code) show_allplatforms_widgets = False twitter_timeline = "" facebook_timeline = "" forum_timeline = "" youtube_timeline = "" diigo_timeline = "" blog_timeline = "" github_timeline = "" trello_timeline = "" profiling = profiling + "| Platform Timelines %s" % (str(datetime.datetime.now())) platformclause = "" #TODO: This will need to change upon implementation of teaching periods if platform != "all": platformclause = " AND clatoolkit_learningrecord.xapi->'context'->>'platform'='%s'" % (platform) else: twitter_timeline = get_timeseries_byplatform("Twitter", course_code) facebook_timeline = get_timeseries_byplatform("Facebook", course_code) forum_timeline = get_timeseries_byplatform("Forum", course_code) youtube_timeline = get_timeseries_byplatform("YouTube", course_code) diigo_timeline = get_timeseries_byplatform("Diigo", course_code) blog_timeline = get_timeseries_byplatform("Blog", course_code) github_timeline = get_timeseries_byplatform("GitHub", course_code) trello_timeline = get_timeseries_byplatform("trello", course_code) show_allplatforms_widgets = True profiling = profiling + "| Pies %s" % (str(datetime.datetime.now())) cursor = connection.cursor() cursor.execute("""SELECT clatoolkit_learningrecord.xapi->'verb'->'display'->>'en-US' as verb, count(clatoolkit_learningrecord.xapi->'verb'->'display'->>'en-US') as counts FROM clatoolkit_learningrecord WHERE clatoolkit_learningrecord.course_code='%s' %s GROUP BY clatoolkit_learningrecord.xapi->'verb'->'display'->>'en-US'; """ % (course_code, platformclause)) result = cursor.fetchall() activity_pie_series = "" for row in result: activity_pie_series = activity_pie_series + "['%s', %s]," % (row[0],row[1]) cursor = connection.cursor() cursor.execute("""SELECT clatoolkit_learningrecord.xapi->'context'->>'platform' as platform, count(clatoolkit_learningrecord.xapi->'verb'->'display'->>'en-US') as counts FROM clatoolkit_learningrecord WHERE clatoolkit_learningrecord.course_code='%s' GROUP BY clatoolkit_learningrecord.xapi->'context'->>'platform'; """ % (course_code)) result = cursor.fetchall() platformactivity_pie_series = "" for row in result: platformactivity_pie_series = platformactivity_pie_series + "['%s', %s]," % (row[0],row[1]) #active members table profiling = profiling + "| Active Members %s" % (str(datetime.datetime.now())) activememberstable = get_active_members_table(platform, course_code) #get_cached_active_users(platform, course_code) profiling = profiling + "| Top Content %s" % (str(datetime.datetime.now())) topcontenttable = get_cached_top_content(platform, course_code) #get_top_content_table(platform, course_code) profiling = profiling + "| End Top Content %s" % (str(datetime.datetime.now())) context_dict = {'profiling': profiling, 'show_dashboardnav':show_dashboardnav, 'course_code':course_code, 'platform':platform, 'twitter_timeline': twitter_timeline, 'facebook_timeline': facebook_timeline, 'forum_timeline': forum_timeline, 'youtube_timeline':youtube_timeline, 'diigo_timeline':diigo_timeline, 'blog_timeline':blog_timeline, 'github_timeline': github_timeline, 'trello_timeline': trello_timeline, 'show_allplatforms_widgets': show_allplatforms_widgets, 'platformactivity_pie_series': platformactivity_pie_series, 'title': title, 'activememberstable': activememberstable, 'topcontenttable': topcontenttable, 'activity_pie_series': activity_pie_series, 'posts_timeline': posts_timeline, 'shares_timeline': shares_timeline, 'likes_timeline': likes_timeline, 'comments_timeline': comments_timeline } return render_to_response('dashboard/dashboard.html', context_dict, context) else: raise PermissionDenied