def finish(self, registration):
        from ututi.lib.security import sign_in_user
        if not registration.location:
            # if there is a university with same title we will use it.
            existing = LocationTag.get_by_title(registration.university_title)
            if existing is not None:
                registration.location = existing
            else:
                registration.location = registration.create_university()

        user = registration.create_user()
        bind_group_invitations(user)

        # TODO: integrity checks here

        meta.Session.add(user)
        registration.completed = True
        # flush before sending any emails
        meta.Session.flush()

        process_registration_invitations(registration)
        meta.Session.commit()

        if user.is_teacher:
            teacher_registered_email(user)

        sign_in_user(user)
        redirect(url(controller='profile', action='register_welcome'))
Exemple #2
0
    def completions(self):
        query = meta.Session.query(LocationTag)
        depth = 0
        widget_id = 0
        if hasattr(self, 'form_result'):
            widget_id = self.form_result.get('widget_id', 0)
            text = self.form_result.get('q', None)
            parent = self.form_result.get('parent', '')
            if text is not None:
                query = query.filter(or_(LocationTag.title_short.op('ILIKE')('%s%%' % text),
                                         LocationTag.title.op('ILIKE')('%s%%' % text)))
            depth = len(parent)
            parent = LocationTag.get_by_title(parent)
            query = query.filter(LocationTag.parent==parent)
        else:
            query = query.filter(LocationTag.parent==None)

        results = []

        for tag in query.order_by(LocationTag.title.asc()).all():
            has_children = meta.Session.query(LocationTag).filter(LocationTag.parent==tag).all() != []
            results.append({'id': tag.title_short, 'title': tag.title, 'path': '/'.join(tag.path), 'has_children': has_children})

        return {'values': results, 'depth': depth, 'id': '#%s .location-%i' % (widget_id, depth)}
Exemple #3
0
 def _to_python(self, value, state):
     if not any(value):
         return None
     return LocationTag.get_by_title(value) or self._notfoundmarker