Skip to content

Commit 25d6c3f

Browse files
committed
Merged Damons branch. Added data to the home.html. Added a few images that are used in the home.html. Added correct contact info that will be added later. Fixed formatting on the discussions.html that Dan and Damon added and added back in the little LinkedIn javascript box.
2 parents e2618f8 + 2b47055 commit 25d6c3f

File tree

17 files changed

+200
-69
lines changed

17 files changed

+200
-69
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.pyc
22
db.sqlite3
3+
.coverage
34
.DS_Store

mep_django/linkedin/.tests.py.swp

20 KB
Binary file not shown.

mep_django/linkedin/.views.py.swp

12 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"pk": 1, "model": "contenttypes.contenttype", "fields": {"model": "logentry", "name": "log entry", "app_label": "admin"}}, {"pk": 2, "model": "contenttypes.contenttype", "fields": {"model": "permission", "name": "permission", "app_label": "auth"}}, {"pk": 3, "model": "contenttypes.contenttype", "fields": {"model": "group", "name": "group", "app_label": "auth"}}, {"pk": 4, "model": "contenttypes.contenttype", "fields": {"model": "user", "name": "user", "app_label": "auth"}}, {"pk": 5, "model": "contenttypes.contenttype", "fields": {"model": "contenttype", "name": "content type", "app_label": "contenttypes"}}, {"pk": 6, "model": "contenttypes.contenttype", "fields": {"model": "session", "name": "session", "app_label": "sessions"}}, {"pk": 7, "model": "contenttypes.contenttype", "fields": {"model": "usersocialauth", "name": "user social auth", "app_label": "default"}}, {"pk": 8, "model": "contenttypes.contenttype", "fields": {"model": "nonce", "name": "nonce", "app_label": "default"}}, {"pk": 9, "model": "contenttypes.contenttype", "fields": {"model": "association", "name": "association", "app_label": "default"}}, {"pk": 10, "model": "contenttypes.contenttype", "fields": {"model": "code", "name": "code", "app_label": "default"}}, {"pk": "dzkr27fac575ng757f7tm1vip13wsu5w", "model": "sessions.session", "fields": {"expire_date": "2014-05-23T22:17:37.060Z", "session_data": "MWQ5ZTAzY2QwZWZiNzE4MDhiZjFiYWVkNmE3NDYwOGU0NTczYmQwMjp7fQ=="}}, {"pk": 1, "model": "auth.permission", "fields": {"codename": "add_logentry", "name": "Can add log entry", "content_type": 1}}, {"pk": 2, "model": "auth.permission", "fields": {"codename": "change_logentry", "name": "Can change log entry", "content_type": 1}}, {"pk": 3, "model": "auth.permission", "fields": {"codename": "delete_logentry", "name": "Can delete log entry", "content_type": 1}}, {"pk": 4, "model": "auth.permission", "fields": {"codename": "add_permission", "name": "Can add permission", "content_type": 2}}, {"pk": 5, "model": "auth.permission", "fields": {"codename": "change_permission", "name": "Can change permission", "content_type": 2}}, {"pk": 6, "model": "auth.permission", "fields": {"codename": "delete_permission", "name": "Can delete permission", "content_type": 2}}, {"pk": 7, "model": "auth.permission", "fields": {"codename": "add_group", "name": "Can add group", "content_type": 3}}, {"pk": 8, "model": "auth.permission", "fields": {"codename": "change_group", "name": "Can change group", "content_type": 3}}, {"pk": 9, "model": "auth.permission", "fields": {"codename": "delete_group", "name": "Can delete group", "content_type": 3}}, {"pk": 10, "model": "auth.permission", "fields": {"codename": "add_user", "name": "Can add user", "content_type": 4}}, {"pk": 11, "model": "auth.permission", "fields": {"codename": "change_user", "name": "Can change user", "content_type": 4}}, {"pk": 12, "model": "auth.permission", "fields": {"codename": "delete_user", "name": "Can delete user", "content_type": 4}}, {"pk": 13, "model": "auth.permission", "fields": {"codename": "add_contenttype", "name": "Can add content type", "content_type": 5}}, {"pk": 14, "model": "auth.permission", "fields": {"codename": "change_contenttype", "name": "Can change content type", "content_type": 5}}, {"pk": 15, "model": "auth.permission", "fields": {"codename": "delete_contenttype", "name": "Can delete content type", "content_type": 5}}, {"pk": 16, "model": "auth.permission", "fields": {"codename": "add_session", "name": "Can add session", "content_type": 6}}, {"pk": 17, "model": "auth.permission", "fields": {"codename": "change_session", "name": "Can change session", "content_type": 6}}, {"pk": 18, "model": "auth.permission", "fields": {"codename": "delete_session", "name": "Can delete session", "content_type": 6}}, {"pk": 19, "model": "auth.permission", "fields": {"codename": "add_usersocialauth", "name": "Can add user social auth", "content_type": 7}}, {"pk": 20, "model": "auth.permission", "fields": {"codename": "change_usersocialauth", "name": "Can change user social auth", "content_type": 7}}, {"pk": 21, "model": "auth.permission", "fields": {"codename": "delete_usersocialauth", "name": "Can delete user social auth", "content_type": 7}}, {"pk": 22, "model": "auth.permission", "fields": {"codename": "add_nonce", "name": "Can add nonce", "content_type": 8}}, {"pk": 23, "model": "auth.permission", "fields": {"codename": "change_nonce", "name": "Can change nonce", "content_type": 8}}, {"pk": 24, "model": "auth.permission", "fields": {"codename": "delete_nonce", "name": "Can delete nonce", "content_type": 8}}, {"pk": 25, "model": "auth.permission", "fields": {"codename": "add_association", "name": "Can add association", "content_type": 9}}, {"pk": 26, "model": "auth.permission", "fields": {"codename": "change_association", "name": "Can change association", "content_type": 9}}, {"pk": 27, "model": "auth.permission", "fields": {"codename": "delete_association", "name": "Can delete association", "content_type": 9}}, {"pk": 28, "model": "auth.permission", "fields": {"codename": "add_code", "name": "Can add code", "content_type": 10}}, {"pk": 29, "model": "auth.permission", "fields": {"codename": "change_code", "name": "Can change code", "content_type": 10}}, {"pk": 30, "model": "auth.permission", "fields": {"codename": "delete_code", "name": "Can delete code", "content_type": 10}}, {"pk": 1, "model": "auth.user", "fields": {"username": "admin", "first_name": "", "last_name": "", "is_active": true, "is_superuser": true, "is_staff": true, "last_login": "2014-05-09T22:14:39.972Z", "groups": [], "user_permissions": [], "password": "pbkdf2_sha256$12000$wpBJqRTP8ZrW$I3zVXGsBOENWKjAjJdsk8tYn/VuPBmbi+1FtB+yc2Fk=", "email": "", "date_joined": "2014-05-09T22:10:22.457Z"}}, {"pk": 2, "model": "auth.user", "fields": {"username": "test", "first_name": "", "last_name": "", "is_active": true, "is_superuser": false, "is_staff": false, "last_login": "2014-05-09T22:15:29.777Z", "groups": [], "user_permissions": [], "password": "pbkdf2_sha256$12000$ILarHukbgsYh$MRZfNyDZGcUfynQYZMVRDRQ+92jsjTSXqHWjm9+Z4JM=", "email": "", "date_joined": "2014-05-09T22:15:29.777Z"}}, {"pk": 1, "model": "default.usersocialauth", "fields": {"uid": "test uid", "extra_data": "{}", "user": 2, "provider": "test provider"}}, {"pk": 1, "model": "admin.logentry", "fields": {"action_flag": 1, "action_time": "2014-05-09T22:15:29.937Z", "object_repr": "test", "object_id": "2", "change_message": "", "user": 1, "content_type": 4}}, {"pk": 2, "model": "admin.logentry", "fields": {"action_flag": 1, "action_time": "2014-05-09T22:17:10.493Z", "object_repr": "UserSocialAuth object", "object_id": "1", "change_message": "", "user": 1, "content_type": 7}}]

