Permalink
Browse files

added the models for the lug_people app

So far there are no ModelAdmins, forms, or registration code - just
the model classes themselves and the appropriate schema migration.
I will start on the admin next.
  • Loading branch information...
1 parent d36f5f4 commit 602348a44467317c18a8616a63674c7ae09ca759 @leafstorm leafstorm committed Jul 7, 2012
View
No changes.
@@ -0,0 +1,122 @@
+# -*- 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 model 'MemberProfile'
+ db.create_table('lug_people_memberprofile', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('user', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['auth.User'], unique=True)),
+ ('nickname', self.gf('django.db.models.fields.CharField')(max_length=32)),
+ ('real_name', self.gf('django.db.models.fields.CharField')(max_length=64, null=True)),
+ ('preferred_name', self.gf('django.db.models.fields.CharField')(default=u'nick', max_length=4)),
+ ('title', self.gf('django.db.models.fields.CharField')(max_length=64, null=True)),
+ ('role', self.gf('django.db.models.fields.CharField')(default=u'visitor', max_length=8)),
+ ))
+ db.send_create_signal('lug_people', ['MemberProfile'])
+
+ # Adding model 'BitType'
+ db.create_table('lug_people_bittype', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('slug', self.gf('django.db.models.fields.SlugField')(max_length=16)),
+ ('caption', self.gf('django.db.models.fields.CharField')(max_length=32)),
+ ('ordering', self.gf('django.db.models.fields.PositiveIntegerField')(db_index=True)),
+ ('format', self.gf('django.db.models.fields.CharField')(default=u'freetext', max_length=8)),
+ ('instructions', self.gf('django.db.models.fields.CharField')(max_length=128)),
+ ('link_template', self.gf('django.db.models.fields.CharField')(max_length=240, null=True)),
+ ))
+ db.send_create_signal('lug_people', ['BitType'])
+
+ # Adding model 'Bit'
+ db.create_table('lug_people_bit', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('owner', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['lug_people.MemberProfile'])),
+ ('bit_type', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['lug_people.BitType'])),
+ ('data', self.gf('django.db.models.fields.CharField')(max_length=240)),
+ ))
+ db.send_create_signal('lug_people', ['Bit'])
+
+
+ def backwards(self, orm):
+ # Deleting model 'MemberProfile'
+ db.delete_table('lug_people_memberprofile')
+
+ # Deleting model 'BitType'
+ db.delete_table('lug_people_bittype')
+
+ # Deleting model 'Bit'
+ db.delete_table('lug_people_bit')
+
+
+ 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'})
+ },
+ 'lug_people.bit': {
+ 'Meta': {'ordering': "('bit_type__ordering', 'bit_type__caption')", 'object_name': 'Bit'},
+ 'bit_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lug_people.BitType']"}),
+ 'data': ('django.db.models.fields.CharField', [], {'max_length': '240'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lug_people.MemberProfile']"})
+ },
+ 'lug_people.bittype': {
+ 'Meta': {'ordering': "('ordering', 'caption')", 'object_name': 'BitType'},
+ 'caption': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
+ 'format': ('django.db.models.fields.CharField', [], {'default': "u'freetext'", 'max_length': '8'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'instructions': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'link_template': ('django.db.models.fields.CharField', [], {'max_length': '240', 'null': 'True'}),
+ 'ordering': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '16'})
+ },
+ 'lug_people.memberprofile': {
+ 'Meta': {'object_name': 'MemberProfile'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'nickname': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
+ 'preferred_name': ('django.db.models.fields.CharField', [], {'default': "u'nick'", 'max_length': '4'}),
+ 'real_name': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True'}),
+ 'role': ('django.db.models.fields.CharField', [], {'default': "u'visitor'", 'max_length': '8'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True'}),
+ 'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True'})
+ }
+ }
+
+ complete_apps = ['lug_people']
No changes.
View
@@ -0,0 +1,162 @@
+from django.db import models
+from django.contrib.auth.models import User
+from django.core import validators
+from django.core.exceptions import ValidationError
+from django.utils.safestring import mark_safe
+from django.utils.html import escape
+import urllib
+
+PREFERRED_NAME_CHOICES = (
+ (u"nick", u"Nickname"),
+ (u"real", u"Real Name"),
+)
+
+ROLE_CHOICES = (
+ (u"student", u"Student"),
+ (u"alumnus", u"Alumnus"),
+ (u"faculty", u"Faculty"),
+ (u"staff", u"Staff"),
+ (u"visitor", u"Visitor")
+)
+
+class MemberProfile(models.Model):
+ user = models.OneToOneField(User, verbose_name="user")
+ # Names
+ nickname = models.CharField("nickname", max_length=32,
+ help_text="IRC nickname, or other kind of online handle.")
+ real_name = models.CharField("real name", max_length=64, null=True,
+ help_text="The name you use in person.")
+ preferred_name = models.CharField("preferred name", max_length=4,
+ choices=PREFERRED_NAME_CHOICES, default=u"nick",
+ help_text="Which name you would prefer the site to use.")
+ # LUG-related organizational info
+ title = models.CharField("title", max_length=64, null=True,
+ help_text="Official LUG title, as officer or "
+ "committee chair.")
+ role = models.CharField("role", max_length=8,
+ choices=ROLE_CHOICES, default=u"visitor",
+ help_text="What your relationship is to NC State. "
+ "(If you are not affiliated with NC State "
+ "except through the LUG, choose Visitor.)")
+
+ def __unicode__(self):
+ return u"%s (%s)" % self.names if self.has_both_names else self.name
+
+ @property
+ def name(self):
+ if self.real_name is None or self.preferred_name == u"nick":
+ return self.nickname
+ else:
+ return self.real_name
+
+ @property
+ def alternate_name(self):
+ if self.real_name is None or self.preferred_name == u"nick":
+ return self.real_name
+ else:
+ return self.nickname
+
+ @property
+ def names(self):
+ if self.real_name is None or self.preferred_name == u"nick":
+ return (self.nickname, self.real_name)
+ else:
+ return (self.real_name, self.nickname)
+
+ @property
+ def has_both_names(self):
+ return self.real_name is not None
+
+ @property
+ def email(self):
+ return self.user.email
+
+
+class BitType(models.Model):
+ BIT_FORMATS = (
+ (u"freetext", u"Free Text"),
+ (u"url", u"URL"),
+ (u"username", u"Username")
+ )
+
+ slug = models.SlugField("slug", max_length=16,
+ help_text="An internal identifier for bits of this "
+ "type.")
+ caption = models.CharField("caption", max_length=32,
+ help_text="Text to caption the links with on users' "
+ "profiles.")
+ ordering = models.PositiveIntegerField("ordering", db_index=True,
+ help_text="The position of links of this type "
+ "relative to others. Lower numbers are "
+ "sorted first.")
+ format = models.CharField("format", max_length=8,
+ choices=BIT_FORMATS, default=u"freetext",
+ help_text="The format that this bit takes. Used "
+ "to validate things.")
+ instructions = models.CharField("instructions", max_length=128,
+ help_text="Instructions to display for entering bits "
+ "of this type.")
+ link_template = models.CharField("link template", max_length=240, null=True,
+ help_text="A template for turning data of this type "
+ "into a link. Include %s where it should "
+ "be substituted in. Obviously useless for "
+ "URLs.")
+
+ class Meta:
+ ordering = ('ordering', 'caption')
+
+ def __unicode__(self):
+ return u"%s (%s)" % (self.caption, self.slug)
+
+
+username_validator = validators.RegexValidator("^[a-zA-Z0-9_.-]$",
+ u"The data must be a username (if this is "
+ "your actual username, contact leafstorm so he can "
+ "fix the regex).")
+
+url_validator = validators.URLValidator()
+
+class Bit(models.Model):
+ owner = models.ForeignKey(MemberProfile, verbose_name="owner")
+ bit_type = models.ForeignKey(BitType, verbose_name="type")
+ data = models.CharField("data", max_length=240)
+
+ class Meta:
+ ordering = ('bit_type__ordering', 'bit_type__caption')
+
+ def __unicode__(self):
+ return u"%s: %r" % (self.bit_type.caption, self.data)
+
+ def clean(self):
+ format = self.bit_type.format
+ if format == u"url":
+ url_validator(self.data)
+ elif format == u"username":
+ username_validator(self.data)
+
+ @property
+ def data_url(self):
+ bt = self.bit_type
+ if bt.format == u"url":
+ return self.data
+ elif bt.link_template:
+ template = bt.link_template
+ format_idx, qmark_idx = template.find("%s"), template.find("?")
+ if format_idx == -1:
+ return template
+ elif qmark_idx != -1 and format_idx > qmark_idx:
+ return template % urllib.quote_plus(self.data)
+ else:
+ return template % urllib.quote(self.data)
+ else:
+ return None
+
+ @property
+ def data_html(self):
+ url = self.data_url
+ if url:
+ return mark_safe('<a href="%s" rel="nofollow">%s</a>' %
+ (escape(url), escape(self.data)))
+ else:
+ return escape(self.data)
+
View
@@ -0,0 +1,16 @@
+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+
+class SimpleTest(TestCase):
+ def test_basic_addition(self):
+ """
+ Tests that 1 + 1 always equals 2.
+ """
+ self.assertEqual(1 + 1, 2)
View
@@ -0,0 +1 @@
+# Create your views here.
View
@@ -126,8 +126,11 @@
'django.contrib.staticfiles',
'django.contrib.admin',
'south',
+ 'lug_people',
)
+AUTH_PROFILE_MODULE = 'lug_people.MemberProfile'
+
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.

0 comments on commit 602348a

Please sign in to comment.