Пример #1
0
 def index(self):
     
     """
         Функция для отображения физуального интерфейса пользователя
     """
     
     if session.has_key('login'):
         return render('/login/login.mako.html')
     else:
         return render('/login/login.mako.html')
Пример #2
0
 def index(self, format='html'):
     if request.params:
         page = request.params['page']
     else:
         page = 1
     c.courses = webhelpers.paginate.Page(Session.query(model.Course),
                                          page=page,
                                          items_per_page=10)
     if 'partial' in request.params:
         return render('/course/list-partial.html')
     else:
         return render('/course/list-full.html')
Пример #3
0
 def index(self, format='html'):
     a = request.environ['authkit.users']
     student_group_id = Session.query(model.Group).filter_by(name='student').first().uid
     c.students = Session.query(model.Users).filter_by(group_id=student_group_id).all()
     if request.params:
         page = request.params['page']
     else:
         page = 1
     c.students = webhelpers.paginate.Page(c.students, page=page, items_per_page=5)
     if 'partial' in request.params:
         return render('/student/list-partial.html')
     else:
         return render('/student/list-full.html')
Пример #4
0
 def signin(self):
     if not h.auth.authorized(h.auth.is_valid_user):
         if not request.params:
             return render('/derived/account/signin.html')
         schema = LoginForm()
         try:
             form_result = schema.to_python(request.params)
         except formencode.validators.Invalid, error:
             c.form_result = error.value
             c.form_errors = error.error_dict or {}
             h.flash('Dang nhap that bai', 'error')
             return render('/derived/account/signin.html')
         else:
             user = meta.Session.query(model.Users). \
                 filter_by(email=request.params['email'],
                           password=request.params['password']). \
                 first()
             if user:
                 if user.group_id == 1:
                     session['user'] = user
                     session.save()
                     if request.environ['HTTP_REFERER']:
                         print request.environ['HTTP_REFERER']
                         redirect(request.environ['HTTP_REFERER'])
                 else:
                     user_info = meta.Session.query(model.UsersInfo). \
                         filter_by(user_id=user.id). \
                         first()
                     if user_info.active == 1:
                         session['user'] = user
                         session.save()
                         if request.environ['HTTP_REFERER']:
                             print request.environ['HTTP_REFERER']
                             redirect(request.environ['HTTP_REFERER'])
                     else:
                         h.flash(
                             'Tai khoan cua ban chua duoc active, Vui long xac nhan bang dia chi email!',
                             'error')
                         return render('/derived/account/signin.html')
             else:
                 c.form_result = {
                     'email': request.params['email'],
                     'password': request.params['password']
                 }
                 c.form_errors = {
                     'email':
                     'Email va Password khong khop voi bat ki tai khoan nao'
                 }
                 if c.form_errors:
                     h.flash('Dang nhap that bai', 'error')
                 return render('/derived/account/signin.html')
Пример #5
0
 def signedin(self):
     # The actual removal of the AuthKit cookie occurs when the response passes
     # through the AuthKit middleware, we simply need to display a page
     # confirming the user is signed out
     # print(1)
     # print(authorize(h.auth.has_auth_kit_role('admin')))
     return render('/derived/account/signedin.html')
Пример #6
0
 def admin_new(self):
     student_group_id = Session.query(
         model.Group).filter_by(name='student').first().uid
     c.students = Session.query(model.Users).filter_by(group_id=student_group_id). \
                     join(model.UsersInfo).filter_by(active=1).all()
     c.courses = Session.query(model.Course)
     return render('/register/admin_new.html')
Пример #7
0
 def create(self):
     schema = CourseForm()
     try:
         form_result = schema.to_python(request.params)
     except formencode.validators.Invalid, error:
         c.form_result = error.value
         c.form_errors = error.error_dict or {}
         return render('/course/admin_new.html')
Пример #8
0
 def update(self, id):
     schema = CourseForm()
     c.id = int(id)
     try:
         form_result = schema.to_python(request.params, c)
     except formencode.validators.Invalid, error:
         c.form_result = error.value
         c.form_errors = error.error_dict or {}
         return render('/course/edit.html')
Пример #9
0
 def create(self):
     schema = StudentForm()
     try:
         form_result = schema.to_python(request.params)
     except formencode.validators.Invalid, error:
         c.form_result = error.value
         c.form_errors = error.error_dict or {}
         h.flash('Tao moi that bai', 'error')
         return render('/student/new.html')
Пример #10
0
 def edit(self, id, format='html'):
     schema = StudentForm()
     student = Session.query(model.Users).filter(Users.id == id).first()
     dict = student.__dict__
     c.form_result = dict.update(student.user_info.__dict__)
     c.form_result = dict
     c.form_errors = {}
     c.id = int(id)
     return render('/student/edit.html')
Пример #11
0
 def course(self):
     if request.method == "GET":
         search_text = request.params['search_text']
     else:
         search_text = ''
     if request.params.has_key('page'):
         page = request.params['page']
     else:
         page = 1
     c.course = Session.query(model.Course).filter(
         Course.name.like('%' + search_text + '%')).all()
     c.courses = webhelpers.paginate.Page(c.course,
                                          page=page,
                                          items_per_page=5)
     c.form_result = request.params
     if 'partial' in request.params:
         return render('/search/search-list-course-partial.html')
     else:
         return render('/search/search-list-course-full.html')
