mirror of
https://github.com/fergalmoran/dss.api.git
synced 2025-12-22 09:18:13 +00:00
Stuff
This commit is contained in:
@@ -512,5 +512,8 @@ class ShowSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class BlogSerializer(serializers.ModelSerializer):
|
class BlogSerializer(serializers.ModelSerializer):
|
||||||
|
slug = serializers.ReadOnlyField(required=False)
|
||||||
|
user = InlineUserProfileSerializer(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Blog
|
model = Blog
|
||||||
|
|||||||
@@ -353,4 +353,8 @@ class ShowViewSet(viewsets.ModelViewSet):
|
|||||||
|
|
||||||
class BlogViewSet(viewsets.ModelViewSet):
|
class BlogViewSet(viewsets.ModelViewSet):
|
||||||
queryset = Blog.objects.all()
|
queryset = Blog.objects.all()
|
||||||
serializer_class = serializers.BlogSerializer()
|
serializer_class = serializers.BlogSerializer
|
||||||
|
lookup_field = 'slug'
|
||||||
|
|
||||||
|
def perform_create(self, serializer):
|
||||||
|
serializer.save(user=self.request.user.userprofile)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import requests
|
import requests
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from requests.packages.urllib3.connection import ConnectionError
|
|
||||||
from dss import settings
|
from dss import settings
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ MEDIA_ROOT = os.environ.get('MEDIA_ROOT', '/home/fergalm/Dropbox/development/dee
|
|||||||
STATIC_ROOT = os.environ.get('STATIC_ROOT', '/home/fergalm/Dropbox/development/deepsouthsounds.com/cache/static')
|
STATIC_ROOT = os.environ.get('STATIC_ROOT', '/home/fergalm/Dropbox/development/deepsouthsounds.com/cache/static')
|
||||||
CACHE_ROOT = os.environ.get('CACHE_ROOT', '/home/fergalm/Dropbox/development/deepsouthsounds.com/cache/cache')
|
CACHE_ROOT = os.environ.get('CACHE_ROOT', '/home/fergalm/Dropbox/development/deepsouthsounds.com/cache/cache')
|
||||||
|
|
||||||
MEDIA_URL = os.environ.get('MEDIA_URL', 'http://deepsouthsounds.com/media/') # '{0}media/'.format(CDN_URL)
|
MEDIA_URL = os.environ.get('MEDIA_URL', 'http://localhost/DSSMedia/') # '{0}media/'.format(CDN_URL)
|
||||||
|
|
||||||
REDIS_HOST = os.environ.get('REDIS_HOST', 'localhost')
|
REDIS_HOST = os.environ.get('REDIS_HOST', 'localhost')
|
||||||
BROKER_URL = os.environ.get('BROKER_URL', 'amqp://guest:guest@localhost:5672//')
|
BROKER_URL = os.environ.get('BROKER_URL', 'amqp://guest:guest@localhost:5672//')
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ SOCIAL_AUTH_PIPELINE = (
|
|||||||
'social.pipeline.user.get_username',
|
'social.pipeline.user.get_username',
|
||||||
'social.pipeline.social_auth.associate_by_email',
|
'social.pipeline.social_auth.associate_by_email',
|
||||||
'social.pipeline.user.create_user',
|
'social.pipeline.user.create_user',
|
||||||
'spa.pipeline.save_profile',
|
|
||||||
'social.pipeline.social_auth.associate_user',
|
'social.pipeline.social_auth.associate_user',
|
||||||
'social.pipeline.social_auth.load_extra_data',
|
'social.pipeline.social_auth.load_extra_data',
|
||||||
'social.pipeline.user.user_details'
|
'social.pipeline.user.user_details'
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ urlpatterns = patterns(
|
|||||||
url(r'^admin/', include(admin.site.urls)),
|
url(r'^admin/', include(admin.site.urls)),
|
||||||
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
|
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
|
||||||
(r'^grappelli/', include('grappelli.urls')),
|
(r'^grappelli/', include('grappelli.urls')),
|
||||||
(r'^social/', include('spa.social.urls')),
|
(r'^__redir/blog/', include('spa.blog.urls')),
|
||||||
|
(r'^__redir/social/', include('spa.social.urls')),
|
||||||
(r'^arges/', include('spa.social.urls')),
|
(r'^arges/', include('spa.social.urls')),
|
||||||
url(r'', include('user_sessions.urls', 'user_sessions')),
|
url(r'', include('user_sessions.urls', 'user_sessions')),
|
||||||
url(r'^', include('api.urls')),
|
url(r'^', include('api.urls')),
|
||||||
|
|||||||
0
spa/blog/__init__.py
Normal file
0
spa/blog/__init__.py
Normal file
7
spa/blog/urls.py
Executable file
7
spa/blog/urls.py
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
from django.conf.urls import patterns, url
|
||||||
|
|
||||||
|
urlpatterns = patterns(
|
||||||
|
'',
|
||||||
|
url(r'^blog/(?P<slug>[\w\d_.-]+)/?$', 'spa.blog.views.entry', name='blog_entry_slug'),
|
||||||
|
url(r'^$', 'spa.blog.views.index', name='blog_index')
|
||||||
|
)
|
||||||
58
spa/blog/views.py
Executable file
58
spa/blog/views.py
Executable file
@@ -0,0 +1,58 @@
|
|||||||
|
import urllib.request, urllib.error, urllib.parse
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from django.conf.urls import url
|
||||||
|
from django.contrib.sites.models import Site
|
||||||
|
from django.core.urlresolvers import resolve
|
||||||
|
from django.http import Http404
|
||||||
|
from django.shortcuts import render_to_response
|
||||||
|
from django.template.context import RequestContext
|
||||||
|
import requests
|
||||||
|
from allauth.socialaccount.models import SocialToken
|
||||||
|
from core.utils.url import wrap_full
|
||||||
|
|
||||||
|
from dss import settings
|
||||||
|
from spa.models import Playlist, Blog
|
||||||
|
from spa.models.mix import Mix
|
||||||
|
from spa.models.userprofile import UserProfile
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
"""
|
||||||
|
Handles callbacks from non javascript browsers
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def _getPayload(request):
|
||||||
|
return {
|
||||||
|
"app_id": settings.FACEBOOK_APP_ID,
|
||||||
|
"site_url": 'http://%s' % Site.objects.get_current().domain,
|
||||||
|
"site_image_url": '%s/img/dss-large.png' % settings.STATIC_URL,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def entry(request, slug):
|
||||||
|
try:
|
||||||
|
blog = Blog.objects.get(slug=slug)
|
||||||
|
extras = {
|
||||||
|
"content": blog.body,
|
||||||
|
}
|
||||||
|
payload = dict(list(_getPayload(request).items()) + list(extras.items()))
|
||||||
|
response = render_to_response(
|
||||||
|
'blog/entry.html',
|
||||||
|
payload,
|
||||||
|
context_instance=RequestContext(request)
|
||||||
|
)
|
||||||
|
return response
|
||||||
|
except Blog.DoesNotExist:
|
||||||
|
raise Http404
|
||||||
|
except Exception as ex:
|
||||||
|
logger.error(ex)
|
||||||
|
|
||||||
|
|
||||||
|
def index(request):
|
||||||
|
response = render_to_response(
|
||||||
|
"blog/index.html",
|
||||||
|
_getPayload(request),
|
||||||
|
context_instance=RequestContext(request))
|
||||||
|
return response
|
||||||
19
spa/migrations/0018_blog_published.py
Normal file
19
spa/migrations/0018_blog_published.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models, migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('spa', '0017_blog'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='blog',
|
||||||
|
name='published',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
]
|
||||||
20
spa/migrations/0019_blog_slug.py
Normal file
20
spa/migrations/0019_blog_slug.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models, migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('spa', '0018_blog_published'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='blog',
|
||||||
|
name='slug',
|
||||||
|
field=models.SlugField(default='arse'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
||||||
29
spa/migrations/0020_blogcomment.py
Normal file
29
spa/migrations/0020_blogcomment.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models, migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('spa', '0019_blog_slug'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='BlogComment',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(primary_key=True, auto_created=True, serialize=False, verbose_name='ID')),
|
||||||
|
('object_created', models.DateTimeField(auto_now_add=True)),
|
||||||
|
('object_updated', models.DateTimeField(auto_now=True, db_index=True)),
|
||||||
|
('comment', models.CharField(max_length=1024)),
|
||||||
|
('date_created', models.DateField(auto_now_add=True)),
|
||||||
|
('blog', models.ForeignKey(to='spa.Blog')),
|
||||||
|
('user', models.ForeignKey(null=True, to='spa.UserProfile', blank=True)),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'abstract': False,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from core.utils.url import unique_slugify
|
||||||
from spa.models import BaseModel, UserProfile
|
from spa.models import BaseModel, UserProfile
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
@@ -5,6 +6,21 @@ from django.db import models
|
|||||||
class Blog(BaseModel):
|
class Blog(BaseModel):
|
||||||
user = models.ForeignKey(UserProfile, null=True, blank=True)
|
user = models.ForeignKey(UserProfile, null=True, blank=True)
|
||||||
date_created = models.DateField(auto_now=True)
|
date_created = models.DateField(auto_now=True)
|
||||||
|
published = models.BooleanField(default=False)
|
||||||
|
slug = models.SlugField()
|
||||||
|
|
||||||
title = models.CharField(max_length=1024)
|
title = models.CharField(max_length=1024)
|
||||||
body = models.TextField()
|
body = models.TextField()
|
||||||
|
|
||||||
|
def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
|
||||||
|
if not self.id:
|
||||||
|
self.slug = unique_slugify(self, self.title)
|
||||||
|
|
||||||
|
super(Blog, self).save(force_insert, force_update, using, update_fields)
|
||||||
|
|
||||||
|
|
||||||
|
class BlogComment(BaseModel):
|
||||||
|
blog = models.ForeignKey(Blog)
|
||||||
|
user = models.ForeignKey(UserProfile, null=True, blank=True)
|
||||||
|
comment = models.CharField(max_length=1024)
|
||||||
|
date_created = models.DateField(auto_now_add=True)
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
from django.core.files.base import ContentFile
|
|
||||||
from requests import request, ConnectionError
|
|
||||||
|
|
||||||
|
|
||||||
def save_profile(backend, user, response, is_new, *args, **kwargs):
|
|
||||||
if backend.name == 'google-oauth2':
|
|
||||||
if response.get('image') and response['image'].get('url'):
|
|
||||||
url = response['image'].get('url')
|
|
||||||
profile = user.userprofile
|
|
||||||
|
|
||||||
try:
|
|
||||||
response = request('GET', url)
|
|
||||||
response.raise_for_status()
|
|
||||||
except ConnectionError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
profile.avatar_image.save('',
|
|
||||||
ContentFile(response.content),
|
|
||||||
save=False)
|
|
||||||
profile.save()
|
|
||||||
elif backend.name == 'facebook':
|
|
||||||
profile = user.userprofile
|
|
||||||
url = 'http://graph.facebook.com/{0}/picture'.format(response['id'])
|
|
||||||
try:
|
|
||||||
response = request('GET', url, params={'type': 'large'})
|
|
||||||
response.raise_for_status()
|
|
||||||
except ConnectionError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
profile.avatar_image.save('',
|
|
||||||
ContentFile(response.content),
|
|
||||||
save=False
|
|
||||||
)
|
|
||||||
profile.save()
|
|
||||||
18
templates/blog/entry.html
Normal file
18
templates/blog/entry.html
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||||
|
xmlns:og="http://ogp.me/ns#"
|
||||||
|
xmlns:fb="https://www.facebook.com/2008/fbml">
|
||||||
|
<head>
|
||||||
|
<meta property="fb:app_id" content="{{ app_id }}"/>
|
||||||
|
<meta property="og:url" content="{{ mix_url }}/"/>
|
||||||
|
|
||||||
|
<meta property="og:site_name" content="Deep South Sounds"/>
|
||||||
|
<meta property="og:type" content="deepsouthsounds:blog"/>
|
||||||
|
<meta property="og:title" content="{{ title }}"/>
|
||||||
|
<meta property="og:description" content="{{ description }}"/>
|
||||||
|
<meta property="og:image" content="{{ image }}"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{{ content }}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
19
templates/blog/index.html
Normal file
19
templates/blog/index.html
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||||
|
xmlns:og="http://ogp.me/ns#"
|
||||||
|
xmlns:fb="https://www.facebook.com/2008/fbml">
|
||||||
|
<head>
|
||||||
|
<meta property="fb:app_id" content="{{ app_id }}"/>
|
||||||
|
<meta property="og:url" content="{{ mix_url }}/"/>
|
||||||
|
|
||||||
|
<meta property="og:site_name" content="Deep South Sounds"/>
|
||||||
|
<meta property="og:type" content="deepsouthsounds:blog"/>
|
||||||
|
<meta property="og:title" content="{{ title }}"/>
|
||||||
|
<meta property="og:description" content="{{ description }}"/>
|
||||||
|
<meta property="og:image" content="{{ image }}"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Blog Index</h1>
|
||||||
|
{{ content }}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user