From fb166e4ea6db2f1f72d203cf8a2c20dc8dcddae5 Mon Sep 17 00:00:00 2001 From: Bishakh Ghosh Date: Wed, 25 May 2016 23:21:49 +0530 Subject: [PATCH 01/52] Disallow null values for website_position_id in WebsiteSection --- website/models.py | 1 - 1 file changed, 1 deletion(-) diff --git a/website/models.py b/website/models.py index fb5e29b8..e7fb6b94 100644 --- a/website/models.py +++ b/website/models.py @@ -26,7 +26,6 @@ class WebsiteSection(models.Model): # determines for what purpose the article is used. Eg: header, body etc. website_position_id = models.CharField(max_length=100, unique=True, - null=True, db_index=True) # determines for which page the article is used. Eg: home, development. From ea36417ee008b790ef4ac1e4d34a3fd483a7a955 Mon Sep 17 00:00:00 2001 From: Bishakh Ghosh Date: Wed, 25 May 2016 23:37:50 +0530 Subject: [PATCH 02/52] Add more tags to bleach whitelist necessary for proper markdown rendering fixes #3 --- website/models.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/website/models.py b/website/models.py index e7fb6b94..f571b55e 100644 --- a/website/models.py +++ b/website/models.py @@ -4,6 +4,18 @@ import bleach import datetime +# markdown allowed tags that are not filtered by bleach + +allowed_html_tags = bleach.ALLOWED_TAGS + ['p', 'pre', 'table', 'img', + 'h1', 'h2', 'h3', 'h4', 'h5', + 'h6', 'b', 'i', 'strong', 'em', + 'tt', 'br', 'blockquote', + 'code', 'ul', 'ol', 'li', + 'dd', 'dt', 'a', 'tr', 'td', + 'div', 'span', 'hr'] + +allowed_attrs = ['href', 'class', 'rel', 'alt', 'class', 'src'] + # Create your models here. @@ -41,17 +53,13 @@ class Meta: ("edit_section", "Can edit available sections"), ) - allowed_html_tags = bleach.ALLOWED_TAGS + ['p', 'pre', 'table', 'img', - 'tr', 'td', 'div', 'span', 'hr'] - allowed_attrs = ['href', 'class', 'rel', 'alt', 'class', 'src'] - def save(self, *args, **kwargs): html_content = markdown.markdown(self.body_markdown, extensions=['codehilite']) print(html_content) # bleach is used to filter html tags like + {% block extra_js_top %}{% endblock %} + {% block header %}{% endblock %} @@ -15,4 +20,5 @@ {% block content %}{% endblock %} {% block footer %}{% endblock %} +{% block extra_js_bottom %}{% endblock %} diff --git a/website/templates/website/editsection.html b/website/templates/website/editsection.html index a82a6726..35b3d624 100644 --- a/website/templates/website/editsection.html +++ b/website/templates/website/editsection.html @@ -1,4 +1,10 @@ {% extends "website/base_template.html" %} +{% load staticfiles %} + +{% block extra_css %} + + +{% endblock %} {% block content_body %} @@ -11,3 +17,12 @@ {% endif %} {% endblock %} + + +{% block extra_js_bottom %} + + + +{% endblock %} \ No newline at end of file From 434328afe2ab91dff83050fa820a74441a72bd75 Mon Sep 17 00:00:00 2001 From: Bishakh Ghosh Date: Thu, 26 May 2016 00:50:49 +0530 Subject: [PATCH 04/52] Add simplemde editor in addsection view --- website/templates/website/addsection.html | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/website/templates/website/addsection.html b/website/templates/website/addsection.html index 6f498da5..7da07e42 100644 --- a/website/templates/website/addsection.html +++ b/website/templates/website/addsection.html @@ -1,5 +1,12 @@ {% extends "website/base_template.html" %} +{% load staticfiles %} + +{% block extra_css %} + + +{% endblock %} + {% block content_body %} {% if form %} @@ -11,3 +18,12 @@ {% endif %} {% endblock %} + + +{% block extra_js_bottom %} + + + +{% endblock %} From c4ef0218a7b8a46278447550a8ee4015b6425e56 Mon Sep 17 00:00:00 2001 From: Bishakh Ghosh Date: Thu, 26 May 2016 00:59:25 +0530 Subject: [PATCH 05/52] Add iframe to bleach whitelist to enable youtube embeds This raises a security risk as any iframe can be embedded in this case fixes #4 Causes #5 --- website/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/models.py b/website/models.py index f571b55e..9b8deb8c 100644 --- a/website/models.py +++ b/website/models.py @@ -12,7 +12,7 @@ 'tt', 'br', 'blockquote', 'code', 'ul', 'ol', 'li', 'dd', 'dt', 'a', 'tr', 'td', - 'div', 'span', 'hr'] + 'div', 'span', 'hr', 'iframe'] allowed_attrs = ['href', 'class', 'rel', 'alt', 'class', 'src'] From 8a573de31aeb27553428196d53b5ecaf3fab9c60 Mon Sep 17 00:00:00 2001 From: Bishakh Ghosh Date: Thu, 26 May 2016 16:41:17 +0530 Subject: [PATCH 06/52] Write custom template filter for converting youtube links to embeds --- website/templatetags/__init__.py | 0 website/templatetags/customfilters.py | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 website/templatetags/__init__.py create mode 100644 website/templatetags/customfilters.py diff --git a/website/templatetags/__init__.py b/website/templatetags/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/website/templatetags/customfilters.py b/website/templatetags/customfilters.py new file mode 100644 index 00000000..119edaac --- /dev/null +++ b/website/templatetags/customfilters.py @@ -0,0 +1,19 @@ +from django import template +import re + +register = template.Library() + + +@register.filter(name='youtube_embed_url') +# converts all youtube URLs in the text to embed HTML +@register.filter(name='youtube_embed_url') +def youtube_embed_url(value): + exp = re.compile(r'((http|https)\:\/\/www\.youtube\.com\/watch\?v=([a-zA-Z0-9]*))') + matches = exp.findall(value) + processed_str = value + template = '' + for match in matches: + processed_str = processed_str.replace(match[0], template % match[2]) + return processed_str From 49a2a7b1d598f3608bd3ff116333d3eb43fe8ce4 Mon Sep 17 00:00:00 2001 From: Bishakh Ghosh Date: Thu, 26 May 2016 17:03:13 +0530 Subject: [PATCH 07/52] Remove iframe from bleach whitelist and use custom filter fixes #5 custom youtube filter replaces youtube links with embed codes while rendering views --- website/models.py | 2 +- website/templates/website/dashboard.html | 4 ++-- website/templates/website/index.html | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/website/models.py b/website/models.py index 9b8deb8c..f571b55e 100644 --- a/website/models.py +++ b/website/models.py @@ -12,7 +12,7 @@ 'tt', 'br', 'blockquote', 'code', 'ul', 'ol', 'li', 'dd', 'dt', 'a', 'tr', 'td', - 'div', 'span', 'hr', 'iframe'] + 'div', 'span', 'hr'] allowed_attrs = ['href', 'class', 'rel', 'alt', 'class', 'src'] diff --git a/website/templates/website/dashboard.html b/website/templates/website/dashboard.html index 9e3962fe..6ea116cb 100644 --- a/website/templates/website/dashboard.html +++ b/website/templates/website/dashboard.html @@ -1,5 +1,5 @@ {% extends "website/base_template.html" %} - +{% load customfilters %} {% block content_body %} @@ -7,7 +7,7 @@ {% for section in all_sections %} {{section}}
-{{section.body_html|safe}} +{{section.body_html|youtube_embed_url|safe}} Edit
{% endfor %} diff --git a/website/templates/website/index.html b/website/templates/website/index.html index 32901cc8..84ede4dd 100644 --- a/website/templates/website/index.html +++ b/website/templates/website/index.html @@ -1,17 +1,18 @@ {% extends "website/base_template.html" %} +{% load customfilters %} {% block content_body %} {% if home_header %}

{{ home_header.title }}

-

{{ home_header.body_html|safe }}

+

{{ home_header.body_html|youtube_embed_url|safe }}

{% else %}

home_header does not exist

{% endif %} {% if getting_started %}

{{ getting_started.title }}

-

{{ getting_started.body_html|safe }}

+

{{ getting_started.body_html|youtube_embed_url|safe }}

{% else %}

getting_started does not exist