Пример #12
0
 def show(self, id, format='html'):
     c.student = Session.query(model.Users).filter(Users.id == id).first()
     if not c.student:
         abort(404, '404 Not Found')
     if request.environ['REMOTE_USER'] == c.student.email or \
             ('admin' in request.environ['authkit.users'].user_group(request.environ['REMOTE_USER']) and \
              'admin' not in request.environ['authkit.users'].user_group(c.student.email)):
         c.courses = Session.query(model.Course).all()
         return render('/student/show.html')
     else:
         abort(403)
Пример #13
0
 def update(self, id):
     schema = StudentForm()
     student = Session.query(model.Users).filter(Users.id == id).first()
     c.id = int(id)
     if not student:
         abort(404, '404 Not Found')
     try:
         form_result = schema.to_python(request.params, c)
     except formencode.validators.Invalid, error:
         c.form_result = error.value
         c.form_errors = error.error_dict or {}
         h.flash('Cap nhat that bai', 'error')
         return render('/student/edit.html')
Пример #14
0
 def student(self):
     if request.method == "GET":
         search_text = request.params['search_text']
     else:
         search_text = ''
     if request.params.has_key('page'):
         page = request.params['page']
     else:
         page = 1
     student_group_id = Session.query(
         model.Group).filter_by(name='student').first().uid
     c.student = Session.query(model.Users).filter(
         Users.email.like('%' + search_text + '%'),
         Users.group_id == student_group_id).all()
     c.students = webhelpers.paginate.Page(c.student,
                                           page=page,
                                           items_per_page=5)
     c.form_result = request.params
     if 'partial' in request.params:
         return render('/search/search-list-student-partial.html')
     else:
         return render('/search/search-list-student-full.html')
Пример #15
0
 def document(self):
     """Render the error document"""
     request = self._py_object.request
     resp = request.environ.get('pylons.original_response')
     code = cgi.escape(request.GET.get('code', ''))
     content = cgi.escape(request.GET.get('message', ''))
     if resp:
         content = literal(resp.status)
         code = code or cgi.escape(str(resp.status_int))
     if not code:
         raise Exception('No status code was found')
     c.code = code
     c.message = content
     return render('/derived/error/document.html')
Пример #16
0
    def edit_static_page(self):

        static_pages_model = StaticPagesModel
        page_translitedTitle = request.params.get('page', 'add_new_page')

        page = static_pages_model.get_by_translitedTitle(page_translitedTitle) 

        if page_translitedTitle == 'add_new_page' or page is None:
            c.title = ''
            c.content = ''
            c.translitedTitle = None
        else:
            c.title = page['title']
            c.content = page['content']
            c.translitedTitle = page['translitedTitle']

        return render('/settings/editStaticPage.mako.html')
Пример #17
0
 def show(self, id, format='html'):
     c.course = Session.query(model.Course).filter(Course.id == id).one()
     return render('/course/show.html')
Пример #18
0
 def search_student(self):
     return render('/search/student.html')
Пример #19
0
 def index(self):
     return render('/base/main.html')
Пример #20
0
 def user_new(self):
     c.courses = Session.query(model.Course)
     if request.environ.has_key('REMOTE_USER') and \
                     'admin' not in request.environ['authkit.users'].user_group(request.environ['REMOTE_USER']):
         return render('/register/user_new.html')
     return redirect(url(controller='students', action='index'))
Пример #21
0
 def notice(self, format='html'):
     return render('/student/notice.html')
Пример #22
0
 def new(self, format='html'):
     if request.environ.has_key('REMOTE_USER') and \
                     'admin' not in request.environ['authkit.users'].user_group(request.environ['REMOTE_USER']):
         h.flash('Ban da dang nhap. Signout de tiep tuc', 'error')
         return redirect(h.url(controller='account', action='signedin'))
     return render('/student/new.html')
Пример #23
0
 def new(self, format='html'):
     return render('/course/new.html')
Пример #24
0
 def signout(self):
     # The actual removal of the AuthKit cookie occurs when the response passes
     # through the AuthKit middleware, we simply need to display a page
     # confirming the user is signed out
     del session['user']
     return render('/derived/account/signedout.html')
Пример #25
0
 def search_course(self):
     return render('search/course.html')
Пример #26
0
 def edit(self, id, format='html'):
     schema = CourseForm()
     course = Session.query(model.Course).filter(Course.id == id).one()
     c.form_result = schema.from_python(course.__dict__)
     c.form_errors = {}
     return render('/course/edit.html')
Пример #27
0
        else:
            name = request.params['name']
            email = request.params['email']
            password = request.params['password']
            string = name + email + password
            token = hashlib.md5(string).hexdigest()
            c.user = model.Users(email=email, password=password)
            c.user.user_info = model.UsersInfo(name=name, token=token)
            Session.add(c.user)
            request.environ['authkit.users'].user_set_group(c.user.email, 'student')
            Session.commit()

            print 'commit xong'
            from rq import Queue
            from manager.queue.worker import conn
            email_content = render('/layout/email_layout/signup.html')
            print email_content
            q = Queue(connection=conn)
            print c.user.email
            q.enqueue(h.send_mail, 'Subject', email_content, c.user.email)

            h.flash('Successfully', 'success')
            return redirect(url(controller='students', action='notice'))

    def notice(self, format='html'):
        return render('/student/notice.html')

    def new(self, format='html'):
        if request.environ.has_key('REMOTE_USER') and \
                        'admin' not in request.environ['authkit.users'].user_group(request.environ['REMOTE_USER']):
            h.flash('Ban da dang nhap. Signout de tiep tuc', 'error')