added homepage url and twitter id to user profile model and form; reverted signalling
relying on signals to ensure that there's always a profile record turned out to be a bad idea; django social auth signals are poorly architected for this; and so it doesn't work. Catching exceptions worked just fine, so I went back to that. Homepage and twitter buttons now show only if they've been entered in settings. Twitter handle works with or without '@' entered.pull/1/head
parent
b1cce24154
commit
559ff63aa3
|
@ -0,0 +1,133 @@
|
|||
# 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):
|
||||
|
||||
# Adding field 'UserProfile.home_url'
|
||||
db.add_column('core_userprofile', 'home_url', self.gf('django.db.models.fields.URLField')(default='', max_length=200, blank=True), keep_default=False)
|
||||
|
||||
# Adding field 'UserProfile.twitter_id'
|
||||
db.add_column('core_userprofile', 'twitter_id', self.gf('django.db.models.fields.CharField')(default='', max_length=15, blank=True), keep_default=False)
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
|
||||
# Deleting field 'UserProfile.home_url'
|
||||
db.delete_column('core_userprofile', 'home_url')
|
||||
|
||||
# Deleting field 'UserProfile.twitter_id'
|
||||
db.delete_column('core_userprofile', 'twitter_id')
|
||||
|
||||
|
||||
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'})
|
||||
},
|
||||
'core.author': {
|
||||
'Meta': {'object_name': 'Author'},
|
||||
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'editions': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'authors'", 'symmetrical': 'False', 'to': "orm['core.Edition']"}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '500'})
|
||||
},
|
||||
'core.campaign': {
|
||||
'Meta': {'object_name': 'Campaign'},
|
||||
'activated': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
|
||||
'amazon_receiver': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}),
|
||||
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'deadline': ('django.db.models.fields.DateTimeField', [], {}),
|
||||
'description': ('django.db.models.fields.TextField', [], {'null': 'True'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '500', 'null': 'True'}),
|
||||
'paypal_receiver': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}),
|
||||
'suspended': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
|
||||
'suspended_reason': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'target': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '14', 'decimal_places': '2'}),
|
||||
'withdrawn': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
|
||||
'withdrawn_reason': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'work': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'campaigns'", 'to': "orm['core.Work']"})
|
||||
},
|
||||
'core.edition': {
|
||||
'Meta': {'object_name': 'Edition'},
|
||||
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'description': ('django.db.models.fields.TextField', [], {'default': "''", 'null': 'True'}),
|
||||
'googlebooks_id': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'isbn_10': ('django.db.models.fields.CharField', [], {'max_length': '10', 'null': 'True'}),
|
||||
'isbn_13': ('django.db.models.fields.CharField', [], {'max_length': '13', 'null': 'True'}),
|
||||
'language': ('django.db.models.fields.CharField', [], {'max_length': '2', 'null': 'True'}),
|
||||
'publication_date': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
|
||||
'publisher': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||
'title': ('django.db.models.fields.CharField', [], {'max_length': '1000'}),
|
||||
'work': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'editions'", 'null': 'True', 'to': "orm['core.Work']"})
|
||||
},
|
||||
'core.subject': {
|
||||
'Meta': {'object_name': 'Subject'},
|
||||
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'editions': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'subjects'", 'symmetrical': 'False', 'to': "orm['core.Edition']"}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '500'})
|
||||
},
|
||||
'core.userprofile': {
|
||||
'Meta': {'object_name': 'UserProfile'},
|
||||
'home_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'tagline': ('django.db.models.fields.CharField', [], {'max_length': '140', 'blank': 'True'}),
|
||||
'twitter_id': ('django.db.models.fields.CharField', [], {'max_length': '15', 'blank': 'True'}),
|
||||
'user': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'profile'", 'unique': 'True', 'to': "orm['auth.User']"})
|
||||
},
|
||||
'core.wishlist': {
|
||||
'Meta': {'object_name': 'Wishlist'},
|
||||
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'user': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'wishlist'", 'unique': 'True', 'to': "orm['auth.User']"}),
|
||||
'works': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'wishlists'", 'symmetrical': 'False', 'to': "orm['core.Work']"})
|
||||
},
|
||||
'core.work': {
|
||||
'Meta': {'object_name': 'Work'},
|
||||
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'openlibrary_id': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True'}),
|
||||
'title': ('django.db.models.fields.CharField', [], {'max_length': '1000'})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['core']
|
|
@ -189,6 +189,8 @@ class Wishlist(models.Model):
|
|||
class UserProfile(models.Model):
|
||||
user = models.OneToOneField(User, related_name='profile')
|
||||
tagline = models.CharField(max_length=140, blank=True)
|
||||
home_url = models.URLField(blank=True)
|
||||
twitter_id = models.CharField(max_length=15, blank=True)
|
||||
|
||||
from regluit.core import signals
|
||||
from regluit.payment.manager import PaymentManager
|
||||
|
|
|
@ -15,7 +15,6 @@ def facebook_extra_values(sender, user, response, details, **kwargs):
|
|||
|
||||
pre_update.connect(facebook_extra_values, sender=FacebookBackend)
|
||||
|
||||
|
||||
def create_user_objects(sender, created, instance, **kwargs):
|
||||
# use get_model to avoid circular import problem with models
|
||||
try:
|
||||
|
@ -28,7 +27,6 @@ def create_user_objects(sender, created, instance, **kwargs):
|
|||
# this can happen when creating superuser during syncdb since the
|
||||
# core_wishlist table doesn't exist yet
|
||||
return
|
||||
|
||||
|
||||
post_save.connect(create_user_objects, sender=User)
|
||||
post_save.connect(create_api_key, sender=User)
|
||||
|
|
|
@ -11,7 +11,12 @@ class ProfileForm(forms.ModelForm):
|
|||
exclude = 'user'
|
||||
widgets = {
|
||||
'tagline': forms.Textarea(attrs={'cols': 35, 'rows': 4}),
|
||||
'twitter_id': forms.TextInput(attrs={'label': 'Twitter Handle', 'maxlength': 16}),
|
||||
}
|
||||
|
||||
def clean_twitter_id(self):
|
||||
twitter_id=self.cleaned_data['twitter_id']
|
||||
return twitter_id.lstrip('@')
|
||||
|
||||
class UserData(forms.Form):
|
||||
username = forms.RegexField(
|
||||
|
@ -23,7 +28,6 @@ class UserData(forms.Form):
|
|||
'invalid': _("This value may contain only letters, numbers and @/./+/-/_ characters.")
|
||||
}
|
||||
)
|
||||
# oldusername = forms.CharField(max_length=30)
|
||||
|
||||
|
||||
def clean_username(self):
|
||||
|
|
|
@ -108,9 +108,17 @@ how do I integrate the your wishlist thing with the tabs thing?
|
|||
</div>
|
||||
<div class="user-block4">
|
||||
<div class="social">
|
||||
<a href="#"><img src="/static/images/header/icon-home.png" alt="Home" title="Home" /></a>
|
||||
<a href="#"><img src="/static/images/header/icon-facebook.png" alt="Facebook" title="Facebook" /></a>
|
||||
<a href="#"><img src="/static/images/header/icon-twitter.png" alt="twitter" title="twitter" /></a>
|
||||
{% if supporter.profile.home_url %}
|
||||
<a href="{{ supporter.profile.home_url }}">
|
||||
<img src="/static/images/header/icon-home.png" alt="{{ supporter }}'s Homepage" title="{{ supporter }}'s Homepage" />
|
||||
</a>
|
||||
{% endif %}
|
||||
<a href="#"><img src="/static/images/header/icon-facebook.png" alt="{{ supporter }}'s Facebook" title="{{ supporter }}'s Facebook" /></a>
|
||||
{% if supporter.profile.twitter_id %}
|
||||
<a href="https://twitter.com/#!/{{ supporter.profile.twitter_id }}">
|
||||
<img src="/static/images/header/icon-twitter.png" alt="{{ supporter }}'s Twitter" title="{{ supporter }}'s Twitter" />
|
||||
</a>
|
||||
{% endif %}
|
||||
<a href="#"><img src="/static/images/header/icon-google.png" alt="google" title="google" /></a>
|
||||
<a href="#"><img src="/static/images/header/icon-group.png" alt="group" title="group" /></a></div>
|
||||
</div>
|
||||
|
@ -125,33 +133,31 @@ how do I integrate the your wishlist thing with the tabs thing?
|
|||
</div>
|
||||
{% ifequal supporter request.user %}
|
||||
<div class="user-block-hide">
|
||||
<form method="POST" action="">
|
||||
{% csrf_token %}
|
||||
<div class="block block1">
|
||||
<div class="block-inner">
|
||||
<h3><a class="profile-edit" href="#">Profile / edit</a></h3>
|
||||
<form method="POST" action="">
|
||||
{% csrf_token %}
|
||||
{{ profile_form.as_p }}
|
||||
<h3><a class="profile-edit" href="#">Your Tagline</a></h3>
|
||||
{{ profile_form.tagline }}
|
||||
|
||||
<input class="profile-save" type="submit" name="submit" value="Update" id="submit">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="block block2">
|
||||
<h3 class="title">Links</h3>
|
||||
<div class="check-list">
|
||||
<input type="checkbox" />
|
||||
<label>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</label>
|
||||
<label>Your homepage URL:</label>
|
||||
{{ profile_form.home_url }}
|
||||
</div>
|
||||
<div class="check-list">
|
||||
<input type="checkbox" />
|
||||
<label>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</label>
|
||||
<label>Your Twitter handle:</label>
|
||||
{{ profile_form.twitter_id }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="block block3">
|
||||
<h3 class="title">Privacy</h3>
|
||||
<h3 class="title">Other Stuff</h3>
|
||||
<div class="check-list">
|
||||
<input type="checkbox" />
|
||||
<label>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</label>
|
||||
</div>
|
||||
<div class="check-list">
|
||||
|
@ -160,8 +166,9 @@ how do I integrate the your wishlist thing with the tabs thing?
|
|||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
{% endifequal %}
|
||||
{% endifequal %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -73,7 +73,11 @@ def supporter(request, supporter_username):
|
|||
# following block to support profile admin form in supporter page
|
||||
if request.user.is_authenticated() and request.user.username == supporter_username:
|
||||
if request.method == 'POST':
|
||||
profile_obj=request.user.get_profile()
|
||||
try:
|
||||
profile_obj=request.user.get_profile()
|
||||
except ObjectDoesNotExist:
|
||||
profile_obj= models.UserProfile()
|
||||
profile_obj.user=request.user
|
||||
profile_form = ProfileForm(data=request.POST,instance=profile_obj)
|
||||
if profile_form.is_valid():
|
||||
profile_form.save()
|
||||
|
|
Loading…
Reference in New Issue