diff --git a/accounts/__init__.py b/accounts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/accounts/admin.py b/accounts/admin.py new file mode 100644 index 0000000..51e6cef --- /dev/null +++ b/accounts/admin.py @@ -0,0 +1,18 @@ +from django.contrib import admin + +from .models import Account, Badge, BadgeGrant + +# Register your models here. +class AccountAdmin(admin.ModelAdmin): + list_display = ('user', 'acctname') +admin.site.register(Account, AccountAdmin) + +class BadgeAdmin(admin.ModelAdmin): + list_display = ('name', 'img_url') +admin.site.register(Badge, BadgeAdmin) + +class GrantAdmin(admin.ModelAdmin): + list_display = ('badge', 'account', 'expires', 'granted_by') +admin.site.register(BadgeGrant, GrantAdmin) + + diff --git a/accounts/apps.py b/accounts/apps.py new file mode 100644 index 0000000..9b3fc5a --- /dev/null +++ b/accounts/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class AccountsConfig(AppConfig): + name = 'accounts' diff --git a/accounts/migrations/0001_initial.py b/accounts/migrations/0001_initial.py new file mode 100644 index 0000000..113aebb --- /dev/null +++ b/accounts/migrations/0001_initial.py @@ -0,0 +1,55 @@ +# Generated by Django 2.0 on 2018-02-02 22:05 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Account', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('acctname', models.CharField(blank=True, max_length=150, verbose_name='Account Name')), + ], + options={ + 'ordering': ('user__username',), + }, + ), + migrations.CreateModel( + name='Badge', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=64, verbose_name='Badge Name')), + ('img_url', models.URLField(verbose_name='Badge Image')), + ], + ), + migrations.CreateModel( + name='BadgeGrant', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('expires', models.DateTimeField()), + ('account', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='accounts.Account')), + ('badge', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='accounts.Badge')), + ('granted_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)), + ], + ), + migrations.AddField( + model_name='account', + name='badges', + field=models.ManyToManyField(through='accounts.BadgeGrant', to='accounts.Badge'), + ), + migrations.AddField( + model_name='account', + name='user', + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/accounts/migrations/__init__.py b/accounts/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/accounts/models.py b/accounts/models.py new file mode 100644 index 0000000..08cd51d --- /dev/null +++ b/accounts/models.py @@ -0,0 +1,70 @@ +from django.db import models +from django.contrib.sites.models import Site +from django.contrib.auth.models import User, Group, AnonymousUser +from django.utils.translation import ugettext_lazy as _ + +import pytz +import datetime +import hashlib + +class Account(models.Model): + " Store account information about a user " + + user = models.OneToOneField(User, on_delete=models.CASCADE) + acctname = models.CharField(_("Account Name"), max_length=150, blank=True) + + badges = models.ManyToManyField('Badge', through='BadgeGrant') + + class Meta: + ordering = ('user__username',) + + def __str__(self): + try: + if self.acctname: + return self.acctname + return "%s" % self.user.username + except: + return "Unknown Account" + + +def _getUserAccount(self): + if not self.is_authenticated: + return Account() + + profile, created = Account.objects.get_or_create(user=self) + + if created: + if self.first_name: + if self.last_name: + profile.acctname = '%s %s' % (self.first_name, self.last_name) + else: + profile.acctname = self.first_name + + profile.save() + + return profile + +def _getAnonAccount(self): + return Account(acctname=_('Anonymous User')) + +User.account = property(_getUserAccount) +AnonymousUser.account = property(_getAnonAccount) + +class Badge(models.Model): + name = models.CharField(_('Badge Name'), max_length=64, blank=False, null=False) + img_url = models.URLField(_('Badge Image'), blank=False, null=False) + + def __str__(self): + return self.name + +class BadgeGrant(models.Model): + badge = models.ForeignKey(Badge, on_delete=models.CASCADE) + account = models.ForeignKey(Account, on_delete=models.CASCADE) + + expires = models.DateTimeField() + granted_by = models.ForeignKey(User, on_delete=models.SET_NULL, null=True) + + def __str__(self): + return '%s for %s' % (self.badge.name, self.account.acctname) + + diff --git a/accounts/tests.py b/accounts/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/accounts/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/accounts/views.py b/accounts/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/accounts/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/get_together/settings.py b/get_together/settings.py index 54a1a72..fea1042 100644 --- a/get_together/settings.py +++ b/get_together/settings.py @@ -46,6 +46,7 @@ INSTALLED_APPS = [ 'get_together', 'events', + 'accounts', ] LOGIN_URL = 'login' diff --git a/get_together/static/img/badges/gold_tier.png b/get_together/static/img/badges/gold_tier.png new file mode 100644 index 0000000..2da7c5d Binary files /dev/null and b/get_together/static/img/badges/gold_tier.png differ diff --git a/get_together/static/img/badges/silver_tier.png b/get_together/static/img/badges/silver_tier.png new file mode 100644 index 0000000..d47cd8d Binary files /dev/null and b/get_together/static/img/badges/silver_tier.png differ diff --git a/get_together/templates/get_together/events/show_event.html b/get_together/templates/get_together/events/show_event.html index ddbe1b6..9291a8c 100644 --- a/get_together/templates/get_together/events/show_event.html +++ b/get_together/templates/get_together/events/show_event.html @@ -1,6 +1,20 @@ {% extends "get_together/base.html" %} {% load markup %} +{% block styles %} + +{% endblock %} + {% block content %}
@@ -38,8 +52,9 @@
{% for attendee in attendee_list %}
-
- +
+ + {% for badge in attendee.user.user.account.badges.all %}{% endfor %}
{{attendee.user}} {{ attendee.status_name }}
{% if attendee.role > 0 %}{{ attendee.role_name }}{% endif %} diff --git a/get_together/templates/get_together/teams/show_team.html b/get_together/templates/get_together/teams/show_team.html index 01a9efe..e3a2567 100644 --- a/get_together/templates/get_together/teams/show_team.html +++ b/get_together/templates/get_together/teams/show_team.html @@ -1,6 +1,20 @@ {% extends "get_together/base.html" %} {% load markup %} +{% block styles %} + +{% endblock %} + {% block content %}
@@ -43,8 +57,9 @@

Members


{% for member in member_list %}
-
- +
+ + {% for badge in member.user.user.account.badges.all %}{% endfor %}
{{member.user}}
{% if member.role > 0 %}{{ member.role_name }}{% endif %}