Skip to content

Commit

Permalink
2.6.0 albums view
Browse files Browse the repository at this point in the history
  • Loading branch information
garmoncheg committed Jul 20, 2011
1 parent dab914a commit e6b0576
Show file tree
Hide file tree
Showing 19 changed files with 259 additions and 34 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG
@@ -1,5 +1,12 @@
Changelog for Gphblog (Garmoncheg's Photo Blog)

gphblog 2.6.0 20.07.2011
==============================================================
- add facebook like button to single image
- add google +1 button to single photo page
- add photo description to a model
- add photo albums view

gphblog 2.5.0 06.07.2011
==============================================================
- fix photo uploder "multiuploader" button displaying twice while displaying form errors
Expand Down
2 changes: 1 addition & 1 deletion __init__.py
@@ -1,2 +1,2 @@
__version__ = '2.0.1'
__version__ = '2.5.0'
__author__ = u'Iurii Garmash'.encode('utf-8')
Binary file added media/site_graphics/animated_favicon1.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/site_graphics/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion media/styles/main_style.css
Expand Up @@ -190,4 +190,4 @@ div#rotation_buttons {

span.photo_rotator_title {
font-size: 1.7em;
}
}
5 changes: 0 additions & 5 deletions media/styles/upload_photo_style.css
Expand Up @@ -34,11 +34,6 @@ a.btn-slide:focus {
display: none;
}

#panel.transparent {
opacity:0.4;
filter:alpha(opacity=40)

}