{% endif %} From 4b8d41e923cb45cd14e4e8c495e8f864c9084bc8 Mon Sep 17 00:00:00 2001 From: Bishakh Ghosh Date: Thu, 26 May 2016 18:49:05 +0530 Subject: [PATCH 08/52] Style youtube embedded player fixes #6 --- website/static/css/main.css | 9 +++++++++ website/static/css/main.css.map | 2 +- website/static/css/main.scss | 13 +++++++++++++ website/templatetags/customfilters.py | 4 ++-- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/website/static/css/main.css b/website/static/css/main.css index 3eb2c561..29f55314 100644 --- a/website/static/css/main.css +++ b/website/static/css/main.css @@ -24,4 +24,13 @@ border: 1px solid transparent; border-radius: 4px; } +img { + display: block; + margin: 0 auto; } + +.youtube-embed { + display: block; + margin: 0 auto; + box-shadow: 0 0 1em #222; } + /*# sourceMappingURL=main.css.map */ diff --git a/website/static/css/main.css.map b/website/static/css/main.css.map index cbe546e1..416c4e64 100644 --- a/website/static/css/main.css.map +++ b/website/static/css/main.css.map @@ -1,6 +1,6 @@ { "version": 3, -"mappings": "AAAA,kBAAmB;EAClB,MAAM,EAAE,KAAK;;AAGd,cAAe;EACd,UAAU,EAAE,IAAI;EAChB,UAAU,EAAE,IAAI;EAChB,aAAa,EAAE,iBAAiB;;AAGjC,kBAAmB;EAClB,SAAS,EAAE,KAAK;EAChB,OAAO,EAAE,WAAW;EACpB,wBAAQ;IACP,UAAU,EAAE,gBAAgB;;AAI9B,cAAe;EACX,QAAQ,EAAE,QAAQ;EAClB,KAAK,EAAE,KAAK;EACZ,OAAO,EAAE,SAAS;EAClB,UAAU,EAAE,IAAI;EAChB,YAAY,EAAE,IAAI;EAClB,aAAa,EAAE,GAAG;EAClB,gBAAgB,EAAE,WAAW;EAC7B,gBAAgB,EAAE,IAAI;EACtB,MAAM,EAAE,qBAAqB;EAC7B,aAAa,EAAE,GAAG", +"mappings": "AAAA,kBAAmB;EAClB,MAAM,EAAE,KAAK;;AAGd,cAAe;EACd,UAAU,EAAE,IAAI;EAChB,UAAU,EAAE,IAAI;EAChB,aAAa,EAAE,iBAAiB;;AAGjC,kBAAmB;EAClB,SAAS,EAAE,KAAK;EAChB,OAAO,EAAE,WAAW;EACpB,wBAAQ;IACP,UAAU,EAAE,gBAAgB;;AAI9B,cAAe;EACX,QAAQ,EAAE,QAAQ;EAClB,KAAK,EAAE,KAAK;EACZ,OAAO,EAAE,SAAS;EAClB,UAAU,EAAE,IAAI;EAChB,YAAY,EAAE,IAAI;EAClB,aAAa,EAAE,GAAG;EAClB,gBAAgB,EAAE,WAAW;EAC7B,gBAAgB,EAAE,IAAI;EACtB,MAAM,EAAE,qBAAqB;EAC7B,aAAa,EAAE,GAAG;;AAItB,GAAI;EACA,OAAO,EAAE,KAAK;EACd,MAAM,EAAE,MAAM;;AAIlB,cAAe;EACX,OAAO,EAAE,KAAK;EACd,MAAM,EAAE,MAAM;EACd,UAAU,EAAE,YAAY", "sources": ["main.scss"], "names": [], "file": "main.css" diff --git a/website/static/css/main.scss b/website/static/css/main.scss index f8e62626..62631e94 100644 --- a/website/static/css/main.scss +++ b/website/static/css/main.scss @@ -28,3 +28,16 @@ border: 1px solid transparent; border-radius: 4px; } + +// default image align to center +img { + display: block; + margin: 0 auto; +} + +// youtube-embed styles +.youtube-embed { + display: block; + margin: 0 auto; + box-shadow: 0 0 1em #222; +} \ No newline at end of file diff --git a/website/templatetags/customfilters.py b/website/templatetags/customfilters.py index 119edaac..41fd7b34 100644 --- a/website/templatetags/customfilters.py +++ b/website/templatetags/customfilters.py @@ -11,8 +11,8 @@ def youtube_embed_url(value): exp = re.compile(r'((http|https)\:\/\/www\.youtube\.com\/watch\?v=([a-zA-Z0-9]*))') matches = exp.findall(value) processed_str = value - template = '' + frameborder="0" allowfullscreen>' for match in matches: processed_str = processed_str.replace(match[0], template % match[2]) return processed_str From 4df14aeb4268c588bcea317fe53983146189a5d9 Mon Sep 17 00:00:00 2001 From: Bishakh Ghosh Date: Sat, 4 Jun 2016 09:15:07 +0530 Subject: [PATCH 14/52] Add publication models and views --- website/admin.py | 1 + website/forms.py | 7 ++ website/migrations/0003_auto_20160602_1828.py | 43 +++++++++ website/migrations/0004_auto_20160604_0343.py | 20 ++++ website/models.py | 27 ++++++ website/templates/website/addpublication.html | 16 ++++ website/templates/website/dashboard.html | 1 + .../website/dashboard_publications.html | 21 +++++ .../templates/website/editpublication.html | 15 +++ website/templates/website/index.html | 13 ++- website/urls.py | 7 ++ website/views.py | 93 ++++++++++++++++++- 12 files changed, 262 insertions(+), 2 deletions(-) create mode 100644 website/migrations/0003_auto_20160602_1828.py create mode 100644 website/migrations/0004_auto_20160604_0343.py create mode 100644 website/templates/website/addpublication.html create mode 100644 website/templates/website/dashboard_publications.html create mode 100644 website/templates/website/editpublication.html diff --git a/website/admin.py b/website/admin.py index ffcd866c..a0f59197 100644 --- a/website/admin.py +++ b/website/admin.py @@ -4,3 +4,4 @@ admin.site.register(models.WebsiteSection) admin.site.register(models.NewsPost) +admin.site.register(models.Publication) diff --git a/website/forms.py b/website/forms.py index 40ce57bf..982b7609 100644 --- a/website/forms.py +++ b/website/forms.py @@ -20,3 +20,10 @@ class AddEditNewsPostForm(ModelForm): class Meta: model = NewsPost fields = ['title', 'body_markdown', 'post_date'] + + +class AddEditPublicationForm(ModelForm): + class Meta: + model = Publication + fields = ['title', 'url', 'author', 'doi', 'journal', 'publisher', + 'year_of_publication', 'month_of_publication', 'bibtex'] diff --git a/website/migrations/0003_auto_20160602_1828.py b/website/migrations/0003_auto_20160602_1828.py new file mode 100644 index 00000000..2b771063 --- /dev/null +++ b/website/migrations/0003_auto_20160602_1828.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-06-02 18:28 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('website', '0002_newspost'), + ] + + operations = [ + migrations.CreateModel( + name='Publication', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=200)), + ('url', models.CharField(max_length=200)), + ('author', models.CharField(max_length=200)), + ('doi', models.CharField(blank=True, max_length=100, null=True)), + ('journal', models.CharField(blank=True, max_length=200, null=True)), + ('publisher', models.CharField(blank=True, max_length=200, null=True)), + ('year_of_publication', models.CharField(blank=True, max_length=4, null=True)), + ('month_of_publication', models.CharField(blank=True, max_length=4, null=True)), + ('bibtex', models.TextField(blank=True, null=True)), + ('created', models.DateTimeField(auto_now_add=True)), + ('modified', models.DateTimeField(auto_now_add=True)), + ], + ), + migrations.AlterField( + model_name='newspost', + name='post_date', + field=models.DateTimeField(default=django.utils.timezone.now), + ), + migrations.AlterField( + model_name='websitesection', + name='website_position_id', + field=models.CharField(db_index=True, max_length=100, unique=True), + ), + ] diff --git a/website/migrations/0004_auto_20160604_0343.py b/website/migrations/0004_auto_20160604_0343.py new file mode 100644 index 00000000..e68dbf8a --- /dev/null +++ b/website/migrations/0004_auto_20160604_0343.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-06-04 03:43 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('website', '0003_auto_20160602_1828'), + ] + + operations = [ + migrations.AlterField( + model_name='publication', + name='month_of_publication', + field=models.CharField(blank=True, max_length=10, null=True), + ), + ] diff --git a/website/models.py b/website/models.py index 53aecf5a..f1b2ed15 100644 --- a/website/models.py +++ b/website/models.py @@ -90,3 +90,30 @@ def save(self, *args, **kwargs): def __str__(self): return self.title + + +class Publication(models.Model): + """ + Model for storing publication information. + """ + title = models.CharField(max_length=200) + url = models.CharField(max_length=200) + author = models.CharField(max_length=200) + doi = models.CharField(max_length=100, null=True, blank=True) + journal = models.CharField(max_length=200, null=True, blank=True) + publisher = models.CharField(max_length=200, null=True, blank=True) + year_of_publication = models.CharField(max_length=4, null=True, blank=True) + month_of_publication = models.CharField(max_length=10, null=True, + blank=True) + bibtex = models.TextField(null=True, blank=True) + + created = models.DateTimeField(editable=False, auto_now_add=True) + modified = models.DateTimeField(editable=False, auto_now_add=True) + + def save(self, *args, **kwargs): + self.modified = datetime.datetime.now() + # Call the "real" save() method. + super(Publication, self).save(*args, **kwargs) + + def __str__(self): + return self.title diff --git a/website/templates/website/addpublication.html b/website/templates/website/addpublication.html new file mode 100644 index 00000000..73612d63 --- /dev/null +++ b/website/templates/website/addpublication.html @@ -0,0 +1,16 @@ +{% extends "website/base_template.html" %} + +{% load staticfiles %} + + +{% block content_body %} + +{% if form %} +
+ {% csrf_token %} + {{ form }} + +
+{% endif %} + +{% endblock %} diff --git a/website/templates/website/dashboard.html b/website/templates/website/dashboard.html index b8150f17..701902b7 100644 --- a/website/templates/website/dashboard.html +++ b/website/templates/website/dashboard.html @@ -5,5 +5,6 @@

Admin Panel

Edit Website Sections
Add / Edit News
+
Add / Edit Publications
{% endblock %} diff --git a/website/templates/website/dashboard_publications.html b/website/templates/website/dashboard_publications.html new file mode 100644 index 00000000..a4f51f2f --- /dev/null +++ b/website/templates/website/dashboard_publications.html @@ -0,0 +1,21 @@ +{% extends "website/base_template.html" %} +{% load customfilters %} +{% block content_body %} + +

Admin Panel

+ +

Add / Edit Publications

+ + +
+ +{% if all_publications %} + {% for publication in all_publications %} + {{publication.title}}
+ {{publication.author}} + Edit +
+ {% endfor %} +{% endif %} + +{% endblock %} \ No newline at end of file diff --git a/website/templates/website/editpublication.html b/website/templates/website/editpublication.html new file mode 100644 index 00000000..91b20381 --- /dev/null +++ b/website/templates/website/editpublication.html @@ -0,0 +1,15 @@ +{% extends "website/base_template.html" %} +{% load staticfiles %} + + +{% block content_body %} + +{% if form %} +
+ {% csrf_token %} + {{ form }} + +
+{% endif %} + +{% endblock %} \ No newline at end of file diff --git a/website/templates/website/index.html b/website/templates/website/index.html index a29e1360..a8007d77 100644 --- a/website/templates/website/index.html +++ b/website/templates/website/index.html @@ -67,4 +67,15 @@

