Skip to content

Commit

Permalink
add csv download of connections
Browse files Browse the repository at this point in the history
  • Loading branch information
wabarr committed Jan 4, 2016
1 parent e679b88 commit 5dbcffa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions academicPhylogeny/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
url(r'^detail/$', search),
url(r'^support/$',support),
url(r'^ajax_login/',ajax_login),
url(r'^connectionsCSV', connections_CSV),
url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}),


Expand Down
16 changes: 16 additions & 0 deletions academicPhylogeny/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from django.utils.datastructures import MultiValueDictKeyError
from django.core.mail import send_mail
import datetime
import csv
from django.utils.timezone import utc
from django.db.models import Count,Min,Max
from collections import Counter
Expand Down Expand Up @@ -44,6 +45,21 @@ def schoolSearch(searchstring):
matches=school.objects.filter(query)
return matches

def connections_CSV(request):
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="phd_connections.csv"'
writer = csv.writer(response)
allConnections = connection.objects.order_by('advisor__lastName')
writer.writerow(['Advisors', 'Student Last', 'Student First', 'Year', 'School', 'Specialization'], )
for conn in allConnections:
writer.writerow([conn.advisor_name().encode('utf8'),
conn.student_Last_Name().encode('utf8'),
conn.student_First_Name().encode('utf8'),
conn.student_Year_Of_PhD(),
conn.student.school.name.encode('utf8'),
' / '.join([special.name for special in conn.student.specialization.all()]),])
return response

def connections_JSON(request):
#first get text data
allConnections = connection.objects.order_by('advisor__lastName')
Expand Down

0 comments on commit 5dbcffa

Please sign in to comment.