Working on account settings page, adding GitTip field.

master
Nick Sergeant 2013-01-13 12:51:25 -05:00
parent 7eed101bc7
commit c72bd604cd
13 changed files with 144 additions and 21 deletions

View File

@ -2,9 +2,8 @@ from django.contrib import admin
from accounts.models import UserProfile
class UserProfileAdmin(admin.ModelAdmin):
list_display = ('user', 'is_pro', 'stripe_id',)
search_fields = ('user__username',)
list_display = ('user', 'is_pro', 'stripe_id', 'gittip_username',)
search_fields = ('user__username', 'gittip_username',)
admin.site.register(UserProfile, UserProfileAdmin)

View File

@ -0,0 +1,7 @@
from django.forms import ModelForm
from accounts.models import UserProfile
class AccountForm(ModelForm):
class Meta:
model = UserProfile
fields = ('gittip_username',)

View File

@ -0,0 +1,69 @@
# -*- coding: 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.gittip_username'
db.add_column('accounts_userprofile', 'gittip_username',
self.gf('django.db.models.fields.CharField')(max_length=250, null=True, blank=True),
keep_default=False)
def backwards(self, orm):
# Deleting field 'UserProfile.gittip_username'
db.delete_column('accounts_userprofile', 'gittip_username')
models = {
'accounts.userprofile': {
'Meta': {'object_name': 'UserProfile'},
'gittip_username': ('django.db.models.fields.CharField', [], {'max_length': '250', 'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_pro': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'stripe_id': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'unique': 'True'})
},
'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'})
}
}
complete_apps = ['accounts']

View File

@ -3,8 +3,10 @@ from django.db import models
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
is_pro = models.BooleanField(default=False)
stripe_id = models.CharField(max_length=100, null=True, blank=True)
user = models.ForeignKey(User, unique=True)
is_pro = models.BooleanField(default=False)
stripe_id = models.CharField(max_length=100, null=True, blank=True)
gittip_username = models.CharField(max_length=250, null=True, blank=True)
User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])

View File

@ -10,15 +10,32 @@
{% block content %}
<div class="static-box">
<h2>Account settings</h2>
<h2>Account</h2>
{% if messages %}
{% for message in messages %}
<p class="alert alert-{{ message.tags }}">{{ message }}</p>
{% endfor %}
{% endif %}
<ul>
<li>Username: {{ request.user.username }}</li>
<li><a href="/api/">API</a> key: {{ request.user.api_key.key }}</li>
<li><a href="/api/">API</a> user ID: {{ request.user.id }}</li>
<li><a href="/password/change/">Change password</a></li>
{% if request.user.profile.is_pro %}
<li>Pro since: </li>
<li>GitTip username:</li>
{% endif %}
</ul>
{% if request.user.profile.is_pro %}
<form class="form-horizontal" action="/account/" method="post">
<legend>Edit Pro settings</legend>
<div class="control-group">
<label class="control-label" for="id_gittip_username">GitTip username:</label>
<div class="controls">
<input type="text" id="id_gittip_username" name="gittip_username" value="{{ request.user.profile.gittip_username }}">
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-success">Save</button>
</div>
{% csrf_token %}
</form>
{% endif %}
</div>
{% endblock %}

View File

@ -1,12 +1,28 @@
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect
from annoying.decorators import render_to
from accounts.forms import AccountForm
from django.contrib import messages
from snipts.models import Snipt
@login_required
@render_to('account.html')
def account(request):
return {}
if request.POST:
form = AccountForm(request.POST, instance=request.user.profile)
if form.is_valid():
form.save()
messages.add_message(request, 25, 'Account settings saved.')
return HttpResponseRedirect('/account/')
else:
form = AccountForm()
return {
'form': form
}
@login_required
@render_to('stats.html')

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1371,6 +1371,18 @@ div.site-notice {
}
// Pages
body.account {
div.static-box {
padding-bottom: 0;
padding-top: 10px;
form {
div.control-group:first-of-type {
margin-top: 20px;
}
}
}
}
body.api {
section.main {
div.inner {

View File

@ -98,6 +98,7 @@ TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.media',
'django.core.context_processors.request',
'django.core.context_processors.static',
'django.contrib.messages.context_processors.messages',
)
MIDDLEWARE_CLASSES = (

View File

@ -17,7 +17,7 @@
<li>No ads.</li>
<li>Statistics for "views" and "favorites" of your snipts.</li>
<li>&ldquo;Pro&rdquo; badge throughout the site.</li>
<li>GitTip</li>
<li><a href="https://www.gittip.com/">GitTip</a> integration ("tip" link on every snipt next to your username).</li>
<li>Custom domain for your <a href="https://blog.snipt.net/announcing-the-sniptnet-blogging-platform/">Snipt blog</a>. Contact <a href="mailto:support@snipt.net">support@snipt.net</a> to set it up.</li>
</ul>
{% if request.user.profile.is_pro %}