News

  • {{news.post_date}} |

    {{ news.body_html|safe }}

  • {% endfor %} -{% endblock %} + + + +

    Publications

    +{% for publication in all_publications %} + {{publication.title}}
    + {{publication.author}} + Edit +
    +{% endfor %} + +{% endblock %} \ No newline at end of file diff --git a/website/urls.py b/website/urls.py index bf06dec4..45d4c992 100644 --- a/website/urls.py +++ b/website/urls.py @@ -26,6 +26,13 @@ url(r'^dashboard/news/add/$', views.add_news_post, name='add_news_post'), + # Publication Management + url(r'^dashboard/publications/$', views.dashboard_publications, + name='dashboard_publications'), + url(r'^dashboard/publications/edit/(?P.*?)/$', + views.edit_publication, name='edit_publication'), + url(r'^dashboard/publications/add/$', views.add_publication, + name='add_publication'), url('', include('social.apps.django_app.urls', namespace='social')), diff --git a/website/views.py b/website/views.py index 00c68604..7ddfc6c3 100644 --- a/website/views.py +++ b/website/views.py @@ -14,10 +14,11 @@ def index(request): getting_started = get_website_section('getting_started') latest_news = get_latest_news_posts(5) - + all_publications = Publication.objects.all() context['home_header'] = home_header context['getting_started'] = getting_started context['latest_news'] = latest_news + context['all_publications'] = all_publications return render(request, 'website/index.html', context) @@ -213,6 +214,96 @@ def edit_news_post(request, news_id): return render(request, 'website/editnews.html', context) +@login_required +def dashboard_publications(request): + try: + social = request.user.social_auth.get(provider='github') + access_token = social.extra_data['access_token'] + except: + access_token = '' + has_permission = has_commit_permission(access_token, 'dipy_web') + if has_permission: + all_publications = Publication.objects.all() + context = {'all_publications': all_publications} + # if(request.user.has_perm('website.view_section')): + return render(request, 'website/dashboard_publications.html', context) + else: + return render(request, 'website/dashboard_publications.html', {}) + + +@login_required +def add_publication(request): + # check if user has edit permissions + try: + social = request.user.social_auth.get(provider='github') + access_token = social.extra_data['access_token'] + except: + access_token = '' + if access_token: + has_permission = has_commit_permission(access_token, 'dipy_web') + else: + has_permission = False + + # if user does not have edit permission: + if not has_permission: + return render(request, 'website/addpublication.html', {}) + + # if user has edit permission: + context = {} + if request.method == 'POST': + submitted_form = AddEditPublicationForm(request.POST) + if submitted_form.is_valid(): + submitted_form.save() + return redirect('/dashboard/publications/') + else: + context['form'] = submitted_form + return render(request, 'website/addpublication.html', context) + + form = AddEditPublicationForm() + context['form'] = form + return render(request, 'website/addpublication.html', context) + + +@login_required +def edit_publication(request, publication_id): + # check if user has edit permissions + try: + social = request.user.social_auth.get(provider='github') + access_token = social.extra_data['access_token'] + except: + access_token = '' + if access_token: + has_permission = has_commit_permission(access_token, 'dipy_web') + else: + has_permission = False + + # if user does not have edit permission: + if not has_permission: + return render(request, 'website/editpublication.html', {}) + + # if user has edit permission: + try: + publication = Publication.objects.get( + id=publication_id) + except: + raise Http404("Website Section does not exist") + + context = {} + if request.method == 'POST': + submitted_form = AddEditPublicationForm(request.POST, + instance=publication) + if submitted_form.is_valid(): + submitted_form.save() + return redirect('/dashboard/publications/') + else: + context['form'] = submitted_form + return render(request, 'website/editpublication.html', context) + + form = AddEditPublicationForm(instance=publication) + context['form'] = form + return render(request, 'website/editpublication.html', context) + + # Definition of functons: def has_commit_permission(access_token, repository_name): From a6bc969c2530fb172987aa112eb9e7ea4815f481 Mon Sep 17 00:00:00 2001 From: Bishakh Ghosh Date: Sat, 4 Jun 2016 17:36:04 +0530 Subject: [PATCH 15/52] Bug Fixes Remove unnecessary custom filter loading in templates Remove duplicate registration of youtube_embed_url filter Fix typos --- website/static/css/main.scss | 2 +- website/templates/website/dashboard.html | 1 - website/templates/website/dashboard_news.html | 1 - website/templates/website/dashboard_publications.html | 1 - website/templatetags/customfilters.py | 1 - 5 files changed, 1 insertion(+), 5 deletions(-) diff --git a/website/static/css/main.scss b/website/static/css/main.scss index 29e88c5a..61a18621 100644 --- a/website/static/css/main.scss +++ b/website/static/css/main.scss @@ -55,7 +55,7 @@ img { } -// carousal-main styles +// carousel-main styles .carousel-indicators{ li { border: 1px solid #1a1a1a; diff --git a/website/templates/website/dashboard.html b/website/templates/website/dashboard.html index 701902b7..28d3321b 100644 --- a/website/templates/website/dashboard.html +++ b/website/templates/website/dashboard.html @@ -1,5 +1,4 @@ {% extends "website/base_template.html" %} -{% load customfilters %} {% block content_body %}

    Admin Panel

    diff --git a/website/templates/website/dashboard_news.html b/website/templates/website/dashboard_news.html index 6d24c5ea..a2f72609 100644 --- a/website/templates/website/dashboard_news.html +++ b/website/templates/website/dashboard_news.html @@ -1,5 +1,4 @@ {% extends "website/base_template.html" %} -{% load customfilters %} {% block content_body %}

    Admin Panel

    diff --git a/website/templates/website/dashboard_publications.html b/website/templates/website/dashboard_publications.html index a4f51f2f..c7c84b7b 100644 --- a/website/templates/website/dashboard_publications.html +++ b/website/templates/website/dashboard_publications.html @@ -1,5 +1,4 @@ {% extends "website/base_template.html" %} -{% load customfilters %} {% block content_body %}

    Admin Panel

    diff --git a/website/templatetags/customfilters.py b/website/templatetags/customfilters.py index 974f6b52..e86271ed 100644 --- a/website/templatetags/customfilters.py +++ b/website/templatetags/customfilters.py @@ -4,7 +4,6 @@ register = template.Library() -@register.filter(name='youtube_embed_url') # converts all youtube URLs in the text to embed HTML @register.filter(name='youtube_embed_url') def youtube_embed_url(value): From 54124925bf3422732dfe2531fb1b51f71cbeff16 Mon Sep 17 00:00:00 2001 From: Bishakh Ghosh Date: Sun, 5 Jun 2016 14:46:07 +0530 Subject: [PATCH 16/52] Make views.py a module as it was getting large. --- website/urls.py | 1 + website/views.py | 367 --------------------------- website/views/__init__.py | 4 + website/views/manage_news.py | 96 +++++++ website/views/manage_publications.py | 96 +++++++ website/views/manage_sections.py | 98 +++++++ website/views/pages.py | 30 +++ website/views/tools.py | 65 +++++ 8 files changed, 390 insertions(+), 367 deletions(-) delete mode 100644 website/views.py create mode 100644 website/views/__init__.py create mode 100644 website/views/manage_news.py create mode 100644 website/views/manage_publications.py create mode 100644 website/views/manage_sections.py create mode 100644 website/views/pages.py create mode 100644 website/views/tools.py diff --git a/website/urls.py b/website/urls.py index 45d4c992..7aec5096 100644 --- a/website/urls.py +++ b/website/urls.py @@ -34,6 +34,7 @@ url(r'^dashboard/publications/add/$', views.add_publication, name='add_publication'), + # social login urls url('', include('social.apps.django_app.urls', namespace='social')), ] diff --git a/website/views.py b/website/views.py deleted file mode 100644 index 7ddfc6c3..00000000 --- a/website/views.py +++ /dev/null @@ -1,367 +0,0 @@ -from django.shortcuts import render, redirect -from django.http import Http404 -from django.core.exceptions import ObjectDoesNotExist -from django.contrib.auth.decorators import login_required -from .models import * -from .forms import * -import requests -# Create your views here. - - -def index(request): - context = {} - home_header = get_website_section('home_header') - getting_started = get_website_section('getting_started') - - latest_news = get_latest_news_posts(5) - all_publications = Publication.objects.all() - context['home_header'] = home_header - context['getting_started'] = getting_started - context['latest_news'] = latest_news - context['all_publications'] = all_publications - return render(request, 'website/index.html', context) - - -@login_required -def dashboard(request): - return render(request, 'website/dashboard.html', {}) - - -def dashboard_login(request): - next_url = request.GET.get('next') - return render(request, 'website/dashboard_login.html', {'next': next_url}) - - -@login_required -def dashboard_sections(request): - try: - social = request.user.social_auth.get(provider='github') - access_token = social.extra_data['access_token'] - except: - access_token = '' - has_permission = has_commit_permission(access_token, 'dipy_web') - if has_permission: - all_website_sections = WebsiteSection.objects.all() - context = {'all_sections': all_website_sections} - # if(request.user.has_perm('website.view_section')): - return render(request, 'website/dashboard_sections.html', context) - else: - return render(request, 'website/dashboard_sections.html', {}) - - -@login_required -def edit_website_section(request, position_id): - # check if user has edit permissions - try: - social = request.user.social_auth.get(provider='github') - access_token = social.extra_data['access_token'] - except: - access_token = '' - if access_token: - has_permission = has_commit_permission(access_token, 'dipy_web') - else: - has_permission = False - - # if user does not have edit permission: - if not has_permission: - return render(request, 'website/editsection.html', {}) - - # if user has edit permission: - try: - website_section = WebsiteSection.objects.get( - website_position_id=position_id) - except: - raise Http404("Website Section does not exist") - - context = {} - if request.method == 'POST': - submitted_form = EditWebsiteSectionForm(request.POST, - instance=website_section) - if submitted_form.is_valid(): - submitted_form.save() - return redirect('/dashboard/sections/') - else: - context['website_section'] = website_section - context['form'] = submitted_form - return render(request, 'website/editsection.html', context) - - form = EditWebsiteSectionForm(instance=website_section) - context['website_section'] = website_section - context['form'] = form - return render(request, 'website/editsection.html', context) - - -@login_required -def add_website_section(request): - # check if user has edit permissions - try: - social = request.user.social_auth.get(provider='github') - access_token = social.extra_data['access_token'] - except: - access_token = '' - if access_token: - has_permission = has_commit_permission(access_token, 'dipy_web') - else: - has_permission = False - - # if user does not have edit permission: - if not has_permission: - return render(request, 'website/addsection.html', {}) - - # if user has edit permission: - context = {} - if request.method == 'POST': - submitted_form = AddWebsiteSectionForm(request.POST) - if submitted_form.is_valid(): - submitted_form.save() - return redirect('/dashboard/sections/') - else: - context['form'] = submitted_form - return render(request, 'website/addsection.html', context) - - form = AddWebsiteSectionForm() - context['form'] = form - return render(request, 'website/addsection.html', context) - - -@login_required -def dashboard_news(request): - try: - social = request.user.social_auth.get(provider='github') - access_token = social.extra_data['access_token'] - except: - access_token = '' - has_permission = has_commit_permission(access_token, 'dipy_web') - if has_permission: - all_news_posts = NewsPost.objects.all() - context = {'all_news_posts': all_news_posts} - # if(request.user.has_perm('website.view_section')): - return render(request, 'website/dashboard_news.html', context) - else: - return render(request, 'website/dashboard_news.html', {}) - - -@login_required -def add_news_post(request): - # check if user has edit permissions - try: - social = request.user.social_auth.get(provider='github') - access_token = social.extra_data['access_token'] - except: - access_token = '' - if access_token: - has_permission = has_commit_permission(access_token, 'dipy_web') - else: - has_permission = False - - # if user does not have edit permission: - if not has_permission: - return render(request, 'website/addnews.html', {}) - - # if user has edit permission: - context = {} - if request.method == 'POST': - submitted_form = AddEditNewsPostForm(request.POST) - if submitted_form.is_valid(): - submitted_form.save() - return redirect('/dashboard/news/') - else: - context['form'] = submitted_form - return render(request, 'website/addnews.html', context) - - form = AddEditNewsPostForm() - context['form'] = form - return render(request, 'website/addnews.html', context) - - -@login_required -def edit_news_post(request, news_id): - # check if user has edit permissions - try: - social = request.user.social_auth.get(provider='github') - access_token = social.extra_data['access_token'] - except: - access_token = '' - if access_token: - has_permission = has_commit_permission(access_token, 'dipy_web') - else: - has_permission = False - - # if user does not have edit permission: - if not has_permission: - return render(request, 'website/editnews.html', {}) - - # if user has edit permission: - try: - news_post = NewsPost.objects.get( - id=news_id) - except: - raise Http404("Website Section does not exist") - - context = {} - if request.method == 'POST': - submitted_form = AddEditNewsPostForm(request.POST, - instance=news_post) - if submitted_form.is_valid(): - submitted_form.save() - return redirect('/dashboard/news/') - else: - context['form'] = submitted_form - return render(request, 'website/editnews.html', context) - - form = AddEditNewsPostForm(instance=news_post) - context['form'] = form - return render(request, 'website/editnews.html', context) - - -@login_required -def dashboard_publications(request): - try: - social = request.user.social_auth.get(provider='github') - access_token = social.extra_data['access_token'] - except: - access_token = '' - has_permission = has_commit_permission(access_token, 'dipy_web') - if has_permission: - all_publications = Publication.objects.all() - context = {'all_publications': all_publications} - # if(request.user.has_perm('website.view_section')): - return render(request, 'website/dashboard_publications.html', context) - else: - return render(request, 'website/dashboard_publications.html', {}) - - -@login_required -def add_publication(request): - # check if user has edit permissions - try: - social = request.user.social_auth.get(provider='github') - access_token = social.extra_data['access_token'] - except: - access_token = '' - if access_token: - has_permission = has_commit_permission(access_token, 'dipy_web') - else: - has_permission = False - - # if user does not have edit permission: - if not has_permission: - return render(request, 'website/addpublication.html', {}) - - # if user has edit permission: - context = {} - if request.method == 'POST': - submitted_form = AddEditPublicationForm(request.POST) - if submitted_form.is_valid(): - submitted_form.save() - return redirect('/dashboard/publications/') - else: - context['form'] = submitted_form - return render(request, 'website/addpublication.html', context) - - form = AddEditPublicationForm() - context['form'] = form - return render(request, 'website/addpublication.html', context) - - -@login_required -def edit_publication(request, publication_id): - # check if user has edit permissions - try: - social = request.user.social_auth.get(provider='github') - access_token = social.extra_data['access_token'] - except: - access_token = '' - if access_token: - has_permission = has_commit_permission(access_token, 'dipy_web') - else: - has_permission = False - - # if user does not have edit permission: - if not has_permission: - return render(request, 'website/editpublication.html', {}) - - # if user has edit permission: - try: - publication = Publication.objects.get( - id=publication_id) - except: - raise Http404("Website Section does not exist") - - context = {} - if request.method == 'POST': - submitted_form = AddEditPublicationForm(request.POST, - instance=publication) - if submitted_form.is_valid(): - submitted_form.save() - return redirect('/dashboard/publications/') - else: - context['form'] = submitted_form - return render(request, 'website/editpublication.html', context) - - form = AddEditPublicationForm(instance=publication) - context['form'] = form - return render(request, 'website/editpublication.html', context) - - -# Definition of functons: - -def has_commit_permission(access_token, repository_name): - """ - Determine if user has commit access to the repository in nipy organisation. - - Input - ----- - access_token : string - GitHub access token of user. - repository_name : string - Name of repository to check if user has commit access to it. - """ - if access_token == '': - return False - response = requests.get('https://api.github.com/orgs/nipy/repos', - params={'access_token': access_token}) - response_json = response.json() - for repo in response_json: - if(repo["name"] == repository_name): - permissions = repo["permissions"] - if(permissions["admin"] and - permissions["push"] and - permissions["pull"]): - return True - return False - - -def get_website_section(requested_website_position_id): - """ - Fetch WebsiteSection with website_position_id - - Input - ----- - website_position_id : string - - Output - ------ - returns WebsiteSection object or None if not found - """ - try: - section = WebsiteSection.objects.get( - website_position_id=requested_website_position_id) - except ObjectDoesNotExist: - section = None - return section - - -def get_latest_news_posts(limit): - """ - Fetch Latest NewsPosts according to post_date - - Input - ----- - limit : string - - Output - ------ - returns a list of NewsPost objects - """ - return NewsPost.objects.order_by('-post_date')[0:limit] diff --git a/website/views/__init__.py b/website/views/__init__.py new file mode 100644 index 00000000..c9363277 --- /dev/null +++ b/website/views/__init__.py @@ -0,0 +1,4 @@ +from .pages import * +from .manage_sections import * +from .manage_news import * +from .manage_publications import * diff --git a/website/views/manage_news.py b/website/views/manage_news.py new file mode 100644 index 00000000..335cfb76 --- /dev/null +++ b/website/views/manage_news.py @@ -0,0 +1,96 @@ +from django.shortcuts import render, redirect +from django.contrib.auth.decorators import login_required +from .tools import has_commit_permission +from website.models import NewsPost +from website.forms import AddEditNewsPostForm +from django.http import Http404 + + +@login_required +def dashboard_news(request): + try: + social = request.user.social_auth.get(provider='github') + access_token = social.extra_data['access_token'] + except: + access_token = '' + has_permission = has_commit_permission(access_token, 'dipy_web') + if has_permission: + all_news_posts = NewsPost.objects.all() + context = {'all_news_posts': all_news_posts} + # if(request.user.has_perm('website.view_section')): + return render(request, 'website/dashboard_news.html', context) + else: + return render(request, 'website/dashboard_news.html', {}) + + +@login_required +def add_news_post(request): + # check if user has edit permissions + try: + social = request.user.social_auth.get(provider='github') + access_token = social.extra_data['access_token'] + except: + access_token = '' + if access_token: + has_permission = has_commit_permission(access_token, 'dipy_web') + else: + has_permission = False + + # if user does not have edit permission: + if not has_permission: + return render(request, 'website/addnews.html', {}) + + # if user has edit permission: + context = {} + if request.method == 'POST': + submitted_form = AddEditNewsPostForm(request.POST) + if submitted_form.is_valid(): + submitted_form.save() + return redirect('/dashboard/news/') + else: + context['form'] = submitted_form + return render(request, 'website/addnews.html', context) + + form = AddEditNewsPostForm() + context['form'] = form + return render(request, 'website/addnews.html', context) + + +@login_required +def edit_news_post(request, news_id): + # check if user has edit permissions + try: + social = request.user.social_auth.get(provider='github') + access_token = social.extra_data['access_token'] + except: + access_token = '' + if access_token: + has_permission = has_commit_permission(access_token, 'dipy_web') + else: + has_permission = False + + # if user does not have edit permission: + if not has_permission: + return render(request, 'website/editnews.html', {}) + + # if user has edit permission: + try: + news_post = NewsPost.objects.get( + id=news_id) + except: + raise Http404("Website Section does not exist") + + context = {} + if request.method == 'POST': + submitted_form = AddEditNewsPostForm(request.POST, + instance=news_post) + if submitted_form.is_valid(): + submitted_form.save() + return redirect('/dashboard/news/') + else: + context['form'] = submitted_form + return render(request, 'website/editnews.html', context) + + form = AddEditNewsPostForm(instance=news_post) + context['form'] = form + return render(request, 'website/editnews.html', context) diff --git a/website/views/manage_publications.py b/website/views/manage_publications.py new file mode 100644 index 00000000..3c828936 --- /dev/null +++ b/website/views/manage_publications.py @@ -0,0 +1,96 @@ +from django.shortcuts import render, redirect +from django.contrib.auth.decorators import login_required +from .tools import has_commit_permission +from website.models import Publication +from website.forms import AddEditPublicationForm +from django.http import Http404 + + +@login_required +def dashboard_publications(request): + try: + social = request.user.social_auth.get(provider='github') + access_token = social.extra_data['access_token'] + except: + access_token = '' + has_permission = has_commit_permission(access_token, 'dipy_web') + if has_permission: + all_publications = Publication.objects.all() + context = {'all_publications': all_publications} + # if(request.user.has_perm('website.view_section')): + return render(request, 'website/dashboard_publications.html', context) + else: + return render(request, 'website/dashboard_publications.html', {}) + + +@login_required +def add_publication(request): + # check if user has edit permissions + try: + social = request.user.social_auth.get(provider='github') + access_token = social.extra_data['access_token'] + except: + access_token = '' + if access_token: + has_permission = has_commit_permission(access_token, 'dipy_web') + else: + has_permission = False + + # if user does not have edit permission: + if not has_permission: + return render(request, 'website/addpublication.html', {}) + + # if user has edit permission: + context = {} + if request.method == 'POST': + submitted_form = AddEditPublicationForm(request.POST) + if submitted_form.is_valid(): + submitted_form.save() + return redirect('/dashboard/publications/') + else: + context['form'] = submitted_form + return render(request, 'website/addpublication.html', context) + + form = AddEditPublicationForm() + context['form'] = form + return render(request, 'website/addpublication.html', context) + + +@login_required +def edit_publication(request, publication_id): + # check if user has edit permissions + try: + social = request.user.social_auth.get(provider='github') + access_token = social.extra_data['access_token'] + except: + access_token = '' + if access_token: + has_permission = has_commit_permission(access_token, 'dipy_web') + else: + has_permission = False + + # if user does not have edit permission: + if not has_permission: + return render(request, 'website/editpublication.html', {}) + + # if user has edit permission: + try: + publication = Publication.objects.get( + id=publication_id) + except: + raise Http404("Website Section does not exist") + + context = {} + if request.method == 'POST': + submitted_form = AddEditPublicationForm(request.POST, + instance=publication) + if submitted_form.is_valid(): + submitted_form.save() + return redirect('/dashboard/publications/') + else: + context['form'] = submitted_form + return render(request, 'website/editpublication.html', context) + + form = AddEditPublicationForm(instance=publication) + context['form'] = form + return render(request, 'website/editpublication.html', context) diff --git a/website/views/manage_sections.py b/website/views/manage_sections.py new file mode 100644 index 00000000..68a0bffd --- /dev/null +++ b/website/views/manage_sections.py @@ -0,0 +1,98 @@ +from django.shortcuts import render, redirect +from django.contrib.auth.decorators import login_required +from .tools import has_commit_permission +from website.models import WebsiteSection +from website.forms import EditWebsiteSectionForm, AddWebsiteSectionForm +from django.http import Http404 + + +@login_required +def dashboard_sections(request): + try: + social = request.user.social_auth.get(provider='github') + access_token = social.extra_data['access_token'] + except: + access_token = '' + has_permission = has_commit_permission(access_token, 'dipy_web') + if has_permission: + all_website_sections = WebsiteSection.objects.all() + context = {'all_sections': all_website_sections} + # if(request.user.has_perm('website.view_section')): + return render(request, 'website/dashboard_sections.html', context) + else: + return render(request, 'website/dashboard_sections.html', {}) + + +@login_required +def edit_website_section(request, position_id): + # check if user has edit permissions + try: + social = request.user.social_auth.get(provider='github') + access_token = social.extra_data['access_token'] + except: + access_token = '' + if access_token: + has_permission = has_commit_permission(access_token, 'dipy_web') + else: + has_permission = False + + # if user does not have edit permission: + if not has_permission: + return render(request, 'website/editsection.html', {}) + + # if user has edit permission: + try: + website_section = WebsiteSection.objects.get( + website_position_id=position_id) + except: + raise Http404("Website Section does not exist") + + context = {} + if request.method == 'POST': + submitted_form = EditWebsiteSectionForm(request.POST, + instance=website_section) + if submitted_form.is_valid(): + submitted_form.save() + return redirect('/dashboard/sections/') + else: + context['website_section'] = website_section + context['form'] = submitted_form + return render(request, 'website/editsection.html', context) + + form = EditWebsiteSectionForm(instance=website_section) + context['website_section'] = website_section + context['form'] = form + return render(request, 'website/editsection.html', context) + + +@login_required +def add_website_section(request): + # check if user has edit permissions + try: + social = request.user.social_auth.get(provider='github') + access_token = social.extra_data['access_token'] + except: + access_token = '' + if access_token: + has_permission = has_commit_permission(access_token, 'dipy_web') + else: + has_permission = False + + # if user does not have edit permission: + if not has_permission: + return render(request, 'website/addsection.html', {}) + + # if user has edit permission: + context = {} + if request.method == 'POST': + submitted_form = AddWebsiteSectionForm(request.POST) + if submitted_form.is_valid(): + submitted_form.save() + return redirect('/dashboard/sections/') + else: + context['form'] = submitted_form + return render(request, 'website/addsection.html', context) + + form = AddWebsiteSectionForm() + context['form'] = form + return render(request, 'website/addsection.html', context) diff --git a/website/views/pages.py b/website/views/pages.py new file mode 100644 index 00000000..f3ced4d1 --- /dev/null +++ b/website/views/pages.py @@ -0,0 +1,30 @@ +from django.shortcuts import render +from website.models import * +from django.contrib.auth.decorators import login_required +from .tools import get_website_section, get_latest_news_posts + + +# Definition of views: + +def index(request): + context = {} + home_header = get_website_section('home_header') + getting_started = get_website_section('getting_started') + latest_news = get_latest_news_posts(5) + all_publications = Publication.objects.all() + + context['home_header'] = home_header + context['getting_started'] = getting_started + context['latest_news'] = latest_news + context['all_publications'] = all_publications + return render(request, 'website/index.html', context) + + +@login_required +def dashboard(request): + return render(request, 'website/dashboard.html', {}) + + +def dashboard_login(request): + next_url = request.GET.get('next') + return render(request, 'website/dashboard_login.html', {'next': next_url}) diff --git a/website/views/tools.py b/website/views/tools.py new file mode 100644 index 00000000..e735007d --- /dev/null +++ b/website/views/tools.py @@ -0,0 +1,65 @@ +from website.models import * +import requests + + +# Definition of functions: + +def get_website_section(requested_website_position_id): + """ + Fetch WebsiteSection with website_position_id + + Input + ----- + website_position_id : string + + Output + ------ + returns WebsiteSection object or None if not found + """ + try: + section = WebsiteSection.objects.get( + website_position_id=requested_website_position_id) + except ObjectDoesNotExist: + section = None + return section + + +def get_latest_news_posts(limit): + """ + Fetch Latest NewsPosts according to post_date + + Input + ----- + limit : string + + Output + ------ + returns a list of NewsPost objects + """ + return NewsPost.objects.order_by('-post_date')[0:limit] + + +def has_commit_permission(access_token, repository_name): + """ + Determine if user has commit access to the repository in nipy organisation. + + Input + ----- + access_token : string + GitHub access token of user. + repository_name : string + Name of repository to check if user has commit access to it. + """ + if access_token == '': + return False + response = requests.get('https://api.github.com/orgs/nipy/repos', + params={'access_token': access_token}) + response_json = response.json() + for repo in response_json: + if(repo["name"] == repository_name): + permissions = repo["permissions"] + if(permissions["admin"] and + permissions["push"] and + permissions["pull"]): + return True + return False From 0bb1ca9dc34ce2f73476e06a504db188f635c5a5 Mon Sep 17 00:00:00 2001 From: Bishakh Ghosh Date: Sun, 5 Jun 2016 16:45:45 +0530 Subject: [PATCH 17/52] Make single templete for add/edit news --- .../{editnews.html => addeditnews.html} | 0 website/templates/website/addnews.html | 29 ------------------- website/views/manage_news.py | 12 ++++---- 3 files changed, 6 insertions(+), 35 deletions(-) rename website/templates/website/{editnews.html => addeditnews.html} (100%) delete mode 100644 website/templates/website/addnews.html diff --git a/website/templates/website/editnews.html b/website/templates/website/addeditnews.html similarity index 100% rename from website/templates/website/editnews.html rename to website/templates/website/addeditnews.html diff --git a/website/templates/website/addnews.html b/website/templates/website/addnews.html deleted file mode 100644 index 7da07e42..00000000 --- a/website/templates/website/addnews.html +++ /dev/null @@ -1,29 +0,0 @@ -{% extends "website/base_template.html" %} - -{% load staticfiles %} - -{% block extra_css %} - - -{% endblock %} - -{% block content_body %} - -{% if form %} -
    - {% csrf_token %} - {{ form }} - -
    -{% endif %} - -{% endblock %} - - -{% block extra_js_bottom %} - - - -{% endblock %} diff --git a/website/views/manage_news.py b/website/views/manage_news.py index 335cfb76..053f58e1 100644 --- a/website/views/manage_news.py +++ b/website/views/manage_news.py @@ -38,7 +38,7 @@ def add_news_post(request): # if user does not have edit permission: if not has_permission: - return render(request, 'website/addnews.html', {}) + return render(request, 'website/addeditnews.html', {}) # if user has edit permission: context = {} @@ -49,11 +49,11 @@ def add_news_post(request): return redirect('/dashboard/news/') else: context['form'] = submitted_form - return render(request, 'website/addnews.html', context) + return render(request, 'website/addeditnews.html', context) form = AddEditNewsPostForm() context['form'] = form - return render(request, 'website/addnews.html', context) + return render(request, 'website/addeditnews.html', context) @login_required @@ -71,7 +71,7 @@ def edit_news_post(request, news_id): # if user does not have edit permission: if not has_permission: - return render(request, 'website/editnews.html', {}) + return render(request, 'website/addeditnews.html', {}) # if user has edit permission: try: @@ -89,8 +89,8 @@ def edit_news_post(request, news_id): return redirect('/dashboard/news/') else: context['form'] = submitted_form - return render(request, 'website/editnews.html', context) + return render(request, 'website/addeditnews.html', context) form = AddEditNewsPostForm(instance=news_post) context['form'] = form - return render(request, 'website/editnews.html', context) + return render(request, 'website/addeditnews.html', context) From 71e879fb6274995b791353df921d2aa28b67b085 Mon Sep 17 00:00:00 2001 From: Bishakh Ghosh Date: Mon, 6 Jun 2016 00:18:30 +0530 Subject: [PATCH 18/52] Add publication entry using bibtex --- requirements.txt | 1 + ...blication.html => addeditpublication.html} | 9 +- .../website/addpublicationbibtex.html | 6 ++ .../website/dashboard_publications.html | 4 +- .../templates/website/editpublication.html | 15 --- website/urls.py | 4 +- website/views/manage_publications.py | 95 +++++++++++++++---- 7 files changed, 94 insertions(+), 40 deletions(-) rename website/templates/website/{addpublication.html => addeditpublication.html} (62%) create mode 100644 website/templates/website/addpublicationbibtex.html delete mode 100644 website/templates/website/editpublication.html diff --git a/requirements.txt b/requirements.txt index 647933cf..fabcd56c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,6 +11,7 @@ python3-openid==3.0.10 requests==2.10.0 requests-oauthlib==0.6.1 six==1.10.0 +bibtexparser==0.6.2 # heroku dependencies whitenoise==3.1 diff --git a/website/templates/website/addpublication.html b/website/templates/website/addeditpublication.html similarity index 62% rename from website/templates/website/addpublication.html rename to website/templates/website/addeditpublication.html index 73612d63..163a7dd2 100644 --- a/website/templates/website/addpublication.html +++ b/website/templates/website/addeditpublication.html @@ -1,5 +1,4 @@ {% extends "website/base_template.html" %} - {% load staticfiles %} @@ -7,10 +6,10 @@ {% if form %}
    - {% csrf_token %} - {{ form }} - + {% csrf_token %} + {{ form }} +
    {% endif %} -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/website/templates/website/addpublicationbibtex.html b/website/templates/website/addpublicationbibtex.html new file mode 100644 index 00000000..51c0b252 --- /dev/null +++ b/website/templates/website/addpublicationbibtex.html @@ -0,0 +1,6 @@ +
    +{% csrf_token %} +

    Bibtex:

    + + +
    \ No newline at end of file diff --git a/website/templates/website/dashboard_publications.html b/website/templates/website/dashboard_publications.html index c7c84b7b..de8415bc 100644 --- a/website/templates/website/dashboard_publications.html +++ b/website/templates/website/dashboard_publications.html @@ -5,7 +5,9 @@

    Admin Panel

    Add / Edit Publications

    - + + +
    {% if all_publications %} diff --git a/website/templates/website/editpublication.html b/website/templates/website/editpublication.html deleted file mode 100644 index 91b20381..00000000 --- a/website/templates/website/editpublication.html +++ /dev/null @@ -1,15 +0,0 @@ -{% extends "website/base_template.html" %} -{% load staticfiles %} - - -{% block content_body %} - -{% if form %} -
    - {% csrf_token %} - {{ form }} - -
    -{% endif %} - -{% endblock %} \ No newline at end of file diff --git a/website/urls.py b/website/urls.py index 7aec5096..6fdbd781 100644 --- a/website/urls.py +++ b/website/urls.py @@ -31,8 +31,8 @@ name='dashboard_publications'), url(r'^dashboard/publications/edit/(?P.*?)/$', views.edit_publication, name='edit_publication'), - url(r'^dashboard/publications/add/$', views.add_publication, - name='add_publication'), + url(r'^dashboard/publications/add/(?P.*?)/$', + views.add_publication, name='add_publication'), # social login urls url('', include('social.apps.django_app.urls', namespace='social')), diff --git a/website/views/manage_publications.py b/website/views/manage_publications.py index 3c828936..ab2d7adf 100644 --- a/website/views/manage_publications.py +++ b/website/views/manage_publications.py @@ -4,6 +4,7 @@ from website.models import Publication from website.forms import AddEditPublicationForm from django.http import Http404 +import bibtexparser @login_required @@ -24,7 +25,7 @@ def dashboard_publications(request): @login_required -def add_publication(request): +def add_publication(request, method): # check if user has edit permissions try: social = request.user.social_auth.get(provider='github') @@ -38,22 +39,82 @@ def add_publication(request): # if user does not have edit permission: if not has_permission: - return render(request, 'website/addpublication.html', {}) + return render(request, 'website/addeditpublication.html', {}) # if user has edit permission: - context = {} - if request.method == 'POST': - submitted_form = AddEditPublicationForm(request.POST) - if submitted_form.is_valid(): - submitted_form.save() - return redirect('/dashboard/publications/') - else: - context['form'] = submitted_form - return render(request, 'website/addpublication.html', context) + if(method == "manual"): + context = {} + if request.method == 'POST': + submitted_form = AddEditPublicationForm(request.POST) + if submitted_form.is_valid(): + submitted_form.save() + return redirect('/dashboard/publications/') + else: + context['form'] = submitted_form + return render(request, 'website/addeditpublication.html', + context) - form = AddEditPublicationForm() - context['form'] = form - return render(request, 'website/addpublication.html', context) + form = AddEditPublicationForm() + context['form'] = form + return render(request, 'website/addeditpublication.html', context) + elif(method == "bibtex"): + if request.method == 'POST': + bibtex_entered = request.POST.get('bibtex') + try: + bib_parsed = bibtexparser.loads(bibtex_entered) + bibInfo = bib_parsed.entries[0] + print(bibInfo) + + if 'title' in bibInfo: + title = bibInfo['title'] + else: + title = None + + if 'author' in bibInfo: + authors = bibInfo['author'] + elif 'authors' in bibInfo: + authors = bibInfo['aithors'] + else: + authors = None + + if 'url' in bibInfo: + url = bibInfo['url'] + elif 'link' in bibInfo: + url = bibInfo['link'] + elif 'doi' in bibInfo: + url = "http://dx.doi.org/" + bibInfo['doi'] + else: + url = None + print(url) + + if(title and authors and url): + publicationObj = Publication(title=title, + author=authors, + url=url) + if 'doi' in bibInfo: + publicationObj.doi = bibInfo['doi'] + if 'journal' in bibInfo: + publicationObj.journal = bibInfo['journal'] + if 'publisher' in bibInfo: + publicationObj.publisher = bibInfo['publisher'] + if 'year' in bibInfo: + publicationObj.year_of_publication = bibInfo['year'] + if 'month' in bibInfo: + publicationObj.month_of_publication = bibInfo['month'] + publicationObj.bibtex = bibtex_entered + publicationObj.save() + return redirect('/dashboard/publications/') + + else: + return render(request, + 'website/addpublicationbibtex.html', {}) + except: + return render(request, 'website/addpublicationbibtex.html', {}) + + else: + return render(request, 'website/addpublicationbibtex.html', {}) + else: + raise Http404("Not a valid method for adding publications.") @login_required @@ -71,7 +132,7 @@ def edit_publication(request, publication_id): # if user does not have edit permission: if not has_permission: - return render(request, 'website/editpublication.html', {}) + return render(request, 'website/addeditpublication.html', {}) # if user has edit permission: try: @@ -89,8 +150,8 @@ def edit_publication(request, publication_id): return redirect('/dashboard/publications/') else: context['form'] = submitted_form - return render(request, 'website/editpublication.html', context) + return render(request, 'website/addeditpublication.html', context) form = AddEditPublicationForm(instance=publication) context['form'] = form - return render(request, 'website/editpublication.html', context) + return render(request, 'website/addeditpublication.html', context) From 9d247b61e0f9ff8426d32b670c6e90f2a5521027 Mon Sep 17 00:00:00 2001 From: Bishakh Ghosh Date: Mon, 6 Jun 2016 11:23:26 +0530 Subject: [PATCH 19/52] Remove edit publication from index page --- website/templates/website/index.html | 1 - 1 file changed, 1 deletion(-) diff --git a/website/templates/website/index.html b/website/templates/website/index.html index a8007d77..2331a93d 100644 --- a/website/templates/website/index.html +++ b/website/templates/website/index.html @@ -74,7 +74,6 @@

    Publications

    {% for publication in all_publications %} {{publication.title}}
    {{publication.author}} - Edit
    {% endfor %} From 91f11488b0ce51e956baf4e5d7eb376d6ad7a7be Mon Sep 17 00:00:00 2001 From: Bishakh Ghosh Date: Mon, 6 Jun 2016 12:02:24 +0530 Subject: [PATCH 20/52] Display publications with bibtex in cite page --- website/static/css/main.css | 5 +++++ website/static/css/main.css.map | 2 +- website/static/css/main.scss | 10 ++++++++- website/templates/website/cite.html | 30 +++++++++++++++++++++++++++ website/templates/website/header.html | 3 +++ website/templates/website/index.html | 8 ------- website/urls.py | 3 +++ website/views/pages.py | 9 ++++++-- 8 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 website/templates/website/cite.html diff --git a/website/static/css/main.css b/website/static/css/main.css index f4b4bf4c..efd224fe 100644 --- a/website/static/css/main.css +++ b/website/static/css/main.css @@ -49,4 +49,9 @@ img { .carousel-indicators .active { background: #e5e5e5; } +.publicationBibtex { + display: none; + background: #e9e9e9; + padding: 1em; } + /*# sourceMappingURL=main.css.map */ diff --git a/website/static/css/main.css.map b/website/static/css/main.css.map index 114eba1d..050aa4b2 100644 --- a/website/static/css/main.css.map +++ b/website/static/css/main.css.map @@ -1,6 +1,6 @@ { "version": 3, -"mappings": "AAAA,kBAAmB;EAClB,MAAM,EAAE,KAAK;;AAGd,cAAe;EACd,UAAU,EAAE,IAAI;EAChB,UAAU,EAAE,IAAI;EAChB,aAAa,EAAE,iBAAiB;;AAGjC,kBAAmB;EAClB,SAAS,EAAE,KAAK;EAChB,OAAO,EAAE,WAAW;EACpB,wBAAQ;IACP,UAAU,EAAE,gBAAgB;;AAI9B,cAAe;EACX,QAAQ,EAAE,QAAQ;EAClB,KAAK,EAAE,KAAK;EACZ,OAAO,EAAE,SAAS;EAClB,UAAU,EAAE,IAAI;EAChB,YAAY,EAAE,IAAI;EAClB,aAAa,EAAE,GAAG;EAClB,gBAAgB,EAAE,WAAW;EAC7B,gBAAgB,EAAE,IAAI;EACtB,MAAM,EAAE,qBAAqB;EAC7B,aAAa,EAAE,GAAG;;AAGtB,UAAW;EACP,KAAK,EAAE,IAAI;EACX,YAAY,EAAE,GAAG;;AAIrB,GAAI;EACA,OAAO,EAAE,KAAK;EACd,MAAM,EAAE,MAAM;;AAIlB,cAAe;EACX,OAAO,EAAE,KAAK;EACd,KAAK,EAAE,IAAI;EACX,SAAS,EAAE,KAAK;;AAEpB,gBAAiB;EACb,OAAO,EAAE,KAAK;EACd,SAAS,EAAE,KAAK;EAChB,QAAQ,EAAE,MAAM;EAChB,MAAM,EAAE,MAAM;EACd,UAAU,EAAE,YAAY;;AAMpB,uBAAG;EACC,MAAM,EAAE,iBAAiB;AAG7B,4BAAQ;EACJ,UAAU,EAAE,OAAO", +"mappings": "AAAA,kBAAmB;EAClB,MAAM,EAAE,KAAK;;AAGd,cAAe;EACd,UAAU,EAAE,IAAI;EAChB,UAAU,EAAE,IAAI;EAChB,aAAa,EAAE,iBAAiB;;AAGjC,kBAAmB;EAClB,SAAS,EAAE,KAAK;EAChB,OAAO,EAAE,WAAW;EACpB,wBAAQ;IACP,UAAU,EAAE,gBAAgB;;AAI9B,cAAe;EACX,QAAQ,EAAE,QAAQ;EAClB,KAAK,EAAE,KAAK;EACZ,OAAO,EAAE,SAAS;EAClB,UAAU,EAAE,IAAI;EAChB,YAAY,EAAE,IAAI;EAClB,aAAa,EAAE,GAAG;EAClB,gBAAgB,EAAE,WAAW;EAC7B,gBAAgB,EAAE,IAAI;EACtB,MAAM,EAAE,qBAAqB;EAC7B,aAAa,EAAE,GAAG;;AAGtB,UAAW;EACP,KAAK,EAAE,IAAI;EACX,YAAY,EAAE,GAAG;;AAIrB,GAAI;EACA,OAAO,EAAE,KAAK;EACd,MAAM,EAAE,MAAM;;AAIlB,cAAe;EACX,OAAO,EAAE,KAAK;EACd,KAAK,EAAE,IAAI;EACX,SAAS,EAAE,KAAK;;AAEpB,gBAAiB;EACb,OAAO,EAAE,KAAK;EACd,SAAS,EAAE,KAAK;EAChB,QAAQ,EAAE,MAAM;EAChB,MAAM,EAAE,MAAM;EACd,UAAU,EAAE,YAAY;;AAMpB,uBAAG;EACC,MAAM,EAAE,iBAAiB;AAG7B,4BAAQ;EACJ,UAAU,EAAE,OAAO;;AAM/B,kBAAmB;EACf,OAAO,EAAE,IAAI;EACb,UAAU,EAAE,OAAO;EACnB,OAAO,EAAE,GAAG", "sources": ["main.scss"], "names": [], "file": "main.css" diff --git a/website/static/css/main.scss b/website/static/css/main.scss index 61a18621..fd9d1a7c 100644 --- a/website/static/css/main.scss +++ b/website/static/css/main.scss @@ -64,4 +64,12 @@ img { .active { background: #e5e5e5; } - } \ No newline at end of file + } + +// cite page - publications + +.publicationBibtex { + display: none; + background: #e9e9e9; + padding: 1em; +} \ No newline at end of file diff --git a/website/templates/website/cite.html b/website/templates/website/cite.html new file mode 100644 index 00000000..7011c123 --- /dev/null +++ b/website/templates/website/cite.html @@ -0,0 +1,30 @@ +{% extends "website/base_template.html" %} + +{% block content_body %} + + +

    Publications

    +{% for publication in all_publications %} +
    +

    {{publication.title}}

    +

    {{publication.author}}

    + {% if publication.bibtex %} + Bibtex +

    {{publication.bibtex}}

    + {% endif %} +
    +
    +{% endfor %} + +{% endblock %} + + +{% block extra_js_bottom %} + + +{% endblock %} \ No newline at end of file diff --git a/website/templates/website/header.html b/website/templates/website/header.html index b862d047..693cead0 100644 --- a/website/templates/website/header.html +++ b/website/templates/website/header.html @@ -21,6 +21,9 @@ + diff --git a/website/templates/website/index.html b/website/templates/website/index.html index 2331a93d..be69f61b 100644 --- a/website/templates/website/index.html +++ b/website/templates/website/index.html @@ -69,12 +69,4 @@

    News

    - -

    Publications

    -{% for publication in all_publications %} - {{publication.title}}
    - {{publication.author}} -
    -{% endfor %} - {% endblock %} \ No newline at end of file diff --git a/website/urls.py b/website/urls.py index 6fdbd781..414620bd 100644 --- a/website/urls.py +++ b/website/urls.py @@ -5,6 +5,9 @@ # Home Page url(r'^$', views.index, name='index'), + # Cite Page for publications + url(r'^cite/$', views.cite, name='cite'), + # Admin Panel Dash Board url(r'^dashboard/$', views.dashboard, name='dashboard'), diff --git a/website/views/pages.py b/website/views/pages.py index f3ced4d1..e89851e1 100644 --- a/website/views/pages.py +++ b/website/views/pages.py @@ -11,15 +11,20 @@ def index(request): home_header = get_website_section('home_header') getting_started = get_website_section('getting_started') latest_news = get_latest_news_posts(5) - all_publications = Publication.objects.all() context['home_header'] = home_header context['getting_started'] = getting_started context['latest_news'] = latest_news - context['all_publications'] = all_publications return render(request, 'website/index.html', context) +def cite(request): + context = {} + all_publications = Publication.objects.all() + context['all_publications'] = all_publications + return render(request, 'website/cite.html', context) + + @login_required def dashboard(request): return render(request, 'website/dashboard.html', {}) From 7a3c3d93b1dbc4344e9e6604a409683b3f49ec72 Mon Sep 17 00:00:00 2001 From: Bishakh Ghosh Date: Mon, 6 Jun 2016 14:04:05 +0530 Subject: [PATCH 21/52] Add delete option for publications --- .../website/dashboard_publications.html | 18 +++++++++++-- website/urls.py | 2 ++ website/views/manage_publications.py | 26 ++++++++++++++++++- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/website/templates/website/dashboard_publications.html b/website/templates/website/dashboard_publications.html index de8415bc..e38a3aa6 100644 --- a/website/templates/website/dashboard_publications.html +++ b/website/templates/website/dashboard_publications.html @@ -13,10 +13,24 @@

    Add / Edit Publications

    {% if all_publications %} {% for publication in all_publications %} {{publication.title}}
    - {{publication.author}} - Edit + {{publication.author}}
    + Edit | + Delete
    {% endfor %} {% endif %} +{% endblock %} + +{% block extra_js_bottom %} + + {% endblock %} \ No newline at end of file diff --git a/website/urls.py b/website/urls.py index 414620bd..c761c302 100644 --- a/website/urls.py +++ b/website/urls.py @@ -36,6 +36,8 @@ views.edit_publication, name='edit_publication'), url(r'^dashboard/publications/add/(?P.*?)/$', views.add_publication, name='add_publication'), + url(r'^dashboard/publications/delete/(?P.*?)/$', + views.delete_publication, name='delete_publication'), # social login urls url('', include('social.apps.django_app.urls', namespace='social')), diff --git a/website/views/manage_publications.py b/website/views/manage_publications.py index ab2d7adf..31dcb67a 100644 --- a/website/views/manage_publications.py +++ b/website/views/manage_publications.py @@ -139,7 +139,7 @@ def edit_publication(request, publication_id): publication = Publication.objects.get( id=publication_id) except: - raise Http404("Website Section does not exist") + raise Http404("Publication does not exist") context = {} if request.method == 'POST': @@ -155,3 +155,27 @@ def edit_publication(request, publication_id): form = AddEditPublicationForm(instance=publication) context['form'] = form return render(request, 'website/addeditpublication.html', context) + + +@login_required +def delete_publication(request, publication_id): + # check if user has edit permissions + try: + social = request.user.social_auth.get(provider='github') + access_token = social.extra_data['access_token'] + except: + access_token = '' + if access_token: + has_permission = has_commit_permission(access_token, 'dipy_web') + else: + has_permission = False + + # if user does not have edit permission: + if not has_permission: + return render(request, 'website/addeditpublication.html', {}) + try: + p = Publication.objects.get(id=publication_id) + except: + raise Http404("Publication does not exist") + p.delete() + return redirect('/dashboard/publications/') From 62f6249dd5bb329868e9ca12f07c1c50e4976fa2 Mon Sep 17 00:00:00 2001 From: Bishakh Ghosh Date: Tue, 7 Jun 2016 12:50:37 +0530 Subject: [PATCH 22/52] Add delete link for news --- website/templates/website/dashboard_news.html | 17 +++++++++++-- website/urls.py | 2 ++ website/views/manage_news.py | 24 +++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/website/templates/website/dashboard_news.html b/website/templates/website/dashboard_news.html index a2f72609..d6960561 100644 --- a/website/templates/website/dashboard_news.html +++ b/website/templates/website/dashboard_news.html @@ -11,8 +11,21 @@

    Add / Edit News

    {% for post in all_news_posts %} {{post}}
    {{post.body_html|safe}} -Edit +Edit | Delete
    {% endfor %} -{% endblock %} \ No newline at end of file +{% endblock %} + +{% block extra_js_bottom %} + + +{% endblock %} diff --git a/website/urls.py b/website/urls.py index c761c302..5fb93325 100644 --- a/website/urls.py +++ b/website/urls.py @@ -28,6 +28,8 @@ views.edit_news_post, name='edit_news_post'), url(r'^dashboard/news/add/$', views.add_news_post, name='add_news_post'), + url(r'^dashboard/news/delete/(?P.*?)/$', + views.delete_news_post, name='delete_news_post'), # Publication Management url(r'^dashboard/publications/$', views.dashboard_publications, diff --git a/website/views/manage_news.py b/website/views/manage_news.py index 053f58e1..54b8626f 100644 --- a/website/views/manage_news.py +++ b/website/views/manage_news.py @@ -94,3 +94,27 @@ def edit_news_post(request, news_id): form = AddEditNewsPostForm(instance=news_post) context['form'] = form return render(request, 'website/addeditnews.html', context) + + +@login_required +def delete_news_post(request, news_id): + # check if user has edit permissions + try: + social = request.user.social_auth.get(provider='github') + access_token = social.extra_data['access_token'] + except: + access_token = '' + if access_token: + has_permission = has_commit_permission(access_token, 'dipy_web') + else: + has_permission = False + + # if user does not have edit permission: + if not has_permission: + return render(request, 'website/addeditnews.html', {}) + try: + n = NewsPost.objects.get(id=news_id) + except: + raise Http404("Publication does not exist") + n.delete() + return redirect('/dashboard/news/') From c08b2881b0fddfc3c4fbb87a599b5fb29f8845e7 Mon Sep 17 00:00:00 2001 From: Bishakh Ghosh Date: Tue, 7 Jun 2016 13:02:04 +0530 Subject: [PATCH 23/52] Add is_highlighted field to Publication model --- .../0005_publication_is_highlighted.py | 20 +++++++++++++++++++ website/models.py | 1 + 2 files changed, 21 insertions(+) create mode 100644 website/migrations/0005_publication_is_highlighted.py diff --git a/website/migrations/0005_publication_is_highlighted.py b/website/migrations/0005_publication_is_highlighted.py new file mode 100644 index 00000000..b358c801 --- /dev/null +++ b/website/migrations/0005_publication_is_highlighted.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-06-07 07:31 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('website', '0004_auto_20160604_0343'), + ] + + operations = [ + migrations.AddField( + model_name='publication', + name='is_highlighted', + field=models.BooleanField(default=False), + ), + ] diff --git a/website/models.py b/website/models.py index f1b2ed15..418e47ad 100644 --- a/website/models.py +++ b/website/models.py @@ -106,6 +106,7 @@ class Publication(models.Model): month_of_publication = models.CharField(max_length=10, null=True, blank=True) bibtex = models.TextField(null=True, blank=True) + is_highlighted = models.BooleanField(default=False) created = models.DateTimeField(editable=False, auto_now_add=True) modified = models.DateTimeField(editable=False, auto_now_add=True) From 25c11e52b9ab445b9a1f1c51af3b63d9a3e66fed Mon Sep 17 00:00:00 2001 From: Bishakh Ghosh Date: Tue, 7 Jun 2016 14:12:47 +0530 Subject: [PATCH 24/52] Add highlight publication views --- website/templates/website/cite.html | 2 ++ .../website/dashboard_publications.html | 6 +++- .../website/highlightpublications.html | 20 +++++++++++ website/urls.py | 2 ++ website/views/manage_publications.py | 36 +++++++++++++++++++ website/views/tools.py | 1 + 6 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 website/templates/website/highlightpublications.html diff --git a/website/templates/website/cite.html b/website/templates/website/cite.html index 7011c123..f66e3052 100644 --- a/website/templates/website/cite.html +++ b/website/templates/website/cite.html @@ -6,7 +6,9 @@

    Publications

    {% for publication in all_publications %}
    + {% if publication.is_highlighted %}{% endif %}

    {{publication.title}}

    + {% if publication.is_highlighted %}
    {% endif %}

    {{publication.author}}

    {% if publication.bibtex %} Bibtex diff --git a/website/templates/website/dashboard_publications.html b/website/templates/website/dashboard_publications.html index e38a3aa6..63fc2110 100644 --- a/website/templates/website/dashboard_publications.html +++ b/website/templates/website/dashboard_publications.html @@ -7,12 +7,16 @@

    Add / Edit Publications

    +
    {% if all_publications %} {% for publication in all_publications %} - {{publication.title}}
    + {% if publication.is_highlighted %}{% endif %} + {{publication.title}} + {% if publication.is_highlighted %}{% endif %} +
    {{publication.author}}
    Edit | Delete diff --git a/website/templates/website/highlightpublications.html b/website/templates/website/highlightpublications.html new file mode 100644 index 00000000..3a8794a4 --- /dev/null +++ b/website/templates/website/highlightpublications.html @@ -0,0 +1,20 @@ +{% extends "website/base_template.html" %} +{% load staticfiles %} + +{% block content_body %} + +

    Select Publications to highlight:

    + +
    +{% csrf_token %} + +{% for publication in all_publications %} + {{ publication.title }}
    + {{ publication.author }}

    +{% endfor %} + + +
    + + +{% endblock %} \ No newline at end of file diff --git a/website/urls.py b/website/urls.py index 5fb93325..d38f342b 100644 --- a/website/urls.py +++ b/website/urls.py @@ -40,6 +40,8 @@ views.add_publication, name='add_publication'), url(r'^dashboard/publications/delete/(?P.*?)/$', views.delete_publication, name='delete_publication'), + url(r'^dashboard/publications/highlight/$', + views.highlight_publications, name='highlight_publications'), # social login urls url('', include('social.apps.django_app.urls', namespace='social')), diff --git a/website/views/manage_publications.py b/website/views/manage_publications.py index 31dcb67a..c50bad75 100644 --- a/website/views/manage_publications.py +++ b/website/views/manage_publications.py @@ -5,6 +5,7 @@ from website.forms import AddEditPublicationForm from django.http import Http404 import bibtexparser +from django.core.exceptions import ObjectDoesNotExist @login_required @@ -179,3 +180,38 @@ def delete_publication(request, publication_id): raise Http404("Publication does not exist") p.delete() return redirect('/dashboard/publications/') + + +@login_required +def highlight_publications(request): + # check if user has edit permissions + try: + social = request.user.social_auth.get(provider='github') + access_token = social.extra_data['access_token'] + except: + access_token = '' + if access_token: + has_permission = has_commit_permission(access_token, 'dipy_web') + else: + has_permission = False + + # if user does not have edit permission: + if not has_permission: + return render(request, 'website/addeditpublication.html', {}) + else: + if request.method == 'POST': + highlighted_publications = request.POST.getlist('highlights[]') + all_publications = Publication.objects.all() + + for p in all_publications: + if str(p.id) in highlighted_publications: + p.is_highlighted = True + else: + p.is_highlighted = False + p.save() + return redirect('/dashboard/publications/') + else: + all_publications = Publication.objects.all() + context = {'all_publications': all_publications} + return render(request, 'website/highlightpublications.html', + context) diff --git a/website/views/tools.py b/website/views/tools.py index e735007d..8d48e451 100644 --- a/website/views/tools.py +++ b/website/views/tools.py @@ -1,5 +1,6 @@ from website.models import * import requests +from django.core.exceptions import ObjectDoesNotExist # Definition of functions: From 5cc77b0212a1ba42fa5f7daaebb0a337a2964d89 Mon Sep 17 00:00:00 2001 From: Bishakh Ghosh Date: Wed, 8 Jun 2016 15:56:36 +0530 Subject: [PATCH 25/52] Add highlighted publications to index page --- website/templates/website/index.html | 23 +++++++++++++++++++++++ website/views/pages.py | 2 ++ 2 files changed, 25 insertions(+) diff --git a/website/templates/website/index.html b/website/templates/website/index.html index be69f61b..d4bce2a9 100644 --- a/website/templates/website/index.html +++ b/website/templates/website/index.html @@ -68,5 +68,28 @@

    News

    {% endfor %} +

    Highlighted Publications

    +{% for publication in highlighted_publications %} +
    +

    {{publication.title}}

    +

    {{publication.author}}

    + {% if publication.bibtex %} + Bibtex +

    {{publication.bibtex}}

    + {% endif %} +
    +
    +{% endfor %} + +{% endblock %} + +{% block extra_js_bottom %} + + {% endblock %} \ No newline at end of file diff --git a/website/views/pages.py b/website/views/pages.py index e89851e1..c68f4b38 100644 --- a/website/views/pages.py +++ b/website/views/pages.py @@ -11,10 +11,12 @@ def index(request): home_header = get_website_section('home_header') getting_started = get_website_section('getting_started') latest_news = get_latest_news_posts(5) + highlighted_publications = Publication.objects.filter(is_highlighted=True) context['home_header'] = home_header context['getting_started'] = getting_started context['latest_news'] = latest_news + context['highlighted_publications'] = highlighted_publications return render(request, 'website/index.html', context) From a73066d312000490241bde3600992daa9b21a029 Mon Sep 17 00:00:00 2001 From: Bishakh Ghosh Date: Wed, 8 Jun 2016 17:58:28 +0530 Subject: [PATCH 26/52] Change news view --- website/templates/website/index.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/website/templates/website/index.html b/website/templates/website/index.html index d4bce2a9..6088d354 100644 --- a/website/templates/website/index.html +++ b/website/templates/website/index.html @@ -62,11 +62,11 @@

    {{ getting_started.title }}

    News

    -
    {% endfor %} + From 728c3a2e2291229c357acca48caa5bc6f075400a Mon Sep 17 00:00:00 2001 From: Bishakh Ghosh Date: Sat, 11 Jun 2016 11:35:09 +0530 Subject: [PATCH 30/52] Fix carousel indicators --- website/templates/website/index.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/website/templates/website/index.html b/website/templates/website/index.html index 00858a80..5bdb16e2 100644 --- a/website/templates/website/index.html +++ b/website/templates/website/index.html @@ -7,9 +7,9 @@ {% endblock %} \ No newline at end of file diff --git a/website/templates/website/index.html b/website/templates/website/index.html index f4c53d5b..fb46d7c3 100644 --- a/website/templates/website/index.html +++ b/website/templates/website/index.html @@ -1,82 +1,120 @@ {% extends "website/base_template.html" %} +{% load staticfiles %} {% load customfilters %} {% block content_body %} +
    +
    + +