Revision aa4109d4 snf-astakos-app/astakos/im/models.py

b/snf-astakos-app/astakos/im/models.py
233 233
        through='Membership')
234 234
    
235 235
    __has_signed_terms = False
236
    __groupnames = []
237 236
    
238 237
    owner = models.ManyToManyField(AstakosGroup, related_name='owner', null=True)
239 238
    
......
243 242
    def __init__(self, *args, **kwargs):
244 243
        super(AstakosUser, self).__init__(*args, **kwargs)
245 244
        self.__has_signed_terms = self.has_signed_terms
246
        if self.id:
247
            self.__groupnames = [g.name for g in self.astakos_groups.all()]
248
        else:
245
        if not self.id:
249 246
            self.is_active = False
250 247
    
251 248
    @property
......
308 305
            self.activation_sent = None
309 306
        
310 307
        super(AstakosUser, self).save(**kwargs)
311
        
312
        # set group if does not exist
313
        groupname = 'shibboleth' if self.provider == 'shibboleth' else 'default'
314
        if groupname not in self.__groupnames:
315
            try:
316
                group = AstakosGroup.objects.get(name = groupname)
317
                Membership(group=group, person=self, date_joined=datetime.now()).save()
318
            except AstakosGroup.DoesNotExist, e:
319
                logger.exception(e)
320 308
    
321 309
    def renew_token(self):
322 310
        md5 = hashlib.md5()
......
576 564

  
577 565
post_save.connect(superuser_post_save, sender=User)
578 566

  
567
def set_default_group(sender, instance, created, **kwargs):
568
    if not created:
569
        return
570
    try:
571
        default = AstakosGroup.objects.get(name = 'default')
572
        Membership(group=default, person=instance, date_joined=datetime.now()).save()
573
    except AstakosGroup.DoesNotExist, e:
574
        logger.exception(e)
575

  
576
post_save.connect(set_default_group, sender=AstakosUser)
577

  
579 578
def get_resources():
580 579
    # use cache
581 580
    return Resource.objects.select_related().all()

Also available in: Unified diff