mep_django/linkedin/models.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
from django.db import models
22

3-
# Create your models here.
4-
'''from django.contrib.auth.models import AbstractUser, UserManager
5-
3+
#from django.contrib.auth.models import AbstractUser, UserManager
64

5+
'''
76
class CustomUser(AbstractUser):
87
objects = UserManager()
9-
'''
10-
118
129
class GroupPost(models.Model):
1310
title = models.CharField(max_length = 500)
1411
summary = models.TextField()
1512
creation_timestamp = models.BigIntegerField()
1613
db_timestamp = models.DateField(auto_now_add = True)
1714
site_group_post_url = models.URLField()
15+
'''
1816

3.09 KB
Loading
Loading
55.8 KB
Loading

mep_django/linkedin/tests.py

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,100 @@
11
from django.test import TestCase
2+
import views
3+
from django.core.urlresolvers import resolve
4+
from django.template.loader import render_to_string
5+
from django.http import HttpRequest
6+
7+
class TestHomeView(TestCase):
8+
'''Unit test for the home view'''
9+
def setUp(self):
10+
self.MY_URL = '/'
11+
12+
def test_found_right_view(self):
13+
'''Test that the URL maps to the right view function'''
14+
self.assertEqual(resolve(self.MY_URL).func, views.home)
15+
16+
def test_status_200(self):
17+
'''Return status 200 upon GET request'''
18+
response = self.client.get(self.MY_URL)
19+
self.assertEqual(response.status_code, 200)
20+
21+
"""
22+
class TestNewsView(TestCase):
23+
'''Unit test for the news view'''
24+
25+
fixtures = ['fix1.json']
26+
27+
def setUp(self):
28+
self.MY_URL = '/news/'
29+
30+
def test_status_403(self):
31+
'''Return status 403 upon GET request when user is not logged in'''
32+
response = self.client.get(self.MY_URL)
33+
self.assertEqual(response.status_code, 403)
34+
35+
def test_status_200(self):
36+
'''Return status 200 upon GET request when user IS logged in'''
37+
self.client.login(username='test', password='pass')
38+
response = self.client.get(self.MY_URL)
39+
self.assertEqual(response.status_code, 200)
40+
"""
41+
42+
class TestDiscussionsView(TestCase):
43+
'''Unit test for the home view'''
44+
45+
#fixtures = [ 'fix1.json' ]
46+
47+
def setUp(self):
48+
self.MY_URL = '/discussions/'
49+
50+
def test_found_right_view(self):
51+
'''Test that the URL maps to the right view function'''
52+
self.assertEqual(resolve(self.MY_URL).func, views.discussions)
53+
54+
def test_status_403(self):
55+
'''Return status 403 upon GET request when user is not logged in'''
56+
response = self.client.get(self.MY_URL)
57+
self.assertEqual(response.status_code, 403)
58+
59+
class TestNewsView(TestCase):
60+
'''Unit test for the home view'''
61+
def setUp(self):
62+
self.MY_URL = '/news/'
63+
64+
def test_found_right_view(self):
65+
'''Test that the URL maps to the right view function'''
66+
self.assertEqual(resolve(self.MY_URL).func, views.news)
67+
68+
def test_status_403(self):
69+
'''Return status 403 upon GET request when user is not logged in'''
70+
response = self.client.get(self.MY_URL)
71+
self.assertEqual(response.status_code, 403)
72+
73+
class TestAboutView(TestCase):
74+
'''Unit test for the about view'''
75+
def setUp(self):
76+
self.MY_URL = '/about/'
77+
78+
def test_found_right_view(self):
79+
'''Test that the URL maps to the right view function'''
80+
self.assertEqual(resolve(self.MY_URL).func, views.about)
81+
82+
def test_status_200(self):
83+
'''Return status 200 upon GET request'''
84+
response = self.client.get(self.MY_URL)
85+
self.assertEqual(response.status_code, 200)
86+
87+
class TestContactView(TestCase):
88+
'''Unit test for the contact view'''
89+
def setUp(self):
90+
self.MY_URL = '/contact/'
91+
92+
def test_found_right_view(self):
93+
'''Test that the URL maps to the right view function'''
94+
self.assertEqual(resolve(self.MY_URL).func, views.contact)
95+
96+
def test_status_200(self):
97+
'''Return status 200 upon GET request'''
98+
response = self.client.get(self.MY_URL)
99+
self.assertEqual(response.status_code, 200)
2100

