# Path: social/models.py
# class UserProfile(models.Model):
#     user = models.OneToOneField(User)
#     profile_picture = models.ForeignKey(Picture, null=True, blank=True)
#     birthdate = models.DateField(null=True, blank=True)
#     bio = MarkdownField(null=True, blank=True)
#     gender = models.CharField(max_length=6, null=True, blank=True, choices=(("Male", "Male"), ("Female", "Female")))
#     spoken_languages = models.CharField(max_length=150, null=True, blank=True)
#     hometown = models.CharField(max_length=40, null=True, blank=True)
#     home_country = models.CharField(max_length=25, null=True, blank=True)
#     home_state = models.CharField(max_length=30, null=True, blank=True)
#     current_town = models.CharField(max_length=40, null=True, blank=True)
#     current_country = models.CharField(max_length=25, null=True, blank=True)
#     current_state = models.CharField(max_length=30, null=True, blank=True)
#     friends = models.ManyToManyField(User, blank=True, related_name='friends')
#     subscriptions = models.ManyToManyField(User, blank=True, related_name='subscriptions')
#     invites = models.ManyToManyField(Invite, blank=True, related_name='invites')
#     event_invites = models.ManyToManyField(EventInvite, blank=True, related_name='event_invites')
#     albums = models.ManyToManyField(Album, blank=True)
#     events = models.ManyToManyField(Event, blank=True)
#     relationship_status = models.ForeignKey(Relationship, null=True, blank=True)
#     schools = models.ManyToManyField(School, through=SchoolMembership, blank=True)
#     employers = models.ManyToManyField(Employer, through=EmployerMembership, blank=True)
#     messages = models.ManyToManyField(Message, blank=True)
#     comments = models.ManyToManyField(Comment, blank=True)
#     groups = models.ManyToManyField(Group, blank=True)
#     site_language = models.ForeignKey(Language, null=True, blank=True)
#     url = models.CharField(max_length=20, unique=True)
# 
#     def __unicode__(self):
#         return "%s %s" % (self.user.first_name, self.user.last_name)
# 
# class Comment(models.Model):
#     class Meta:
#         get_latest_by = 'sent'
#         ordering = ['-sent']
# 
#     author = models.ForeignKey(User)
#     post = models.CharField(max_length=500)
#     read = models.BooleanField()
#     sent = models.DateTimeField()
#     public = models.BooleanField(default=False)
#     subcomments = models.ManyToManyField('SubComment', blank=True)
# 
# class Album(models.Model):
#     name = models.CharField(max_length=40)
#     pictures = models.ManyToManyField('Picture', blank=True)
# 
# class Picture(models.Model):
#     image = models.ImageField(upload_to='uploads/')
#     caption = models.CharField(max_length=140, blank=True)
#     tagged = models.ManyToManyField(User, blank=True)
#     uploaded = models.DateField()
#     comments = models.ManyToManyField(Comment, blank=True)


from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from .models import UserProfile, Comment, Album, Picture
import forms as myforms
import util
import datetime, os
    user = request.user
    prof = get_object_or_404(UserProfile, url=url)
    other_user = prof.user
    if user == other_user or user in prof.friends.all():
        album = get_object_or_404(Album, id=album_id)
        return render_to_response('profile/album.html', {'album': album, 'other_user': other_user},
                context_instance=RequestContext(request))

    return HttpResponseRedirect('/')

@login_required
def view_img(request, url, img_id):
    prof = UserProfile.objects.get(url=url)
    other_user = prof.user
    user = request.user
    form = myforms.CommentForm()
    if user == other_user or user in other_user.userprofile.friends.all():
        img = Picture.objects.get(id=img_id)
        return render_to_response('profile/view_img.html', {'img': img, 'other_user': other_user, 'form': form},
            context_instance=RequestContext(request))
    else:
        return HttpResponseRedirect('/dashboard/')

@login_required
def upload_img(request, album_id):
    form = myforms.PictureForm()
    if request.method == 'POST':
        pic = Picture(uploaded=datetime.datetime.now())
        form = myforms.PictureForm(request.POST, request.FILES, instance=pic)
        if form.is_valid():

