Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development2 #13

Merged
merged 27 commits into from
Aug 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8029bc9
Keep API key in settings
ghoshbishakh Jul 12, 2016
a1039ab
Add google analytics snippet to all views
ghoshbishakh Jul 14, 2016
463d83f
Add news post view to share news posts
ghoshbishakh Jul 16, 2016
4d83009
Add social share button to news feeds
ghoshbishakh Jul 16, 2016
fe27fc0
Clear cache on model edits
ghoshbishakh Jul 16, 2016
520e18c
Use thicker fonts for better readibility
ghoshbishakh Jul 17, 2016
2dc960a
Fix navbar collapse css issue
ghoshbishakh Jul 17, 2016
e7f764c
Fix css error
ghoshbishakh Jul 18, 2016
fc9b244
Shrink navbar properly on smaller screens
ghoshbishakh Jul 18, 2016
616b200
Add custom 404 and 500 error pages
ghoshbishakh Jul 20, 2016
553e623
Fix error pages markup
ghoshbishakh Jul 20, 2016
ab6a8e3
Add meta tags to error pages
ghoshbishakh Jul 20, 2016
53a0a5d
Add youtube gallery
ghoshbishakh Jul 21, 2016
a9741f0
Add simple visualization using D3
ghoshbishakh Jul 22, 2016
263bd85
Fix navbar overflow in mobile devices
ghoshbishakh Jul 23, 2016
a45ae28
Raise 404 when section is not found
ghoshbishakh Jul 23, 2016
9607ce9
Make a separate follow us page for all social feeds.
ghoshbishakh Jul 24, 2016
2ce32b4
Use first paragraph for meta description
ghoshbishakh Jul 24, 2016
a26c2be
Generate gallery from examples
ghoshbishakh Jul 25, 2016
f4e14f4
Use example images in honeycomb
ghoshbishakh Jul 26, 2016
5e5a33e
Add tutorials page
ghoshbishakh Jul 28, 2016
f060a1c
Add Sections in the tutorials page
ghoshbishakh Aug 2, 2016
ca2eb45
Fix duplicate tutorials bug
ghoshbishakh Aug 2, 2016
3c286e8
Toggle turotials page sections
ghoshbishakh Aug 5, 2016
eb89a2c
Change toggle speed for tutorial page sections
ghoshbishakh Aug 5, 2016
a0ab514
Update docstrings in methods for parsing tutorials
ghoshbishakh Aug 5, 2016
c5f563a
Fix docstrings in tools.py
ghoshbishakh Aug 10, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion dipy_web/settings.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'social.apps.django_app.default',
'meta',
'website'
'website',
'github_visualization'
]

