def create(request): if not request.is_xhr: if request.method == 'POST': p = Project() factories = {'active': bool, 'featured': bool, 'tags': lambda x: x.split(' ')} keys = ( 'active', 'featured', 'tags' , 'category', 'name', 'text', 'preview_small', 'preview_big' , 'download_mac', 'download_pc') p['id'] = make_id(request.form.get('name')) for k in keys: v = request.form.get(k) p[k] = (factories[k](v) if k in factories else v) resp = Project.create(p) return redirect(url_for('update', docid=p['id'])) elif request.method == 'GET': context = { 'project': {}, 'user': { 'roles': request.session.get('roles', []) }, 'debug': request.debug } return render_html('projects/create.html', context)
def retrieve(request, docid): if request.method == 'GET': project = Project.retrieve(docid) if not request.is_xhr: context = { "project": project, 'user': { 'roles': request.session.get('roles', []) }, 'debug': request.debug } return render_html('projects/retrieve.html',context)
def up_list(req): """docstring for up_list""" if req.method == 'GET': docs = [wrap(p) for p in Up.list(req.session['username'])] context = { "docs": docs } return render_html('u/list.html', context) else: raise NotFound
def login(request): """docstring for login""" if request.method == 'GET': context = {'referrer': request.args.get('referrer', url_for('index'))} return render_html('users/login.html', context) elif request.method == 'POST': username = request.form.get('username') password = request.form.get('password') user = User.db.get(username) if user and User.chkpwd(password, user['password']): request.session['id'] = uuid.uuid4().hex request.session['roles'] = user['roles'] or [] request.session['username'] = user['_id'] user['session'] = request.session user['last_login'] = time.time() User.update(user) red = redirect(request.args.get('referrer', url_for('index'))) return red context = { 'referrer': request.args['referrer'], 'user': { 'roles': request.session.get('roles', []) }, 'debug': request.debug } return render_html('users/login.html', context)
def index(request): if not request.is_xhr: context = { 'featured': [wrap(p) for p in Project.allFeatured()], 'active': reversed([wrap(p) for p in Project.allActiveNotFeatured()]), 'user': { 'roles': request.session.get('roles', []) }, 'debug': request.debug } return render_html('index.html', context) else: raise NotImplementedError('nothing here')
def plist(request): active_results = [wrap(p) for p in Project.allActive()] if not request.is_xhr and request.method == 'GET': context = { 'active': reversed(active_results), 'user': { 'roles': request.session.get('roles', []) }, 'debug': request.debug } return render_html('/projects/list.html', context) elif request.is_xhr and request.method == 'GET': return Response(simplejson.dumps(active_results), mimetype='application/json')
def not_found(request): return render_html('not_found.html')