def save(self, commit=True): """ - Extracts form data - Searches User database for user with same email - Found email, reuse the User object for new Role - Did not find email, create the User object for new Role """ email = self.cleaned_data.get('email') username = self.cleaned_data.get('username') password = self.cleaned_data.get('password') # Create user for new role user = create_user(email, username, password, is_active=True) user.save() print user # Create each role user_account = PostAccount.objects.create( user=user, slug=generate_unique_slug('account','PostAccount') ) user_account.save() print user_account return user_account
def clean_data(self): from core.utils import generate_unique_slug calendars = Calendar.objects.filter(slug=u'') categories = Category.objects.filter(slug=u'') events = Event.objects.filter(slug=u'') self.count = len(calendars) + len(categories) + len(events) """ These loops are intentially not DRY so that we can defer the import of generate_unique_slug to avoid circular dependency issues and not have to do the import within a separate function that repeats per modified object """ if calendars: for idx, cal in enumerate(calendars): try: cal.slug = generate_unique_slug(cal.title, Calendar, False) cal.save() except Exception, e: print e.message print 'Title: ', cal.title print 'Slug: ', cal.slug self.update_progress(idx)
def save(self): """ Make sure the slug is updated when the title is changed """ tag = super(TagForm, self).save(commit=False) tag.slug = generate_unique_slug(tag.name, Tag, True) tag.save() return tag
try: cal.slug = generate_unique_slug(cal.title, Calendar, False) cal.save() except Exception, e: print e.message print 'Title: ', cal.title print 'Slug: ', cal.slug self.update_progress(idx) if categories: for idx, cat in enumerate(categories): try: cat.slug = generate_unique_slug(cat.title, Category, False) cat.save() except Exception, e: print e.message print 'Title: ', cat.title print 'Slug: ', cat.slug self.update_progress(idx) if events: for idx, event in enumerate(events): try: event.slug = generate_unique_slug(event.title, Event, False) event.save() except Exception, e: print e.message print 'Title: ', event.title print 'Slug: ', event.slug self.update_progress(idx)