MIDDLEWARE_CLASSES = [
Expand Down Expand Up @@ -74,6 +75,7 @@ TEMPLATES = [
'social.apps.django_app.context_processors.backends',
'social.apps.django_app.context_processors.login_redirect',
'website.context_processor.nav_pages_processor',
'website.context_processor.google_analytics_processor',
],
},
},
Expand Down Expand Up @@ -155,6 +157,9 @@ STATICFILES_DIRS = (

LOGIN_URL = '/dashboard/login'

# Google Analytics
GOOGLE_ANALYTICS_TRACKING_ID = ''

# documentation repository settings
DOCUMENTATION_REPO_OWNER = 'ghoshbishakh'
DOCUMENTATION_REPO_NAME = 'dipy_web'
Expand All @@ -167,6 +172,9 @@ FACEBOOK_APP_SECRET = ''
TWITTER_CONSUMER_KEY = ''
TWITTER_CONSUMER_SECRET = ''

# google API keys
GOOGLE_API_KEY = ''

# default meta information
DEFAULT_TITLE = "DIPY - Diffusion Imaging In Python"
DEFAULT_DESCRIPTION = """Dipy is a free and open source software
Expand Down
4 changes: 4 additions & 0 deletions dipy_web/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('website.urls')),
url(r'^', include('github_visualization.urls')),
]

handler404 = 'website.views.custom404'
Copy link
Collaborator

Choose a reason for hiding this comment

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

For my info, those do not seem to be added to url_patterns. Are those names (handler404 and 500) reserved words?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes handler404 and handler500 are reserved words. Django performs some kind of magic with them and renders the views assigned to them in case of 404 or 500.

handler500 = 'website.views.custom500'
Empty file.
3 changes: 3 additions & 0 deletions github_visualization/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions github_visualization/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class GithubVisualizationConfig(AppConfig):
name = 'github_visualization'
Empty file.
3 changes: 3 additions & 0 deletions github_visualization/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
8 changes: 8 additions & 0 deletions github_visualization/static/js/d3.min.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{% load staticfiles %}

<!doctype html>
<html>
<head>
<script type="text/javascript" src="{% static "js/d3.min.js" %}"></script>
</head>
<body>
<div id="vizcontainer">
<svg style="width:100%;height:500px;border:1px lightgray solid;" />
</div>
</body>

<script type="text/javascript">
var contributors = {{ contributors|safe }};

var yScale = d3.scaleLinear().domain([0,contributors[0].contributions]).range([4,40]);

function contributors_viz(contributorData) {
d3.select("svg")
.append("g")
.attr("id", "contributorsG")
.attr("transform", "translate(50,300)")
.selectAll("g")
.data(contributorData)
.enter()
.append("g")
.attr("class", "contributorG")
.attr("transform", function (d,i) {return "translate(" + (i * 40) + ", " + -yScale(d.contributions) * 6 + ")"});

var contributorG = d3.selectAll("g.contributorG");

contributorG.append("circle")
.attr("r", function(d,i){ return yScale(d.contributions);})
.style("fill", "pink")
.style("stroke", "black")
.style("stroke-width", "1px");

contributorG.append("text")
.style("text-anchor", "middle")
.attr("y", 30)
.style("font-size", "10px")
.text(function(d) {return d.login;});

contributorG.insert("image", "text")
.attr("xlink:href", function(d) {
return d.avatar_url;
})
.attr("width", "45px").attr("height", "20px").attr("x", "-22")
.attr("y", "-10");
}

contributors_viz(contributors);

</script>

</html>
3 changes: 3 additions & 0 deletions github_visualization/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
14 changes: 14 additions & 0 deletions github_visualization/tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import requests


def fetch_all_contributors(user, repo):
try:
response = requests.get(
"https://api.github.com/repos/%s/%s/contributors" %
(user, repo))
if response.status_code != 200:
return None
response = response.text
return response
except:
return None
9 changes: 9 additions & 0 deletions github_visualization/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.conf.urls import include, url
from . import views

urlpatterns = [
# Home Page
url(r'^contributors$', views.contributors_bubble,
name='contributors_bubble'),

]
12 changes: 12 additions & 0 deletions github_visualization/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.shortcuts import render
from .tools import *


# Create your views here.

def contributors_bubble(request):
context = {}
context['contributors'] = fetch_all_contributors('nipy', 'dipy')
return render(request,
'github_visualization/contributors_bubble.html',
context)
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ requests==2.10.0
requests-oauthlib==0.6.1
six==1.10.0
bibtexparser==0.6.2
beautifulsoup4==4.5.0
django-meta==1.3

# heroku dependencies
whitenoise==3.1
dj-database-url==0.4.1
gunicorn==19.5.0
psycopg2==2.6.1
django-meta==1.3
17 changes: 17 additions & 0 deletions website/context_processor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.conf import settings

from .models import WebsiteSection, DocumentationLink


Expand All @@ -6,3 +8,18 @@ def nav_pages_processor(request):
show_in_nav=True)
all_doc_displayed = DocumentationLink.objects.filter(displayed=True)
return {'pages_in_nav': pages, 'all_doc_displayed': all_doc_displayed}


def google_analytics_processor(request):
tracking_id = settings.GOOGLE_ANALYTICS_TRACKING_ID
tracking_code = """<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', '%s', 'auto');
ga('send', 'pageview');

</script>""" % (tracking_id,)
return {'google_analytics': tracking_code}
2 changes: 1 addition & 1 deletion website/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Meta:
class AddEditNewsPostForm(ModelForm):
class Meta:
model = NewsPost
fields = ['title', 'body_markdown', 'post_date']
fields = ['title', 'body_markdown', 'post_date', 'description']


class AddEditPublicationForm(ModelForm):
Expand Down
21 changes: 21 additions & 0 deletions website/migrations/0014_newspost_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-07-16 06:02
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('website', '0013_carouselimage_display_description'),
]

operations = [
migrations.AddField(
model_name='newspost',
name='description',
field=models.CharField(default='sample description', max_length=140),
preserve_default=False,
),
]
18 changes: 18 additions & 0 deletions website/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.db import models
from django.contrib.auth.models import User
from django.core.cache import cache
from django.utils import timezone
import markdown
import bleach
Expand Down Expand Up @@ -68,6 +69,10 @@ def save(self, *args, **kwargs):
self.body_html = bleach.clean(html_content, allowed_html_tags,
allowed_attrs)
self.modified = datetime.datetime.now()

# clear the cache
cache.clear()

# Call the "real" save() method.
super(WebsiteSection, self).save(*args, **kwargs)

Expand All @@ -79,6 +84,7 @@ class NewsPost(models.Model):
title = models.CharField(max_length=200)
body_markdown = models.TextField()
body_html = models.TextField(editable=False)
description = models.CharField(max_length=140)
post_date = models.DateTimeField(default=timezone.now)
created = models.DateTimeField(editable=False, auto_now_add=True)
modified = models.DateTimeField(editable=False, auto_now_add=True)
Expand All @@ -91,6 +97,10 @@ def save(self, *args, **kwargs):
self.body_html = bleach.clean(html_content, allowed_html_tags,
allowed_attrs)
self.modified = datetime.datetime.now()

# clear the cache
cache.clear()

# Call the "real" save() method.
super(NewsPost, self).save(*args, **kwargs)

Expand Down Expand Up @@ -123,6 +133,10 @@ class Publication(models.Model):

def save(self, *args, **kwargs):
self.modified = datetime.datetime.now()

# clear the cache
cache.clear()

# Call the "real" save() method.
super(Publication, self).save(*args, **kwargs)

Expand All @@ -145,6 +159,10 @@ class CarouselImage(models.Model):

def save(self, *args, **kwargs):
self.modified = datetime.datetime.now()

# clear the cache
cache.clear()

# Call the "real" save() method.
super(CarouselImage, self).save(*args, **kwargs)

Expand Down
Loading