3-
# Create your tests here.

mep_django/linkedin/views.py

Lines changed: 30 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from django.shortcuts import redirect, render
22
from django.contrib.auth import logout as auth_logout
3-
from social.apps.django_app.default.models import UserSocialAuth
43
from linkedin import linkedin
5-
#from django.http import HttpResponse
4+
from django.core.exceptions import PermissionDenied
65

6+
API_KEY = '75l485e9k29snc'
7+
API_SECRET = 'iw7fONMpJZcY5HOb'
78

89
def logout(request):
910
"""logs the user out, then redirects to the home page"""
@@ -14,7 +15,6 @@ def home(request):
1415
"""displays the home page"""
1516
return render(request, 'home.html', {})
1617

17-
1818
def about(request):
1919
"""displays the about page"""
2020
return render(request, 'about.html', {})
@@ -23,12 +23,10 @@ def contact(request):
2323
"""displays the contact page"""
2424
return render(request, 'contact.html', {})
2525

26-
2726
def temp(request):
2827
"""this is used for the popup window which houses the linkedin login page"""
2928
return render(request, 'temp.html', {})
3029

31-
3230
def profile(request):
3331
"""displays the user's profile page"""
3432
if request.user.is_authenticated():
@@ -53,40 +51,39 @@ def profile(request):
5351