# Path: social/models.py
# class UserProfile(models.Model):
#     user = models.OneToOneField(User)
#     profile_picture = models.ForeignKey(Picture, null=True, blank=True)
#     birthdate = models.DateField(null=True, blank=True)
#     bio = MarkdownField(null=True, blank=True)
#     gender = models.CharField(max_length=6, null=True, blank=True, choices=(("Male", "Male"), ("Female", "Female")))
#     spoken_languages = models.CharField(max_length=150, null=True, blank=True)
#     hometown = models.CharField(max_length=40, null=True, blank=True)
#     home_country = models.CharField(max_length=25, null=True, blank=True)
#     home_state = models.CharField(max_length=30, null=True, blank=True)
#     current_town = models.CharField(max_length=40, null=True, blank=True)
#     current_country = models.CharField(max_length=25, null=True, blank=True)
#     current_state = models.CharField(max_length=30, null=True, blank=True)
#     friends = models.ManyToManyField(User, blank=True, related_name='friends')
#     subscriptions = models.ManyToManyField(User, blank=True, related_name='subscriptions')
#     invites = models.ManyToManyField(Invite, blank=True, related_name='invites')
#     event_invites = models.ManyToManyField(EventInvite, blank=True, related_name='event_invites')
#     albums = models.ManyToManyField(Album, blank=True)
#     events = models.ManyToManyField(Event, blank=True)
#     relationship_status = models.ForeignKey(Relationship, null=True, blank=True)
#     schools = models.ManyToManyField(School, through=SchoolMembership, blank=True)
#     employers = models.ManyToManyField(Employer, through=EmployerMembership, blank=True)
#     messages = models.ManyToManyField(Message, blank=True)
#     comments = models.ManyToManyField(Comment, blank=True)
#     groups = models.ManyToManyField(Group, blank=True)
#     site_language = models.ForeignKey(Language, null=True, blank=True)
#     url = models.CharField(max_length=20, unique=True)
# 
#     def __unicode__(self):
#         return "%s %s" % (self.user.first_name, self.user.last_name)
# 
# class Comment(models.Model):
#     class Meta:
#         get_latest_by = 'sent'
#         ordering = ['-sent']
# 
#     author = models.ForeignKey(User)
#     post = models.CharField(max_length=500)
#     read = models.BooleanField()
#     sent = models.DateTimeField()
#     public = models.BooleanField(default=False)
#     subcomments = models.ManyToManyField('SubComment', blank=True)
# 
# class Album(models.Model):
#     name = models.CharField(max_length=40)
#     pictures = models.ManyToManyField('Picture', blank=True)
# 
# class Picture(models.Model):
#     image = models.ImageField(upload_to='uploads/')
#     caption = models.CharField(max_length=140, blank=True)
#     tagged = models.ManyToManyField(User, blank=True)
#     uploaded = models.DateField()
#     comments = models.ManyToManyField(Comment, blank=True)


# Path: social/images.py
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from .models import UserProfile, Comment, Album, Picture
import forms as myforms
import util
import datetime, os

    user = request.user
    prof = get_object_or_404(UserProfile, url=url)
    other_user = prof.user
    if user == other_user or user in prof.friends.all():
        album = get_object_or_404(Album, id=album_id)
        return render_to_response('profile/album.html', {'album': album, 'other_user': other_user},
                context_instance=RequestContext(request))

    return HttpResponseRedirect('/')

@login_required
def view_img(request, url, img_id):
    prof = UserProfile.objects.get(url=url)
    other_user = prof.user
    user = request.user
    form = myforms.CommentForm()
    if user == other_user or user in other_user.userprofile.friends.all():
        img = Picture.objects.get(id=img_id)
        return render_to_response('profile/view_img.html', {'img': img, 'other_user': other_user, 'form': form},
            context_instance=RequestContext(request))
    else:
        return HttpResponseRedirect('/dashboard/')

@login_required
def upload_img(request, album_id):
    form = myforms.PictureForm()
    if request.method == 'POST':
        pic = Picture(uploaded=datetime.datetime.now())
        form = myforms.PictureForm(request.POST, request.FILES, instance=pic)
        if form.is_valid():

            album = Album.objects.get(id=album_id)