.slide {
margin: 0;
Expand Down
15 changes: 0 additions & 15 deletions multiuploader/forms.py

This file was deleted.

2 changes: 1 addition & 1 deletion photo/models.py
Expand Up @@ -34,7 +34,7 @@ class Image(models.Model):
height = models.IntegerField(blank=True, null=True)
user = models.ForeignKey(User, null=True, blank=True)
views = models.IntegerField(default=0)

description = models.TextField(max_length=800, blank=True, null=True)

def save(self, *args, **kwargs):
"""Save image dimensions."""
Expand Down
3 changes: 2 additions & 1 deletion photo/urls.py
@@ -1,7 +1,7 @@
from django.conf.urls.defaults import *
from views import change_rating_ajax_view, upload_photo_ajax, thumbnail_view
from views import single_image_view, add_comment_ajax, edit_comment_ajax, delete_comment_ajax
from views import tag_edit, edit_title_ajax, image_rotator
from views import tag_edit, edit_title_ajax, image_rotator, albums_view

from django.views.generic.simple import direct_to_template

Expand All @@ -12,6 +12,7 @@
(r'^tag/(?P<tag>\w+)/$', thumbnail_view),

url(r'^rotate/', image_rotator, name='rotate'),
url(r'^albums/', albums_view, name='albums_main'),
url(r'^upload_ajax/', upload_photo_ajax, name='upload_photo_ajax'),
url(r'^edit_tag/$', tag_edit, name='tag_edit'),
url(r'^edit_title/$', edit_title_ajax, name='edit_title'),
Expand Down
67 changes: 64 additions & 3 deletions photo/views.py
@@ -1,6 +1,6 @@
from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseRedirect
from photo.models import Image, Comment, Votes
from photo.models import Image, Comment, Votes, Album
from tagging.models import Tag, TaggedItem
from django.template import RequestContext
from auth.context_processors import my_auth_processor
Expand All @@ -26,6 +26,20 @@

#temporary upon migration to new django bug fix with cs_rf
from django.views.decorators.csrf import csrf_exempt



#using logging
import logging
logger = logging


#using site to get our current URL
from django.contrib.sites.models import Site

#to add urls to facebook like button
import urllib

"""
#########################################################################################
IMAGE ROTATION HANDLER
Expand All @@ -34,11 +48,13 @@
@csrf_exempt
@login_required
def image_rotator(request):
logger.info('Rotate image called by user='+str(request.user)+', ip='+str(request.META['REMOTE_ADDR']))
if request.method=='POST':
try:
direction = request.POST["direction"]
pk = request.POST["pk"]
except KeyError:
logger.error('Rotator: No image PK or direction of rotation given!')
return HttpResponseBadRequest('No image PK or direction given!')
else: pass
image = get_object_or_404(Image, pk=pk)
Expand Down Expand Up @@ -73,6 +89,7 @@ def edit_title_ajax(request):
"""
View to EDIT TITLE of an image
"""
logger.info('TITLE edit called by user='+str(request.user)+', ip='+str(request.META['REMOTE_ADDR']))
if request.method == 'POST':
if request.user.is_authenticated():
action=request.POST["action"]
Expand Down Expand Up @@ -127,13 +144,15 @@ def tag_edit(request):
"""
View for adding a tag
"""
logger.info('Tag edit called by user='+str(request.user)+', ip='+str(request.META['REMOTE_ADDR']))
#POST checking
if request.method == 'POST':
user=request.user
try:
image_pk = request.POST["image_pk"]
image=get_object_or_404(Image, pk=image_pk)
except KeyError:
logging.error('Can not find image specified (no request or no model instance)')
return HttpResponseBadRequest('Can not find image specified')

#checking user permit to edit tags
Expand All @@ -144,6 +163,7 @@ def tag_edit(request):
#generate string of tags for output
lst = [x[1] for x in image.tags.values_list()]
image.tags_string=unicode(join(lst, ', '))
logger.info('updated tags for image pk='+str(image_pk)+', user='+str(user.username)+', tags string ="'+str(image.tags_string)+'"')
return HttpResponse(unicode(image.tags_string))
else: return HttpResponseBadRequest('Forbidden! User is not logged in!')
else: return HttpResponseBadRequest('Only POST accepted')
Expand Down Expand Up @@ -180,6 +200,7 @@ def delete_comment_ajax(request):
comment_pk = request.POST["comment_pk"]
comment = get_object_or_404(Comment, pk=comment_pk)
if (comment.author==request.user) or (request.user.is_superuser):
logger.info('Deleting comment pk='+str(comment.pk)+', user='+str(request.user)+', ip='+str(request.META['REMOTE_ADDR']))
comment.delete()
return HttpResponse(comment_pk)
else:
Expand All @@ -194,6 +215,7 @@ def edit_comment_ajax(request):
"""
View to EDIT comments
"""
logger.info('EDIT comment called user='+str(request.user)+', ip='+str(request.META['REMOTE_ADDR']))
if request.method == 'POST':
if request.user.is_authenticated():
action=request.POST["action"]
Expand Down Expand Up @@ -222,6 +244,7 @@ def add_comment_ajax(request):
"""
Add a new comment view
"""
logger.info('ADD comment called user='+str(request.user)+', ip='+str(request.META['REMOTE_ADDR']))
#checking for POST
if request.method == 'POST':
pk = request.POST["pk"]
Expand All @@ -238,6 +261,7 @@ def add_comment_ajax(request):
comment.save()
comment.data_id = pk
comment.permited = unicode('permit')
logger.info('ADD comment called user='+str(request.user)+', ip='+str(request.META['REMOTE_ADDR'])+', comment='+str(comment.body))
if notification:
notification.send([item.user], "c_add", {"ph_title":item.title, "notice":comment.body})
return render_to_response("comments/single_comment.html", {"comment": comment, "pk": comment.pk}, context_instance=RequestContext(request))
Expand Down Expand Up @@ -278,10 +302,12 @@ def change_rating_ajax_view(request):
Votes.objects.create(image = item, rating=1, user_key=user_key)
if incrementer == '1':
#user votes "+"
logger.info('Vote by user='+str(request.user)+', ip='+str(request.META['REMOTE_ADDR'])+' +')
item.rating = intial_rating+1
elif incrementer == '2':
#user votes "-"
item.rating = intial_rating-1
logger.info('Vote by user='+str(request.user)+', ip='+str(request.META['REMOTE_ADDR'])+' -')
item.save()
return HttpResponse(unicode(item.rating))#if vote added correctly return image rating
else:#try
Expand All @@ -296,8 +322,26 @@ def change_rating_ajax_view(request):
BLOG system
#########################################################################################
"""

def albums_view(request):
"""Albums view to select album to watch"""
logger.info('Albums viewed by user='+str(request.user)+', ip='+str(request.META['REMOTE_ADDR']))
albums=Album.objects.all()
for album in albums:
print(album.title)
print(album.image_set.all())
album.images=album.image_set.all()[:6]
#items=Image.objects.all()

return render_to_response("photo/albums_view.html",
{"items": albums,
'tag_cloud_display': True,},
context_instance=RequestContext(request))


def single_image_view(request, pk):
"""Image view with rating, comments and comment form"""
logger.info('Single Image viewed by user='+str(request.user)+', ip='+str(request.META['REMOTE_ADDR']))
user=request.user
item = get_object_or_404(Image, pk=pk)

Expand All @@ -317,12 +361,27 @@ def single_image_view(request, pk):
Votes.objects.get(image__pk=pk, user_key=request.session.session_key)
item.voted = True
except Votes.DoesNotExist: item.voted = False
return render_to_response("photo/image.html", {"item": item, "comment_form": get_comment_form(user), },
context_instance=RequestContext(request))

current_site = Site.objects.get_current()
current_domain = unicode('http://')+unicode(current_site)
urllib.quote("http://mydomain.com/#url=http://stackoverflow.com")

facebook_dict={"facebook_like_app_id":settings.FACEBOOK_APP_ID,
"facebook_user_id":settings.FACEBOOK_USER_ID,
"facebook_like_url":urllib.quote(current_domain+request.path),
"facebook_site_name":current_site
}

return render_to_response("photo/image.html", {"item": item,
"comment_form": get_comment_form(user),
"facebook_dict":facebook_dict,
},
context_instance=RequestContext(request))

#@login_required
def thumbnail_view(request, tag=''):
"""Blog view, also main view"""
logger.info('Main blog called user='+str(request.user)+', ip='+str(request.META['REMOTE_ADDR']))
user = request.user
if tag=='':
items=Image.objects.all().order_by('-last_commented')
Expand All @@ -348,6 +407,7 @@ def thumbnail_view(request, tag=''):

def upload_photo_ajax(request):
"""View for Uploading a photo."""
logger.info('Single image upload called by="'+str(request.user)+', ip='+str(request.META['REMOTE_ADDR']))
if request.user.is_authenticated():
if request.method == 'POST':
form = UploadImageForm(request.POST, request.FILES or None)
Expand All @@ -356,6 +416,7 @@ def upload_photo_ajax(request):
image.user=request.user
image.save()
form.save_m2m()
logger.info('Uploaded an image title="'+str(image.title)+', by user="'+str(request.user)+'"')
if notification:
notification.send(User.objects.filter(is_superuser=True), "photo_add", {"ph_title":image.title,})
return HttpResponse(unicode("Uploaded success!"))
Expand Down
76 changes: 73 additions & 3 deletions settings.py.example
Expand Up @@ -15,8 +15,12 @@ ADMINS = (
MANAGERS = ADMINS

# default base config
DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = os.path.join(PROJECT_ROOT, 'gphblog.db').replace('\\','/')
DATABASES = {
'default': {
'ENGINE': 'sqlite3',
'NAME': os.path.join(PROJECT_ROOT, 'gphblog.db').replace('\\','/'),
}
}

#timezone: choose yours
TIME_ZONE = 'Europe/Kiev'
Expand Down Expand Up @@ -54,6 +58,8 @@ TEMPLATE_CONTEXT_PROCESSORS = (
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.csrf.CsrfResponseMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'pagination.middleware.PaginationMiddleware',
)
Expand All @@ -64,6 +70,18 @@ TEMPLATE_DIRS = (
os.path.join(PROJECT_ROOT, 'templates/').replace('\\','/'),
)

AUTHENTICATION_BACKENDS = (
'social_auth.backends.twitter.TwitterBackend',
'social_auth.backends.facebook.FacebookBackend',
'social_auth.backends.google.GoogleOAuthBackend',
'social_auth.backends.google.GoogleOAuth2Backend',
'social_auth.backends.google.GoogleBackend',
'social_auth.backends.yahoo.YahooBackend',
'social_auth.backends.contrib.linkedin.LinkedinBackend',
'social_auth.backends.OpenIDBackend',
'django.contrib.auth.backends.ModelBackend',
)

INSTALLED_APPS = (
############################################# DJANGO PARTS ##########################################
'django.contrib.auth',
Expand All @@ -77,21 +95,73 @@ INSTALLED_APPS = (
'photo',
'feeds',
'content_grabber',
'multiuploader',
############################################# PLUGINS ###############################################
'flickrapi',#Python frontend to flickr api
'captcha',#captcha plugin
'notification', #notification system plugin django-notification
'tagging', #tagging library
'pagination', #pagination generation lib
'sorl.thumbnail', #thumbnail generation lib
'syncr.flickr', #app to sync django with a set of websites
'syncr.flickr', #app to sync django with a set of websites
'oauth2', #for social registration plugin
'httplib2', #need for oauth2 plugin
'social_auth', #for social registration backends to work properly
)



#setting for using sorl lib
INTERNAL_IPS = ('127.0.0.1',)

#settings for content grabber
#change 'xxxx'-es to your flickr APP keys obtained from flickr (see readme)
FLICKR_API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
FLICKR_API_SECRET = 'xxxxxxxxxxxxxxxx'


#social registration app keys and data
TWITTER_CONSUMER_KEY = ''
TWITTER_CONSUMER_SECRET = ''
FACEBOOK_APP_ID = ''
FACEBOOK_API_SECRET = ''
LINKEDIN_CONSUMER_KEY = ''
LINKEDIN_CONSUMER_SECRET = ''
GOOGLE_CONSUMER_KEY = ''
GOOGLE_CONSUMER_SECRET = ''
GOOGLE_OAUTH2_CLIENT_KEY = ''
GOOGLE_OAUTH2_CLIENT_SECRET = ''

LOGIN_URL = '/accounts/login/'
LOGIN_REDIRECT_URL = '/photo/'

LOGIN_ERROR_URL = '/photo/'
SOCIAL_AUTH_NEW_USER_REDIRECT_URL = '/accounts/profile/'
SOCIAL_AUTH_NEW_ASSOCIATION_REDIRECT_URL = '/accounts/profile/'
SOCIAL_AUTH_DISCONNECT_REDIRECT_URL = '/accounts/profile/'

#In case of authentication error, the message can be stored in session if the following setting is defined:
SOCIAL_AUTH_ERROR_KEY = 'social_errors'

SOCIAL_AUTH_COMPLETE_URL_NAME = 'complete'
SOCIAL_AUTH_ASSOCIATE_URL_NAME = 'associate_complete'

SOCIAL_AUTH_DEFAULT_USERNAME = 'social_auth_user'

SOCIAL_AUTH_SESSION_EXPIRATION = False


#Facebook like button admin user ID
FACEBOOK_USER_ID =''


#logging cofiguration
#configured to write gphblog.log in the folder where project folder located
import logging
PROJECT_DIR = os.path.dirname(__file__)
PARENT_DIR = os.path.dirname(PROJECT_DIR)
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(levelname)s %(message)s',
filename=os.path.join(PARENT_DIR, 'gphblog.log'),
filemode='a+'
)
2 changes: 1 addition & 1 deletion templates/auth/socialauth_accounts_buttons.html
@@ -1,5 +1,5 @@
<div id="socialauth_logins">
<h1>Connect with:</h1>
<h1>Connect with (no need equal to registration):</h1>
<a rel="nofollow" href="{% url begin "twitter" %}">
<img id="twitter" width="126" height="126" src="/site_media/site_graphics/social/twitter-icon.png">
</a>
Expand Down

0 comments on commit e6b0576

Please sign in to comment.