5452
def get_access_tokens(user):
5553
"""Query user database to retrieve OAuth1 access tokens for the currently logged-in user"""
54+
55+
def get_app(user):
56+
"""Given a valid user object, return a LinkedInApplication instance that can be used to make the Linkedin API calls"""
57+
# Query user database to retrieve OAuth1 access tokens for the currently logged-in user"""
5658
social_user = user.social_auth.get()
5759
OAUTH_USER_TOKEN = social_user.extra_data['access_token']['oauth_token']
58-
OAUTH_USER_TOKEN_SECRET = social_user.extra_data['access_token']['oauth_token_secret']
59-
return (OAUTH_USER_TOKEN, OAUTH_USER_TOKEN_SECRET)
60+
OAUTH_USER_TOKEN_SECRET = social_user.extra_data['access_token']['oauth_token_secret']
61+
auth = linkedin.LinkedInDeveloperAuthentication(API_KEY, API_SECRET, OAUTH_USER_TOKEN, OAUTH_USER_TOKEN_SECRET, '', linkedin.PERMISSIONS.enums.values())
62+
return linkedin.LinkedInApplication(auth)
6063

61-
def news(request):
62-
"""Diplays the LinkedIn content, this is the critical view of the app"""
63-
64-
if not request.user.is_authenticated():
65-
return redirect('home')
66-
67-
API_KEY = '75l485e9k29snc'
68-
API_SECRET = 'iw7fONMpJZcY5HOb'
69-
USER_KEY, USER_SECRET = get_access_tokens(request.user)
70-
64+
def discussions(request):
65+
"""Displays the LinkedIn group content"""
66+
# handle unauthorized access with a 403
67+
if not request.user.is_authenticated() or not request.user.is_active:
68+
raise PermissionDenied
69+
# this is the ID of the linkedin group
7170
GROUP_ID = 1627067
72-
COMPANY_ID = 1035
73-
7471
POST_SELECTORS = ['title', 'summary', 'creation-timestamp', 'site-group-post-url', 'creator', 'id',]
75-
COMPANY_SELECTORS = ['name', 'id']
76-
77-
auth = linkedin.LinkedInDeveloperAuthentication(API_KEY, API_SECRET, USER_KEY, USER_SECRET, '', linkedin.PERMISSIONS.enums.values())
78-
app = linkedin.LinkedInApplication(auth)
79-
72+
app = get_app(request.user)
8073
group_posts = app.get_posts(GROUP_ID, selectors=POST_SELECTORS)
81-
74+
return render(request, 'discussions.html', {'post_list':group_posts['values'],})
75+
76+
def news(request):
77+
"""Diplays the LinkedIn company content, this is the critical view of the app"""
78+
# handle unauthorized access with a 403
79+
if not request.user.is_authenticated() or not request.user.is_active:
80+
raise PermissionDenied
81+
COMPANY_ID = 1035
82+
COMPANY_SELECTORS = ['name', 'id']
83+
app = get_app(request.user)
8284
company = app.get_companies(company_ids=[COMPANY_ID], selectors=COMPANY_SELECTORS, params={'is-company-admin': 'true'})
83-
84-
updates = app.get_company_updates(COMPANY_ID, params={'count': 10, 'event-type': 'status-update',})
85-
86-
import pprint
87-
pp = pprint.PrettyPrinter(indent=2)
88-
89-
pp.pprint(updates['values'])
85+
count = 10
86+
updates = app.get_company_updates(COMPANY_ID, params={'count': count, 'event-type': 'status-update',})
9087

9188
update_list = []
9289
for update in updates['values']:
@@ -98,21 +95,4 @@ def news(request):
9895
my_dict['shortenedUrl'] = update['updateContent']['companyStatusUpdate']['share']['content'].get('shortenedUrl')
9996
update_list.append(my_dict)
10097

