From 1d479a32a3da3a8676a69eac0b80d8d5b018117d Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Thu, 6 Sep 2018 18:38:13 +0530 Subject: [PATCH 01/24] etherpad initialized --- etherpad/__init__.py | 0 etherpad/admin.py | 3 +++ etherpad/apps.py | 5 +++++ etherpad/migrations/__init__.py | 0 etherpad/models.py | 3 +++ etherpad/tests.py | 3 +++ etherpad/views.py | 3 +++ 7 files changed, 17 insertions(+) create mode 100644 etherpad/__init__.py create mode 100644 etherpad/admin.py create mode 100644 etherpad/apps.py create mode 100644 etherpad/migrations/__init__.py create mode 100644 etherpad/models.py create mode 100644 etherpad/tests.py create mode 100644 etherpad/views.py diff --git a/etherpad/__init__.py b/etherpad/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/etherpad/admin.py b/etherpad/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/etherpad/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/etherpad/apps.py b/etherpad/apps.py new file mode 100644 index 00000000..796b0654 --- /dev/null +++ b/etherpad/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class EtherpadConfig(AppConfig): + name = 'etherpad' diff --git a/etherpad/migrations/__init__.py b/etherpad/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/etherpad/models.py b/etherpad/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/etherpad/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/etherpad/tests.py b/etherpad/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/etherpad/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/etherpad/views.py b/etherpad/views.py new file mode 100644 index 00000000..91ea44a2 --- /dev/null +++ b/etherpad/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. From f3e80e919766fd31480272267434d7a09477d46e Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Thu, 6 Sep 2018 19:14:05 +0530 Subject: [PATCH 02/24] etherpad models added --- CollaborationSystem/settings.py | 1 + etherpad/migrations/0001_initial.py | 54 +++++++++++++++++++++++++++++ etherpad/models.py | 20 ++++++++++- 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 etherpad/migrations/0001_initial.py diff --git a/CollaborationSystem/settings.py b/CollaborationSystem/settings.py index bc62c4cc..0551ad59 100644 --- a/CollaborationSystem/settings.py +++ b/CollaborationSystem/settings.py @@ -78,6 +78,7 @@ 'wiki.plugins.images.apps.ImagesConfig', 'wiki.plugins.macros.apps.MacrosConfig', 'Recommendation_API', + 'etherpad', ] + get_machina_apps() SITE_ID = 1 diff --git a/etherpad/migrations/0001_initial.py b/etherpad/migrations/0001_initial.py new file mode 100644 index 00000000..e8dc846d --- /dev/null +++ b/etherpad/migrations/0001_initial.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.7 on 2018-09-06 13:43 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('BasicArticle', '0020_merge_20180627_1228'), + ('Group', '0013_groupinvitations'), + ('Community', '0024_auto_20180614_0125'), + ] + + operations = [ + migrations.CreateModel( + name='EtherArticle', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('article_ether_id', models.TextField()), + ('article', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ether_article', to='BasicArticle.Articles')), + ], + ), + migrations.CreateModel( + name='EtherCommunity', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('community_ether_id', models.TextField()), + ('community', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ether_community', to='Community.Community')), + ], + ), + migrations.CreateModel( + name='EtherGroup', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('group_ether_id', models.TextField()), + ('group', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ether_group', to='Group.Group')), + ], + ), + migrations.CreateModel( + name='EtherUser', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('user_ether_id', models.TextField()), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ether_user', to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/etherpad/models.py b/etherpad/models.py index 71a83623..33244251 100644 --- a/etherpad/models.py +++ b/etherpad/models.py @@ -1,3 +1,21 @@ from django.db import models +from Community.models import Community +from Group.models import Group +from BasicArticle.models import Articles +from django.contrib.auth.models import User -# Create your models here. +class EtherCommunity(models.Model): + community = models.ForeignKey(Community, related_name='ether_community') + community_ether_id = models.TextField() + +class EtherGroup(models.Model): + group = models.ForeignKey(Group, related_name='ether_group') + group_ether_id = models.TextField() + +class EtherArticle(models.Model): + article = models.ForeignKey(Articles, related_name='ether_article') + article_ether_id = models.TextField() + +class EtherUser(models.Model): + user = models.ForeignKey(User, related_name='ether_user') + user_ether_id = models.TextField() From 75a3e0451a34f237b25feb781f42584b1969d84e Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Thu, 6 Sep 2018 19:29:05 +0530 Subject: [PATCH 03/24] create ether pad id for community --- etherpad/views.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/etherpad/views.py b/etherpad/views.py index 91ea44a2..4826d217 100644 --- a/etherpad/views.py +++ b/etherpad/views.py @@ -1,3 +1,11 @@ from django.shortcuts import render +from py_etherpad import EtherpadLiteClient +from django.conf import settings +from .models import EtherCommunity + +def create_community_ether(community): + epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) + result = epclient.createGroupIfNotExistsFor(community.id) + EtherCommunity.objects.create(community=community, community_ether_id=result['groupID']) + return -# Create your views here. From 644f54f78e028a32893a3af966b71fd264d0d429 Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Thu, 6 Sep 2018 19:39:44 +0530 Subject: [PATCH 04/24] create ether pad id for group --- etherpad/views.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/etherpad/views.py b/etherpad/views.py index 4826d217..9974b941 100644 --- a/etherpad/views.py +++ b/etherpad/views.py @@ -1,7 +1,7 @@ from django.shortcuts import render from py_etherpad import EtherpadLiteClient from django.conf import settings -from .models import EtherCommunity +from .models import EtherCommunity, EtherGroup def create_community_ether(community): epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) @@ -9,3 +9,10 @@ def create_community_ether(community): EtherCommunity.objects.create(community=community, community_ether_id=result['groupID']) return + +def create_group_ether(community_id, group): + epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) + group_id = str(community_id) + str(group) + result = epclient.createGroupIfNotExistsFor(group_id) + EtherGroup.objects.create(group=group, group_ether_id=result['groupID']) + return \ No newline at end of file From 9ecdce5f741dd211b661dd26f30ec0447da64b72 Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Thu, 6 Sep 2018 20:15:49 +0530 Subject: [PATCH 05/24] create ether pad for article in community --- etherpad/views.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/etherpad/views.py b/etherpad/views.py index 9974b941..c2e93eb6 100644 --- a/etherpad/views.py +++ b/etherpad/views.py @@ -1,7 +1,7 @@ from django.shortcuts import render from py_etherpad import EtherpadLiteClient from django.conf import settings -from .models import EtherCommunity, EtherGroup +from .models import EtherCommunity, EtherGroup, EtherArticle, EtherUser def create_community_ether(community): epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) @@ -15,4 +15,11 @@ def create_group_ether(community_id, group): group_id = str(community_id) + str(group) result = epclient.createGroupIfNotExistsFor(group_id) EtherGroup.objects.create(group=group, group_ether_id=result['groupID']) - return \ No newline at end of file + return + +def create_article_ether_community(community_id, article): + epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) + community = EtherCommunity.objects.get(community=community_id) + result = epclient.createGroupPad(community.community_ether_id, article.id) + EtherArticle.objects.create(article=article, article_ether_id=result['padID']) + \ No newline at end of file From 7a2da135a671c6ca8bb1b2e612383ca197f1c1da Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Thu, 6 Sep 2018 20:32:36 +0530 Subject: [PATCH 06/24] create ether pad for group --- etherpad/views.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/etherpad/views.py b/etherpad/views.py index c2e93eb6..bb180fce 100644 --- a/etherpad/views.py +++ b/etherpad/views.py @@ -10,9 +10,9 @@ def create_community_ether(community): return -def create_group_ether(community_id, group): +def create_group_ether(group): epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) - group_id = str(community_id) + str(group) + group_id = 'group' + str(group.id) result = epclient.createGroupIfNotExistsFor(group_id) EtherGroup.objects.create(group=group, group_ether_id=result['groupID']) return @@ -22,4 +22,11 @@ def create_article_ether_community(community_id, article): community = EtherCommunity.objects.get(community=community_id) result = epclient.createGroupPad(community.community_ether_id, article.id) EtherArticle.objects.create(article=article, article_ether_id=result['padID']) - \ No newline at end of file + return + +def create_article_ether_group(group_id, article): + epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) + group = EtherGroup.objects.get(group=group_id) + result = epclient.createGroupPad(group.group_ether_id, article.id) + EtherArticle.objects.create(article=article, article_ether_id=result['padID']) + return From 0eff488beca5b1bdcc7850976b7d3555f1683adf Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Thu, 6 Sep 2018 20:37:29 +0530 Subject: [PATCH 07/24] create ether pad if for user --- etherpad/views.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/etherpad/views.py b/etherpad/views.py index bb180fce..c161627a 100644 --- a/etherpad/views.py +++ b/etherpad/views.py @@ -30,3 +30,9 @@ def create_article_ether_group(group_id, article): result = epclient.createGroupPad(group.group_ether_id, article.id) EtherArticle.objects.create(article=article, article_ether_id=result['padID']) return + +def create_ether_user(user): + epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) + result = epclient.createAuthorIfNotExistsFor(user.id, user.username) + EtherUser.object.create(user=user, user_ether_id= result['authorID']) + return \ No newline at end of file From fc3f2107e3ced0a4bb34573697a4f93dcca037e1 Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Fri, 7 Sep 2018 15:36:23 +0530 Subject: [PATCH 08/24] create ether id while user sign up --- UserRolesPermission/views.py | 2 ++ etherpad/admin.py | 4 +++- etherpad/views.py | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/UserRolesPermission/views.py b/UserRolesPermission/views.py index 1148f6df..b89c282c 100644 --- a/UserRolesPermission/views.py +++ b/UserRolesPermission/views.py @@ -21,6 +21,7 @@ from django.core import serializers from datetime import date from decouple import config +from etherpad.views import create_ether_user def signup(request): """ @@ -58,6 +59,7 @@ def signup(request): else: user = form.save() assign_role(user, Author) + create_ether_user(user) auth_login(request, user, backend='django.contrib.auth.backends.ModelBackend') return redirect('user_dashboard') else: diff --git a/etherpad/admin.py b/etherpad/admin.py index 8c38f3f3..213961e1 100644 --- a/etherpad/admin.py +++ b/etherpad/admin.py @@ -1,3 +1,5 @@ from django.contrib import admin - +from .models import EtherUser # Register your models here. + +admin.site.register(EtherUser) \ No newline at end of file diff --git a/etherpad/views.py b/etherpad/views.py index c161627a..e0a9af15 100644 --- a/etherpad/views.py +++ b/etherpad/views.py @@ -34,5 +34,5 @@ def create_article_ether_group(group_id, article): def create_ether_user(user): epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) result = epclient.createAuthorIfNotExistsFor(user.id, user.username) - EtherUser.object.create(user=user, user_ether_id= result['authorID']) + EtherUser.objects.create(user=user, user_ether_id= result['authorID']) return \ No newline at end of file From 2006902cfe9d7d62cf969e47c6abb9f5834683c6 Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Fri, 7 Sep 2018 15:50:31 +0530 Subject: [PATCH 09/24] create community ether id while creating the community --- Community/views.py | 8 +++++++- etherpad/admin.py | 6 ++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Community/views.py b/Community/views.py index 3a987248..fab8fea0 100644 --- a/Community/views.py +++ b/Community/views.py @@ -30,7 +30,7 @@ from ast import literal_eval import json import requests -# Create your views here. +from etherpad.views import create_community_ether def display_communities(request): if request.method == 'POST': @@ -255,6 +255,9 @@ def handle_community_creation_requests(request): ) + #create the ether id for community + create_community_ether(communitycreation) + create_wiki_for_community(communitycreation) communityadmin = Roles.objects.get(name='community_admin') communitymembership = CommunityMembership.objects.create( @@ -433,6 +436,9 @@ def create_community(request): remove_or_add_user_feed(usr,community,'community_created') notify_remove_or_add_user(request.user, usr,community,'community_created') + #create the ether id for community + create_community_ether(community) + create_wiki_for_community(community) return redirect('community_view', community.pk) diff --git a/etherpad/admin.py b/etherpad/admin.py index 213961e1..c2a1a3c3 100644 --- a/etherpad/admin.py +++ b/etherpad/admin.py @@ -1,5 +1,7 @@ from django.contrib import admin -from .models import EtherUser +from .models import EtherUser, EtherCommunity, EtherGroup # Register your models here. -admin.site.register(EtherUser) \ No newline at end of file +admin.site.register(EtherUser) +admin.site.register(EtherCommunity) +admin.site.register(EtherGroup) \ No newline at end of file From 5e0838360ae0355523a6d45b5a0e5175e742681a Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Fri, 7 Sep 2018 16:01:13 +0530 Subject: [PATCH 10/24] create ether id while creating the group --- Group/views.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Group/views.py b/Group/views.py index 47778d5c..21445241 100644 --- a/Group/views.py +++ b/Group/views.py @@ -18,6 +18,7 @@ from django.conf import settings import json import requests +from etherpad.views import create_group_ether def create_group(request): if request.method == 'POST': @@ -37,7 +38,11 @@ def create_group(request): created_by = user ) role = Roles.objects.get(name='group_admin') - obj = GroupMembership.objects.create(user=user, group=group, role=role) + GroupMembership.objects.create(user=user, group=group, role=role) + + #create ether id for the group + create_group_ether(group) + notify_remove_or_add_user(request.user, user, group, 'group_created') remove_or_add_user_feed(request.user, group, "group_created") return group From acc23e8a82fb2e8158ba8ec21e638f5dd7f1ab51 Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Fri, 7 Sep 2018 16:20:46 +0530 Subject: [PATCH 11/24] create the ether id for article while creating the article --- Community/views.py | 6 +++++- etherpad/admin.py | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Community/views.py b/Community/views.py index fab8fea0..9a81df77 100644 --- a/Community/views.py +++ b/Community/views.py @@ -30,7 +30,7 @@ from ast import literal_eval import json import requests -from etherpad.views import create_community_ether +from etherpad.views import create_community_ether, create_article_ether_community def display_communities(request): if request.method == 'POST': @@ -133,6 +133,10 @@ def community_article_create(request): if status=='1': article = create_article(request) CommunityArticles.objects.create(article=article, user = request.user , community =community ) + + #create the ether id for artcile blonging to this community + create_article_ether_community(cid, article) + # return community_article_create_body(request, article, community) data={ 'article_id':article.id, diff --git a/etherpad/admin.py b/etherpad/admin.py index c2a1a3c3..fca2aa8d 100644 --- a/etherpad/admin.py +++ b/etherpad/admin.py @@ -1,7 +1,8 @@ from django.contrib import admin -from .models import EtherUser, EtherCommunity, EtherGroup +from .models import EtherUser, EtherCommunity, EtherGroup, EtherArticle # Register your models here. admin.site.register(EtherUser) admin.site.register(EtherCommunity) -admin.site.register(EtherGroup) \ No newline at end of file +admin.site.register(EtherGroup) +admin.site.register(EtherArticle) \ No newline at end of file From f3c858050504c9a09abb938d8e3c7da80f4d3714 Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Fri, 7 Sep 2018 16:48:00 +0530 Subject: [PATCH 12/24] create ether id while creating group article --- Group/views.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Group/views.py b/Group/views.py index 21445241..73b2de2e 100644 --- a/Group/views.py +++ b/Group/views.py @@ -18,7 +18,7 @@ from django.conf import settings import json import requests -from etherpad.views import create_group_ether +from etherpad.views import create_group_ether, create_article_ether_group def create_group(request): if request.method == 'POST': @@ -138,6 +138,10 @@ def group_article_create(request): if status=='1': article = create_article(request) GroupArticles.objects.create(article=article, user = request.user , group =group ) + + #create ether id for the article belonging to the group + create_article_ether_group(gid, article) + # return community_article_create_body(request, article, community) data={ 'article_id':article.id, From 599d66df82db2767ac9fbd42235561d2b68407b4 Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Fri, 7 Sep 2018 18:12:15 +0530 Subject: [PATCH 13/24] create session of user for a particular community --- etherpad/views.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/etherpad/views.py b/etherpad/views.py index e0a9af15..257a7d46 100644 --- a/etherpad/views.py +++ b/etherpad/views.py @@ -2,6 +2,7 @@ from py_etherpad import EtherpadLiteClient from django.conf import settings from .models import EtherCommunity, EtherGroup, EtherArticle, EtherUser +from time import time def create_community_ether(community): epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) @@ -35,4 +36,16 @@ def create_ether_user(user): epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) result = epclient.createAuthorIfNotExistsFor(user.id, user.username) EtherUser.objects.create(user=user, user_ether_id= result['authorID']) + return + + + +#session creation + +def create_session_community(request, community, user): + epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) + ether_com = EtherCommunity.objects.get(community=community) + ether_user = EtherUser.objects.get(user=user) + result = EtherpadLiteClient.createSession(ether_com.community_ether_id, ether_user.user_ether_id, validUntil=time()+28800) + request.session['sessionID'] = result['sessionID'] return \ No newline at end of file From 629e4b37629fa438314aff36c748df65bb579287 Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Fri, 7 Sep 2018 20:24:00 +0530 Subject: [PATCH 14/24] create session and set cookie for accesing the pad --- Community/views.py | 8 ++++++-- etherpad/views.py | 14 ++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Community/views.py b/Community/views.py index 9a81df77..111e87a2 100644 --- a/Community/views.py +++ b/Community/views.py @@ -30,7 +30,7 @@ from ast import literal_eval import json import requests -from etherpad.views import create_community_ether, create_article_ether_community +from etherpad.views import create_community_ether, create_article_ether_community, create_session_community def display_communities(request): if request.method == 'POST': @@ -170,7 +170,11 @@ def community_article_create(request): data={} return JsonResponse(data) else: - return render(request, 'new_article.html', {'community':community, 'status':1}) + #create the session for this article in ether pad + sid = create_session_community(request, cid) + response = render(request, 'new_article.html', {'community':community, 'status':1}) + response.set_cookie('sessionID', sid) + return response else: return redirect('home') else: diff --git a/etherpad/views.py b/etherpad/views.py index 257a7d46..ec9dc2a0 100644 --- a/etherpad/views.py +++ b/etherpad/views.py @@ -42,10 +42,12 @@ def create_ether_user(user): #session creation -def create_session_community(request, community, user): +def create_session_community(request, community_id): epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) - ether_com = EtherCommunity.objects.get(community=community) - ether_user = EtherUser.objects.get(user=user) - result = EtherpadLiteClient.createSession(ether_com.community_ether_id, ether_user.user_ether_id, validUntil=time()+28800) - request.session['sessionID'] = result['sessionID'] - return \ No newline at end of file + ether_com = EtherCommunity.objects.get(community=community_id) + ether_com = str(ether_com.community_ether_id) + ether_user = EtherUser.objects.get(user=request.user) + ether_user = str(ether_user.user_ether_id) + validUntil = int(time())+28800 + result = epclient.createSession(ether_com, ether_user, validUntil) + return result['sessionID'] \ No newline at end of file From 0353eda544948b4c3dda601795eab2cff2c34f5e Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Fri, 7 Sep 2018 20:39:57 +0530 Subject: [PATCH 15/24] pad operations move from basic article to etherpad --- BasicArticle/views.py | 20 +------------------- etherpad/views.py | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/BasicArticle/views.py b/BasicArticle/views.py index 5c3542d9..632fd195 100644 --- a/BasicArticle/views.py +++ b/BasicArticle/views.py @@ -23,25 +23,7 @@ from django.conf import settings from Recommendation_API.views import get_Recommendations import json - -def getHTML(article): - epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) - result = epclient.getHtml(article.id) - return result['html'] - -# +++++++++++++++++++++++++++++++++++++++++++ - - -def getText(article): - epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) - result = epclient.getText(article.id) - return result['text'] - -# +++++++++++++++++++++++++++++++++++++++++++ - -def deletePad(article): - epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) - epclient.deletePad(article.id) +from etherpad.views import getHTML, getText, deletePad def article_autosave(request,pk): if request.user.is_authenticated: diff --git a/etherpad/views.py b/etherpad/views.py index ec9dc2a0..56803441 100644 --- a/etherpad/views.py +++ b/etherpad/views.py @@ -50,4 +50,27 @@ def create_session_community(request, community_id): ether_user = str(ether_user.user_ether_id) validUntil = int(time())+28800 result = epclient.createSession(ether_com, ether_user, validUntil) - return result['sessionID'] \ No newline at end of file + return result['sessionID'] + + +#pad operations + + +def getHTML(article): + epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) + result = epclient.getHtml(article.id) + return result['html'] + +# +++++++++++++++++++++++++++++++++++++++++++ + + +def getText(article): + epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) + result = epclient.getText(article.id) + return result['text'] + +# +++++++++++++++++++++++++++++++++++++++++++ + +def deletePad(article): + epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) + epclient.deletePad(article.id) \ No newline at end of file From e8e998c4cfec24fa1fdcd6ed104b8dce53f535d1 Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Fri, 7 Sep 2018 20:52:44 +0530 Subject: [PATCH 16/24] resolve and map actual etherpad id with gethtml and gettext --- etherpad/views.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/etherpad/views.py b/etherpad/views.py index 56803441..a428f67c 100644 --- a/etherpad/views.py +++ b/etherpad/views.py @@ -57,20 +57,23 @@ def create_session_community(request, community_id): def getHTML(article): - epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) - result = epclient.getHtml(article.id) - return result['html'] + epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) + article = EtherArticle.objects.get(article=article) + result = epclient.getHtml(article.article_ether_id) + return result['html'] # +++++++++++++++++++++++++++++++++++++++++++ def getText(article): - epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) - result = epclient.getText(article.id) - return result['text'] + epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) + article = EtherArticle.objects.get(article=article) + result = epclient.getText(article.article_ether_id) + return result['text'] # +++++++++++++++++++++++++++++++++++++++++++ def deletePad(article): - epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) - epclient.deletePad(article.id) \ No newline at end of file + epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) + article = EtherArticle.objects.get(article=article) + epclient.deletePad(article.article_ether_id) \ No newline at end of file From 9d5ddea6d1146d21d77d20a4d4704372af66eb3e Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Mon, 10 Sep 2018 16:08:59 +0530 Subject: [PATCH 17/24] return the pad ids after creation in community or group --- etherpad/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/etherpad/views.py b/etherpad/views.py index a428f67c..e5ebad8b 100644 --- a/etherpad/views.py +++ b/etherpad/views.py @@ -23,14 +23,14 @@ def create_article_ether_community(community_id, article): community = EtherCommunity.objects.get(community=community_id) result = epclient.createGroupPad(community.community_ether_id, article.id) EtherArticle.objects.create(article=article, article_ether_id=result['padID']) - return + return result['padID'] def create_article_ether_group(group_id, article): epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) group = EtherGroup.objects.get(group=group_id) result = epclient.createGroupPad(group.group_ether_id, article.id) EtherArticle.objects.create(article=article, article_ether_id=result['padID']) - return + return result['padID'] def create_ether_user(user): epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) From 4bf66b37f1ac733569e143e6272597495c0e4390 Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Mon, 10 Sep 2018 16:24:43 +0530 Subject: [PATCH 18/24] actual ether pad id to be loaded in iframe --- Community/views.py | 5 +++-- templates/new_article.html | 11 ++--------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/Community/views.py b/Community/views.py index 111e87a2..e8855839 100644 --- a/Community/views.py +++ b/Community/views.py @@ -135,7 +135,7 @@ def community_article_create(request): CommunityArticles.objects.create(article=article, user = request.user , community =community ) #create the ether id for artcile blonging to this community - create_article_ether_community(cid, article) + padid = create_article_ether_community(cid, article) # return community_article_create_body(request, article, community) data={ @@ -144,7 +144,8 @@ def community_article_create(request): 'user_id':request.user.id, 'username':request.user.username, 'url':settings.SERVERURL, - 'articleof':'community' + 'articleof':'community', + 'padid':padid } return JsonResponse(data) # return redirect('article_edit', article.pk) diff --git a/templates/new_article.html b/templates/new_article.html index 24a4f13b..8a367c56 100644 --- a/templates/new_article.html +++ b/templates/new_article.html @@ -260,17 +260,10 @@ type: 'POST', data: formData, success: function (data) { - console.log(data.article_id); - console.log(data.username); - console.log(data.community_or_group_id); - console.log(data.url); - console.log(data.articleof); - - - + if(update==0) { - var src= data.url + '/p/' + data.article_id + '?userName=' +data.username; + var src= data.url + '/p/' + data.padid; console.log(src); document.getElementById("etherpad_iframe").src= src; id = data.article_id; From 1cc60e8a186d07518292f4cfb563713ef4bce267 Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Mon, 10 Sep 2018 16:35:12 +0530 Subject: [PATCH 19/24] create session for group article ether pad --- etherpad/views.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/etherpad/views.py b/etherpad/views.py index e5ebad8b..4e6fdc7e 100644 --- a/etherpad/views.py +++ b/etherpad/views.py @@ -40,7 +40,7 @@ def create_ether_user(user): -#session creation +#session creation community def create_session_community(request, community_id): epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) @@ -76,4 +76,18 @@ def getText(article): def deletePad(article): epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) article = EtherArticle.objects.get(article=article) - epclient.deletePad(article.article_ether_id) \ No newline at end of file + epclient.deletePad(article.article_ether_id) + + + +#create session group + +def create_session_group(request, group_id): + epclient = EtherpadLiteClient(settings.APIKEY, settings.APIURL) + ether_group = EtherGroup.objects.get(group=group_id) + ether_group = str(ether_group.group_ether_id) + ether_user = EtherUser.objects.get(user=request.user) + ether_user = str(ether_user.user_ether_id) + validUntil = int(time())+28800 + result = epclient.createSession(ether_group, ether_user, validUntil) + return result['sessionID'] \ No newline at end of file From 80c3718c1e42d146db294b6c1f9753df6910aee6 Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Mon, 10 Sep 2018 16:44:50 +0530 Subject: [PATCH 20/24] set seeion cookie and load iframe with actula ether pad id --- Group/views.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Group/views.py b/Group/views.py index 73b2de2e..db157032 100644 --- a/Group/views.py +++ b/Group/views.py @@ -18,7 +18,7 @@ from django.conf import settings import json import requests -from etherpad.views import create_group_ether, create_article_ether_group +from etherpad.views import create_group_ether, create_article_ether_group, create_session_group def create_group(request): if request.method == 'POST': @@ -140,7 +140,7 @@ def group_article_create(request): GroupArticles.objects.create(article=article, user = request.user , group =group ) #create ether id for the article belonging to the group - create_article_ether_group(gid, article) + padid = create_article_ether_group(gid, article) # return community_article_create_body(request, article, community) data={ @@ -149,7 +149,8 @@ def group_article_create(request): 'user_id':request.user.id, 'username':request.user.username, 'url':settings.SERVERURL, - 'articleof':'group' + 'articleof':'group', + 'padid':padid } return JsonResponse(data) # return redirect('article_edit', article.pk) @@ -175,7 +176,11 @@ def group_article_create(request): data={} return JsonResponse(data) else: - return render(request, 'new_article.html', {'group':group, 'status':1}) + #create session for this group article in ether pad + sid = create_session_group(request, gid) + response = render(request, 'new_article.html', {'group':group, 'status':1}) + response.set_cookie('sessionID', sid) + return response else: return redirect('home') else: From d6b727f99d4fc1dd6eb762367769373981666725 Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Mon, 10 Sep 2018 17:12:42 +0530 Subject: [PATCH 21/24] get etherpad id for and article --- etherpad/views.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/etherpad/views.py b/etherpad/views.py index 4e6fdc7e..dcd2ea72 100644 --- a/etherpad/views.py +++ b/etherpad/views.py @@ -90,4 +90,9 @@ def create_session_group(request, group_id): ether_user = str(ether_user.user_ether_id) validUntil = int(time())+28800 result = epclient.createSession(ether_group, ether_user, validUntil) - return result['sessionID'] \ No newline at end of file + return result['sessionID'] + + +def get_pad_id(article_id): + article = EtherArticle.objects.get(article=article_id) + return article.article_ether_id \ No newline at end of file From f30945b893025c9c6b217aaedf474df0d8fcf5f1 Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Mon, 10 Sep 2018 18:31:47 +0530 Subject: [PATCH 22/24] get ether pad id and session while editing the article --- BasicArticle/views.py | 9 +++++++-- templates/edit_article.html | 12 ++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/BasicArticle/views.py b/BasicArticle/views.py index 632fd195..de90f3d9 100644 --- a/BasicArticle/views.py +++ b/BasicArticle/views.py @@ -23,7 +23,7 @@ from django.conf import settings from Recommendation_API.views import get_Recommendations import json -from etherpad.views import getHTML, getText, deletePad +from etherpad.views import getHTML, getText, deletePad, create_session_community, create_session_group, get_pad_id def article_autosave(request,pk): if request.user.is_authenticated: @@ -234,6 +234,7 @@ def edit_article(request, pk): try: cmember = CommunityMembership.objects.get(user =request.user.id, community = article.community.pk) + sessionid = create_session_community(request, article.community.id) try: transition = Transitions.objects.get(from_state=article.article.state) state1 = States.objects.get(name='draft') @@ -265,6 +266,7 @@ def edit_article(request, pk): cmember = CommunityMembership.objects.get(user=request.user.id, community = communitygroup.community.pk) try: gmember =GroupMembership.objects.get(user=request.user.id, group = article.group.pk) + sessionid = create_session_group(request, article.group.id) except GroupMembership.DoesNotExist: gmember = 'FALSE' try: @@ -285,7 +287,10 @@ def edit_article(request, pk): # print ("Hello6") raise Http404 - return render(request, 'edit_article.html', {'article': article, 'cmember':cmember,'gmember':gmember,'message':message, 'belongs_to':belongs_to,'transition': transition, 'private':private,'uname':request.user,'url':settings.SERVERURL}) + padid = get_pad_id(article.article.id) + response = render(request, 'edit_article.html', {'article': article, 'cmember':cmember,'gmember':gmember,'message':message, 'belongs_to':belongs_to,'transition': transition, 'private':private,'url':settings.SERVERURL, 'padid':padid}) + response.set_cookie('sessionID', sessionid) + return response else: return redirect('login') diff --git a/templates/edit_article.html b/templates/edit_article.html index 457e3e00..5626895d 100644 --- a/templates/edit_article.html +++ b/templates/edit_article.html @@ -56,7 +56,7 @@
- + You can create your content in 4000 words.
{% if article.article.image %} @@ -83,7 +83,7 @@
- + You can create your content in 4000 words.
{% if article.article.image %} @@ -114,7 +114,7 @@
- + You can create your content in 4000 words.
{% if article.article.image %} @@ -144,7 +144,7 @@
- + You can create your content in 4000 words.
{% if article.article.image %} @@ -171,7 +171,7 @@
- + You can create your content in 4000 words.
{% if article.article.image %} @@ -198,7 +198,7 @@
- + You can create your content in 4000 words.
{% if article.article.image %} From adc8bb5fa6b6510b10dcb5ab287a11f2db2def7c Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Mon, 10 Sep 2018 19:08:08 +0530 Subject: [PATCH 23/24] remove console logs --- templates/edit_article.html | 2 -- templates/new_article.html | 17 ++++++----------- templates/view_article.html | 2 -- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/templates/edit_article.html b/templates/edit_article.html index 5626895d..1213473e 100644 --- a/templates/edit_article.html +++ b/templates/edit_article.html @@ -248,8 +248,6 @@ dataType: 'json', success: function (data) { if (data.success) { - console.log("Done"); - console.log(data.html); } } }); diff --git a/templates/new_article.html b/templates/new_article.html index 8a367c56..d5efcbc8 100644 --- a/templates/new_article.html +++ b/templates/new_article.html @@ -85,7 +85,7 @@
{% csrf_token %}
- + {% if request.POST.articleof == 'group' %} {% endif %} @@ -264,7 +264,6 @@ if(update==0) { var src= data.url + '/p/' + data.padid; - console.log(src); document.getElementById("etherpad_iframe").src= src; id = data.article_id; // document.getElementById('create').innerText="Update Article and Go to Next Step"; @@ -273,7 +272,7 @@ // document.getElementById('next').disabled=false; } // check(); - console.log("Checking done"); + }, complete: function(){ setTimeout(function(){ @@ -307,8 +306,6 @@ data: formData, success: function (data) { // alert(data); - console.log(data.article_id); - console.log(data.body); console.log("Done checkin"); }, fail: function(){ @@ -327,13 +324,13 @@ // ======================================================== // ======================================================== - $("#next1").on("click",function(){$("#create").click();if(pos<2)pos++;console.log(pos);}); + $("#next1").on("click",function(){$("#create").click();if(pos<2)pos++;}); $("#next2").on("click",function(){ - $("#save").click();if(pos<2)pos++;console.log(pos); + $("#save").click();if(pos<2)pos++; }); - $("#prev").on("click",function(){if(pos>0)pos--;console.log(pos);check();}); + $("#prev").on("click",function(){if(pos>0)pos--;check();}); $("#finish").on("click",function(){location.href = "/article-view/"+id+"/";}); @@ -348,7 +345,6 @@ success: function (data) { // alert(data); // console.log(data.article_id); - console.log(data.body); // check(); // console.log("Done checkin") $.ajax({ @@ -359,7 +355,6 @@ // alert(data); // console.log(data.article_id); // console.log("!"); - console.log(data); // console.log(data.inappropriates); status= data.inappropriates; // check(); @@ -374,7 +369,7 @@ } else { - if(pos<2)pos++;console.log(pos); + if(pos<2)pos++; $("#save").click(); } }, diff --git a/templates/view_article.html b/templates/view_article.html index 07a29acc..75aabce8 100644 --- a/templates/view_article.html +++ b/templates/view_article.html @@ -128,7 +128,6 @@

Leave a Comment

success: function (data) { // alert(data); // console.log(data.article_id); - console.log(data.body); // check(); // console.log("Done checkin") $.ajax({ @@ -139,7 +138,6 @@

Leave a Comment

// alert(data); // console.log(data.article_id); // console.log("!"); - console.log(data); // console.log(data.inappropriates); status= data.inappropriates; // check(); From 62edd7cf81004b9e76176a39cb386a9a366a6c91 Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Mon, 10 Sep 2018 19:55:17 +0530 Subject: [PATCH 24/24] remove article autosave intervals --- CollaborationSystem/urls.py | 3 --- templates/edit_article.html | 26 -------------------------- 2 files changed, 29 deletions(-) diff --git a/CollaborationSystem/urls.py b/CollaborationSystem/urls.py index b2ef42c0..f28e5781 100644 --- a/CollaborationSystem/urls.py +++ b/CollaborationSystem/urls.py @@ -58,9 +58,6 @@ url(r'^articles/$', articleview.display_articles, name='display_articles'), url(r'^article-view/(?P\d*)/$', articleview.view_article, name='article_view'), - - url(r'^ajax/article_autosave/(?P\d*)/$', articleview.article_autosave, name='article_autosave'), - url(r'^ajax/article_text/(?P\d*)/$', articleview.article_text, name='article_text'), url(r'^h5p-view/(?P\d*)/$', communityview.h5p_view, name='h5p_view'), diff --git a/templates/edit_article.html b/templates/edit_article.html index 1213473e..36ccbd75 100644 --- a/templates/edit_article.html +++ b/templates/edit_article.html @@ -235,32 +235,6 @@ {% endblock %} {% block javascript %} - -