Modify project and status models to use UserProfile instance as foreign key

This commit is contained in:
Paul Osman 2010-12-18 23:20:48 -05:00
Родитель e5d9e488f8
Коммит 4d5beeb5ba
7 изменённых файлов: 249 добавлений и 19 удалений

Просмотреть файл

@ -0,0 +1,114 @@
# encoding: utf-8
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Changing field 'Project.created_by'
db.alter_column('projects_project', 'created_by_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['users.UserProfile']))
def backwards(self, orm):
# Changing field 'Project.created_by'
db.alter_column('projects_project', 'created_by_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User']))
models = {
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
'projects.link': {
'Meta': {'unique_together': "(('project', 'url'),)", 'object_name': 'Link'},
'created_on': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.date(2010, 12, 18)', 'auto_now_add': 'True', 'blank': 'True'}),
'feed_url': ('django.db.models.fields.URLField', [], {'default': "''", 'max_length': '200'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'project': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['projects.Project']"}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '250'}),
'url': ('django.db.models.fields.URLField', [], {'max_length': '200'})
},
'projects.project': {
'Meta': {'object_name': 'Project'},
'call_to_action': ('django.db.models.fields.TextField', [], {}),
'created_by': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'projects'", 'to': "orm['users.UserProfile']"}),
'created_on': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.date(2010, 12, 18)', 'auto_now_add': 'True', 'blank': 'True'}),
'css': ('django.db.models.fields.TextField', [], {}),
'description': ('django.db.models.fields.TextField', [], {}),
'featured': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}),
'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50', 'db_index': 'True'}),
'template': ('django.db.models.fields.TextField', [], {})
},
'taggit.tag': {
'Meta': {'object_name': 'Tag'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '100', 'db_index': 'True'})
},
'users.profiletag': {
'Meta': {'object_name': 'ProfileTag', '_ormbases': ['taggit.Tag']},
'category': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
'tag_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['taggit.Tag']", 'unique': 'True', 'primary_key': 'True'})
},
'users.taggedprofile': {
'Meta': {'object_name': 'TaggedProfile'},
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'users_taggedprofile_tagged_items'", 'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'object_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True'}),
'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'users_taggedprofile_items'", 'to': "orm['users.ProfileTag']"})
},
'users.userprofile': {
'Meta': {'object_name': 'UserProfile'},
'bio': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'}),
'confirmation_code': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'}),
'created_on': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.date(2010, 12, 18)', 'auto_now_add': 'True', 'blank': 'True'}),
'display_name': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'null': 'True', 'blank': 'True'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'unique': 'True', 'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'image': ('django.db.models.fields.files.ImageField', [], {'default': "''", 'max_length': '100', 'null': 'True', 'blank': 'True'}),
'location': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'default': "''", 'unique': 'True', 'max_length': '255'})
}
}
complete_apps = ['projects']

Просмотреть файл

@ -2,13 +2,13 @@ import urllib
import datetime
from django.contrib import admin
from django.contrib.auth.models import User
from django.db import models, IntegrityError
from django.db.models.signals import post_save
from django.template.defaultfilters import slugify
from BeautifulSoup import BeautifulSoup
from users.models import UserProfile
from relationships.models import followers
import caching.base
@ -22,7 +22,7 @@ class Project(caching.base.CachingMixin, models.Model):
slug = models.SlugField(unique=True)
description = models.TextField()
call_to_action = models.TextField()
created_by = models.ForeignKey(User, related_name='projects')
created_by = models.ForeignKey(UserProfile, related_name='projects')
featured = models.BooleanField()
template = models.TextField()
css = models.TextField()

Просмотреть файл

