Changeset - 35b75b6f963c
[Not reviewed]
0 1 0
James Polley - 7 years ago 2017-09-30 01:01:39
jp@jamezpolley.com
Badger should fail gracefully if auth_groups hasn't been populated

Let's say you've just installed symposion for the first time, and
you're running the intial `./manage.py migrate`

In that circumstance, there isn't an auth_group table. Naturally this
means you get Some Errors when trying to look for a particular group.

This change handles that error and drives on.
1 file changed with 8 insertions and 2 deletions:
0 comments (0 inline, 0 general)
vendor/registrasion/registrasion/contrib/badger.py
Show inline comments
...
 
@@ -22,12 +22,13 @@ import subprocess
 

	
 
import pdb
 

	
 
from django.core.management.base import BaseCommand
 

	
 
from django.contrib.auth.models import User, Group
 
from django.db.utils import OperationalError
 
from pinaxcon.registrasion.models import AttendeeProfile
 
from registrasion.controllers.cart import CartController
 
from registrasion.controllers.invoice import InvoiceController
 
from registrasion.models import Voucher
 
from registrasion.models import Attendee
 
from registrasion.models import Product
...
 
@@ -121,14 +122,19 @@ def set_colour(soup, slice_id, colour):
 
    elem = soup.find(".//*[@id='%s']" % slice_id)
 
    if elem is None:
 
        raise ValueError('could not find tag id=%s' % slice_id)
 
    style = elem.get('style')
 
    elem.set('style', style.replace('fill:#316a9a', 'fill:#%s' % colour))
 

	
 
Volunteers = Group.objects.filter(name='Conference volunteers').first().user_set.all()
 
Organisers = Group.objects.filter(name='Conference organisers').first().user_set.all()
 
## It's possible that this script will be run before the database has been populated
 
try:
 
    Volunteers = Group.objects.filter(name='Conference volunteers').first().user_set.all()
 
    Organisers = Group.objects.filter(name='Conference organisers').first().user_set.all()
 
except (OperationalError, AttributeError):
 
    Volunteers = []
 
    Organisers = []
 

	
 
def is_volunteer(attendee):
 
    '''
 
    Returns True if attendee is in the Conference volunteers group.
 
    False otherwise.
 
    '''
0 comments (0 inline, 0 general)