101-
102-
103-
104-
'''
105-
for post in group_posts['values']:
106-
for k, v in post.iteritems():
107-
if k == 'creator':
108-
print 'Creator{'
109-
for k2, v2 in post['creator'].iteritems():
110-
print '\t' + str(k2) + ': '
111-
print '\t' + str(v2) + '\n'
112-
print '}'
113-
else:
114-
print str(k) + ': '
115-
print str(v) + '\n'
116-
#raw_input()
117-
'''
118-
return render(request, 'news.html', {'post_list':group_posts['values'], 'update_list': update_list})
98+
return render(request, 'news.html', {'update_list': update_list,})

mep_django/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@
4444
'django.contrib.staticfiles',
4545
'social.apps.django_app.default', # added by chad
4646
'mep_django.linkedin', # added by chad
47+
'django_nose',
4748
)
4849

50+
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
51+
4952
MIDDLEWARE_CLASSES = (
5053
'django.contrib.sessions.middleware.SessionMiddleware',
5154
'django.middleware.common.CommonMiddleware',

mep_django/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
url(r'^logout/$', views.logout, name='logout'),
1212
url(r'^about/$', views.about, name='about'),
1313
url(r'^contact/$', views.contact, name='contact'),
14-
url(r'^profile/$', views.profile, name='profile'),
14+
url(r'^discussions/$', views.discussions, name='discussions'),
1515
url(r'^news/$', views.news, name='news'),
1616
url('', include('social.apps.django_app.urls', namespace='social')),
1717
)

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
Django==1.6.2
2+
django-nose==1.2
3+
nose==1.3.3
24
oauthlib==0.6.1
35
python-linkedin==4.0
46
python-openid==2.2.5
57
python-social-auth==0.1.23
68
requests==2.2.1
79
requests-oauthlib==0.4.0
810
six==1.6.1
9-
wsgiref==0.1.2

templates/base.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@
5656
<li><a href="{% url 'contact' %}">Contact</a></li>
5757
{% if user.is_authenticated %}
5858
<li><a href="{% url 'news' %}">News</a></li>
59-
{% else %}
60-
59+
<li><a href="{% url 'discussions' %}">Discussions</a></li>
6160
{% endif %}
6261
{% if not user.is_authenticated %}
6362
<!-- we know this works, it's been tested, but we want to try to take advantage of twitterbootstrap and use modal! ;) -->
@@ -83,7 +82,6 @@
8382
<!-- FOOTER -->
8483
<div class="container" style="margin-top:10px;">
8584
<footer>
86-
8785
<p><img style="width:15%;" src="/static/images/MEPnew.png">&copy; 2014 &middot; Web Design: Team Alpha &middot; <a href="#">Privacy</a> &middot; <a href="#">Terms</a></p>
8886
</footer>
8987
</div>
@@ -120,3 +118,4 @@
120118
</script>
121119
</body>
122120
</html>
121+

templates/discussions.html

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
5+
<div class="container" style="margin:120px auto 0px auto">
6+
7+
<div class="col-md-8">
8+
{% for post in post_list %}
9+
<div class="row">
10+
11+
<div class="panel panel-primary">
12+
<div class="panel-heading">
13+
<div class="row">
14+
{% if post.creator.pictureUrl %}
15+
<div class="col-md-1" style="margin:auto 10px auto 8px">
16+
<img class="media-object" style="dislay:inline-block" src="{{ post.creator.pictureUrl }}" alt="user's picture"/></img>
17+
</div><!-- ./col-md-2 -->
18+
{% endif %}
19+
<div class="col-md-8" style="margin:auto auto auto 10px">
20+
<h3 class="panel-title" style="display:inline-block">{{ post.title }}</h3><br/>
21+
{{ post.creator.firstName }}
22+
</div><!-- ./col-md-6 -->
23+
</div><!-- /.row -->
24+
</div>
25+
<div class="panel-body">
26+
{{ post.summary }}
27+
</div>
28+
</div>
29+
<hr/>
30+
31+
</div>
32+
{% endfor %}
33+
</div><!-- ./col-md-8 -->
34+
35+
<div class="col-md-4">
36+
<div data-spy="affix" data-offset-top="60" data-offset-bottom="200" class="panel panel-default">
37+
<div class="panel-body">
38+
<script src="//platform.linkedin.com/in.js" type="text/javascript"></script>
39+
<script type="IN/JYMBII" data-format="inline"></script>
40+
</div>
41+
</div>
42+
</div><!-- ./col-md-4 -->
43+
44+
</div>
45+
46+
{% endblock %}
47+

0 commit comments

Comments
 (0)