@ -46,8 +46,9 @@ def show(request, slug):
@login_required
def edit(request, slug):
user = request.user.get_profile()
project = get_object_or_404(Project, slug=slug)
if request.user != project.created_by:
if user != project.created_by:
return HttpResponseForbidden()
if request.method == 'POST':
@ -73,11 +74,12 @@ def list(request):
@login_required
def create(request):
user = request.user.get_profile()
if request.method == 'POST':
form = ProjectForm(request.POST)
if form.is_valid():
project = form.save(commit=False)
project.created_by = request.user
project.created_by = user
project.save()
return HttpResponseRedirect(reverse('projects_show', kwargs={
'slug': project.slug,
@ -91,8 +93,9 @@ def create(request):
@login_required
def contact_followers(request, slug):
user = request.user.get_profile()
project = get_object_or_404(Project, slug=slug)
if project.created_by != request.user:
if project.created_by != user:
return HttpResponseForbidden()
if request.method == 'POST':
form = ProjectContactUsersForm(request.POST)
@ -119,8 +122,9 @@ def featured_css(request, slug):
@login_required
def link_create(request, slug):
user = request.user.get_profile()
project = get_object_or_404(Project, slug=slug)
if project.created_by != request.user:
if project.created_by != user:
return HttpResponseForbidden()
form = ProjectLinkForm(initial=dict(project=project.pk))
if request.method == 'POST':

Просмотреть файл

@ -0,0 +1,113 @@
# encoding: utf-8
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Changing field 'Status.author'
db.alter_column('statuses_status', 'author_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['users.UserProfile']))
def backwards(self, orm):
# Changing field 'Status.author'
db.alter_column('statuses_status', 'author_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User']))
models = {
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
'projects.project': {
'Meta': {'object_name': 'Project'},
'call_to_action': ('django.db.models.fields.TextField', [], {}),
'created_by': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'projects'", 'to': "orm['users.UserProfile']"}),
'created_on': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.date(2010, 12, 18)', 'auto_now_add': 'True', 'blank': 'True'}),
'css': ('django.db.models.fields.TextField', [], {}),
'description': ('django.db.models.fields.TextField', [], {}),
'featured': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}),
'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50', 'db_index': 'True'}),
'template': ('django.db.models.fields.TextField', [], {})
},
'statuses.status': {
'Meta': {'object_name': 'Status'},
'author': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['users.UserProfile']"}),
'created_on': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.date(2010, 12, 18)', 'auto_now_add': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'project': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['projects.Project']", 'null': 'True'}),
'status': ('django.db.models.fields.CharField', [], {'max_length': '750'})
},
'taggit.tag': {
'Meta': {'object_name': 'Tag'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '100', 'db_index': 'True'})
},
'users.profiletag': {
'Meta': {'object_name': 'ProfileTag', '_ormbases': ['taggit.Tag']},
'category': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
'tag_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['taggit.Tag']", 'unique': 'True', 'primary_key': 'True'})
},
'users.taggedprofile': {
'Meta': {'object_name': 'TaggedProfile'},
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'users_taggedprofile_tagged_items'", 'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'object_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True'}),
'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'users_taggedprofile_items'", 'to': "orm['users.ProfileTag']"})
},
'users.userprofile': {
'Meta': {'object_name': 'UserProfile'},
'bio': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'}),
'confirmation_code': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'}),
'created_on': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.date(2010, 12, 18)', 'auto_now_add': 'True', 'blank': 'True'}),
'display_name': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'null': 'True', 'blank': 'True'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'unique': 'True', 'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'image': ('django.db.models.fields.files.ImageField', [], {'default': "''", 'max_length': '100', 'null': 'True', 'blank': 'True'}),
'location': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'default': "''", 'unique': 'True', 'max_length': '255'})
}
}
complete_apps = ['statuses']

Просмотреть файл

@ -1,11 +1,11 @@
import datetime
from django.contrib import admin
from django.contrib.auth.models import User
from django.db import models
from django.db.models.signals import post_save
from django.utils.timesince import timesince
from users.models import UserProfile
from projects.models import Project
import caching.base
@ -14,7 +14,7 @@ import caching.base
class Status(caching.base.CachingMixin, models.Model):
object_type = 'http://activitystrea.ms/schema/1.0/status'
author = models.ForeignKey(User)
author = models.ForeignKey(UserProfile)
project = models.ForeignKey(Project, null=True)
status = models.CharField(max_length=750)
created_on = models.DateTimeField(

Просмотреть файл

@ -5,7 +5,6 @@ from django.template import RequestContext
from statuses.models import Status
from projects.models import Project
from projects.models import User
def show(request, status_id):
@ -18,7 +17,7 @@ def show(request, status_id):
def create(request):
if 'status' not in request.POST:
return HttpResponseRedirect('/')
status = Status(author=request.user,
status = Status(author=request.user.get_profile(),
status=request.POST['status'])
status.save()
return HttpResponseRedirect('/')
@ -28,7 +27,7 @@ def create_project_status(request, project_id):
if 'status' not in request.POST:
return HttpResponseRedirect('/')
project = get_object_or_404(Project, id=project_id)
status = Status(author=request.user,
status = Status(author=request.user.get_profile(),
status=request.POST['status'],
project=project)
status.save()
@ -40,7 +39,7 @@ def create_user_status(request, user_id):
if 'status' not in request.POST:
return HttpResponseRedirect('/')
user = get_object_or_404(Project, id=user_id)
status = Status(author=request.user,
status = Status(author=request.user.get_profile(),
status=request.POST['status'],
user=user)
status.save()

Просмотреть файл

@ -18,7 +18,7 @@ Comment out until we're finished refactoring activity
<a href="{% locale_url projects_show slug=project.slug %}">{{ project.name }}</a>
</nav>
{% if user == project.created_by %}
{% if user.get_profile == project.created_by %}
<div id="project-actions">
<div class="button"><a href="#">{{ _('Edit Project') }}</a></div>
<div class="button"><a href="{% locale_url projects_contact_followers slug=project.slug %}">{{ _('Message Followers') }}</a></div>
@ -89,13 +89,13 @@ Comment out until we're finished refactoring activity
</nav>
<div id="project-lead">
<a href="{% locale_url profiles_show username=project.created_by.username %}">
<img class="member-picture" src="{{ MEDIA_URL }}{{ project.created_by.get_profile.image_or_default }}" height="54" width="54">
<a href="{{ project.created_by.get_absolute_url }}">
<img class="member-picture" src="{{ MEDIA_URL }}{{ project.created_by.image_or_default }}" height="54" width="54">
</a>
<div class="member-details">
<h3 class="member-name">
<a href="{% locale_url profiles_show username=project.created_by.username %}">{{ project.created_by.get_profile.get_full_name_or_username }}</a>
<a href="{{ project.created_by.get_absolute_url }}">{{ project.created_by.name }}</a>
</h3>
<div class="member-actions">
@ -108,7 +108,7 @@ Comment out until we're finished refactoring activity
</div>
<div class="member-bio">
{{ project.created_by.get_profile.bio }}
{{ project.created_by.bio }}
</div>
</div> <!-- /.member-details -->