def make_response(data, marshal_table, cursors=None): if util.is_iterable(data): response = { 'status': 'success', 'count': len(data), 'now': datetime.utcnow().isoformat(), 'result': map(lambda l: flask_restful.marshal(l, marshal_table), data), } if cursors: if isinstance(cursors, dict): if cursors.get('next'): response['next_cursor'] = cursors['next'] response['next_url'] = util.generate_next_url(cursors['next']) if cursors.get('prev'): response['prev_cursor'] = cursors['prev'] response['prev_url'] = util.generate_next_url(cursors['prev']) else: response['next_cursor'] = cursors response['next_url'] = util.generate_next_url(cursors) return util.jsonpify(response) return util.jsonpify({ 'status': 'success', 'now': datetime.utcnow().isoformat(), 'result': flask_restful.marshal(data, marshal_table), })
def resource_grid(): resource_dbs, cursors = model.Resource.get_dbs( model.Resource.query(model.Resource.hotness > 0), limit=20, prev_cursor=True, order='-hotness') city_filter_dbs, _ = model.Filter.get_dbs( filter_property='city', order='-photos_count', ) tag_filter_dbs, _ = model.Filter.get_dbs( filter_property='tags', order='-photos_count', ) return flask.render_template( 'resource/resource_grid.html', html_class='resource-grid', title=u'تصفح الصور', resource_dbs=resource_dbs, city_filter_dbs=city_filter_dbs, tag_filter_dbs=tag_filter_dbs, next_url=util.generate_next_url(cursors.get('next')), prev_url=util.generate_next_url(cursors.get('prev')), api_url=flask.url_for('api.resource.list'), )
def make_response(data, marshal_table, cursors=None): if util.is_iterable(data): response = { 'status': 'success', 'count': len(data), 'now': datetime.utcnow().isoformat(), 'result': [flask_restful.marshal(d, marshal_table) for d in data], } if cursors: if isinstance(cursors, dict): if cursors.get('next'): response['next_cursor'] = cursors['next'] response['next_url'] = util.generate_next_url( cursors['next']) if cursors.get('prev'): response['prev_cursor'] = cursors['prev'] response['prev_url'] = util.generate_next_url( cursors['prev']) else: response['next_cursor'] = cursors response['next_url'] = util.generate_next_url(cursors) return util.jsonpify(response) return util.jsonpify({ 'status': 'success', 'now': datetime.utcnow().isoformat(), 'result': flask_restful.marshal(data, marshal_table), })
def resource_search(): query = model.Resource.query(model.Resource.hotness > 0) tags = util.param('tags', list) current_filter = None if tags: query = query.filter(model.Resource.tags.IN(tags)) current_filter = 'tags=' + tags[0] address_first_line = util.param('address_first_line') if address_first_line: query = query.filter( model.Resource.address_first_line == address_first_line) current_filter = 'address_first_line=' + address_first_line address_second_line = util.param('address_second_line') if address_second_line: query = query.filter( model.Resource.address_second_line == address_second_line) current_filter = 'address_second_line=' + address_second_line city = util.param('city') if city: query = query.filter(model.Resource.city == city) current_filter = 'city=' + city country = util.param('country') if country: query = query.filter(model.Resource.country == country) current_filter = 'country=' + country city_filter_dbs, _ = model.Filter.get_dbs( filter_property='city', order='-photos_count', ) tag_filter_dbs, _ = model.Filter.get_dbs( filter_property='tags', order='-photos_count', ) resource_dbs, cursors = model.Resource.get_dbs(query, limit=20, prev_cursor=True, order='-hotness') return flask.render_template( 'resource/resource_grid.html', html_class='resource-grid', title=u'ابحث عن صور', resource_dbs=resource_dbs, city_filter_dbs=city_filter_dbs, tag_filter_dbs=tag_filter_dbs, current_filter=current_filter, next_url=util.generate_next_url(cursors.get('next')), prev_url=util.generate_next_url(cursors.get('prev')), api_url=flask.url_for('api.resource.list'), )
def show_detail(id): # remove the media from session and set a new one. # this is used for the back url session.pop('media', None) media = request.args.get('media') if media is None: media = 'tv' session['media'] = media form = NewComment(mediaType=media) shows = showFunctions.getDetails(id, media) #shows = getSingleShowInfo(id, media) back_url = request.args.get('back') showId = str(id) if (auth.current_user_id > 0): fav = showFunctions.isFavorited(id) #fake_data(showid) comments_db, comments_cursor = model.UserComments.get_dbs(showId=showId, limit=10, prev_cursor=True) if form.validate_on_submit(): media = form.mediaType.data comment = model.UserComments(user_key=auth.current_user_key(), showId=showId, body=form.body.data, creator=auth.current_user_db().name) if comment.put(): flask.flash("Comment Created", category='success') return flask.redirect( flask.url_for('show_detail', id=id, media=media, order='-created')) return flask.render_template( 'details.html', html_class='show_detail', shows=shows, back_url=back_url, fav=fav, media=media, form=form, comments_db=comments_db, next_url=util.generate_next_url(comments_cursor['next']), prev_url=util.generate_next_url(comments_cursor['prev']), )
def admin_filter_list(): filter_dbs, cursors = model.Filter.get_dbs( limit=30, prev_cursor=True, order='-photos_count') return flask.render_template( 'filter/filter_list.html', html_class='filter-list', title=u'قائمة الفلاتر', filter_dbs=filter_dbs, next_url=util.generate_next_url(cursors.get('next')), prev_url=util.generate_next_url(cursors.get('prev')), api_url=flask.url_for('api.filter.list'), )
def admin_resource_list(): resource_dbs, cursors = model.Resource.get_dbs(hotness=-1, limit=10, prev_cursor=True, order='-created') return flask.render_template( 'resource/resource_list.html', html_class='resource-list', title=u'قائمة الصور', resource_dbs=resource_dbs, next_url=util.generate_next_url(cursors.get('next')), prev_url=util.generate_next_url(cursors.get('prev')), api_url=flask.url_for('api.resource.list'), )
def user_list(): user_dbs, cursors = model.User.get_dbs( email=util.param('email'), prev_cursor=True, ) permissions = list(UserUpdateForm._permission_choices) permissions += util.param('permissions', list) or [] return flask.render_template( 'user/user_list.html', html_class='user-list', title=_('User List'), user_dbs=user_dbs, next_url=util.generate_next_url(cursors['next']), prev_url=util.generate_next_url(cursors['prev']), api_url=flask.url_for('api.admin.user.list'), permissions=sorted(set(permissions)), )
def lot_list(): lot_dbs, lot_cursor = model.lot.get_dbs() lotNames = [] campusNames = [] for lot in lot_dbs: parent = lot.key.parent().get(use_cache=False, use_memcache=False) if parent is not None: campusNames.append(parent.key.id()) else: campusNames.append("Failed to get campus") lotNames.append(lot.key.id()) totalLots = len(lotNames) return flask.render_template( 'lot_list.html', html_class='lot-list', title='Lot List', lot_dbs=lot_dbs, next_url=util.generate_next_url(lot_cursor), campusNames=campusNames, lotNames=lotNames, totalLots=totalLots, )
def member_list(): member_dbs, member_cursor = model.Member.get_dbs(order='joined_date') return flask.render_template( 'member/member_list.html', html_class='member-list', title='Bio', member_dbs=member_dbs, next_url=util.generate_next_url(member_cursor), )
def guide_list(): guide_dbs, post_cursor = model.Guide.get_dbs(query=model.Guide.query(), ) return flask.render_template( 'guide/guide_list.html', html_class='guide-list', title='Guide List', guide_dbs=guide_dbs, next_url=util.generate_next_url(post_cursor), )
def song_list(): song_dbs, song_cursor = model.Song.get_dbs(order='rank') return flask.render_template( 'song/song_list.html', html_class='song-list', title='Songs & Lyrics', song_dbs=song_dbs, next_url=util.generate_next_url(song_cursor), )
def project_list(): project_dbs, project_cursor = model.Project.get_dbs(user_key=auth.current_user_key()) return flask.render_template( 'project/project_list.html', html_class='project-list', title='Projects', project_dbs=project_dbs, next_url=util.generate_next_url(project_cursor), api_url=flask.url_for('api.project.list'), )
def comment_list(): comment_dbs, comment_cursor = model.Comment.get_dbs() return flask.render_template( 'comment/comment_list.html', html_class='comment-list', title='Comment List', comment_dbs=comment_dbs, next_url=util.generate_next_url(comment_cursor), api_url=flask.url_for('api.comment.list'), )
def admin_pay_list(): pay_dbs, pay_cursor = model.Pay.get_dbs() return flask.render_template( 'admin/pay_list.html', html_class='admin-pay-list', title='Pay List', pay_dbs=pay_dbs, next_url=util.generate_next_url(pay_cursor), )
def person_list(): person_dbs, person_cursor = model.Person.get_dbs(user_key=auth.current_user_key()) return flask.render_template( 'person/person_list.html', html_class='person-list', title=u'People I’ve met', person_dbs=person_dbs, next_url=util.generate_next_url(person_cursor), api_url=flask.url_for('api.person.list'), )
def pay_list(): pay_dbs, pay_cursor = auth.current_user_db().get_pay_dbs() return flask.render_template( 'pay/pay_list.html', html_class='pay-list', title='Pay List', pay_dbs=pay_dbs, next_url=util.generate_next_url(pay_cursor), )
def contact_list(): contact_dbs, contact_cursor = model.Contact.get_dbs( user_key=auth.current_user_key(), ) return flask.render_template( 'contact_list.html', html_class='contact-list', title='Contact List', contact_dbs=contact_dbs, next_url=util.generate_next_url(contact_cursor), )
def admin_price_list(): price_dbs, price_cursor = model.Price.get_dbs(order=util.param('order') or '-modified', ) return flask.render_template( 'price/admin_price_list.html', html_class='admin-price-list', title='Price List', price_dbs=price_dbs, next_url=util.generate_next_url(price_cursor), api_url=flask.url_for('api.admin.price.list'), )
def admin_vote_list(): vote_dbs, vote_cursor = model.Vote.get_dbs(order=util.param('order') or '-modified', ) return flask.render_template( 'vote/admin_vote_list.html', html_class='admin-vote-list', title='Vote List', vote_dbs=vote_dbs, next_url=util.generate_next_url(vote_cursor), api_url=flask.url_for('api.admin.vote.list'), )
def admin_song_list(): song_dbs, song_cursor = model.Song.get_dbs(order=util.param('order') or '-modified', ) return flask.render_template( 'song/admin_song_list.html', html_class='admin-song-list', title='Song List', song_dbs=song_dbs, next_url=util.generate_next_url(song_cursor), api_url=flask.url_for('api.admin.song.list'), )
def user_list(): args = parser.parse({ 'email': wf.Str(missing=None), 'permissions': wf.DelimitedList(wf.Str(), delimiter=',', missing=[]), }) user_dbs, cursors = model.User.get_dbs( email=args['email'], prev_cursor=True, ) permissions = list(UserUpdateForm._permission_choices) permissions += args['permissions'] return flask.render_template( 'user/user_list.html', html_class='user-list', title='User List', user_dbs=user_dbs, next_url=util.generate_next_url(cursors['next']), prev_url=util.generate_next_url(cursors['prev']), api_url=flask.url_for('api.admin.user.list'), permissions=sorted(set(permissions)), )
def recommender_list(): recommender_dbs, post_cursor = model.Recommender.get_dbs( query=model.Recommender.query(), ) return flask.render_template( 'recommender/recommender_list.html', html_class='recommender-list', title='Recommender List', recommender_dbs=recommender_dbs, next_url=util.generate_next_url(post_cursor), )
def welcome(): post_dbs, post_cursor = model.Post.get_dbs() top_post_dbs, _ = model.Post.get_dbs(order='-votes', limit=4) return flask.render_template( 'welcome.html', html_class='welcome', post_dbs=post_dbs, top_post_dbs=top_post_dbs, next_url=util.generate_next_url(post_cursor), api_url=flask.url_for('api.post.list'), )
def admin_account_list(): account_dbs, account_cursor = model.Account.get_dbs( order=util.param('order') or '-modified', ) return flask.render_template( 'account/admin_account_list.html', html_class='admin-account-list', title='Account List', account_dbs=account_dbs, next_url=util.generate_next_url(account_cursor), api_url=flask.url_for('api.admin.account.list'), )
def resource_list(): resource_dbs, resource_cursor = model.Resource.get_dbs() return flask.render_template( 'resource/resource_list.html', html_class='resource-list', title='Resource List', resource_dbs=resource_dbs, next_url=util.generate_next_url(resource_cursor), api_url=flask.url_for('api.resource.list'), )
def admin_member_list(): member_dbs, member_cursor = model.Member.get_dbs(order=util.param('order') or '-modified', ) return flask.render_template( 'member/admin_member_list.html', html_class='admin-member-list', title='Member List', member_dbs=member_dbs, next_url=util.generate_next_url(member_cursor), api_url=flask.url_for('api.admin.member.list'), )
def admin_currency_list(): currency_dbs, currency_cursor = model.Currency.get_dbs( order=util.param('order') or '-modified', ) return flask.render_template( 'currency/admin_currency_list.html', html_class='admin-currency-list', title='Currency List', currency_dbs=currency_dbs, next_url=util.generate_next_url(currency_cursor), api_url=flask.url_for('api.admin.currency.list'), )
def admin_repo_list(): repo_dbs, repo_cursor = model.Repo.get_dbs(order=util.param('order') or '-modified', ) return flask.render_template( 'repo/admin_repo_list.html', html_class='admin-repo-list', title='Repo List', repo_dbs=repo_dbs, next_url=util.generate_next_url(repo_cursor), api_url=flask.url_for('api.admin.repo.list'), )
def post_list(): post_dbs, post_cursor = model.Post.get_dbs( query=model.Post.query(), ) return flask.render_template( 'post_list.html', html_class='post-list', title='Post List', post_dbs=post_dbs, next_url=util.generate_next_url(post_cursor), )
def resource_list(): resource_dbs, resource_cursor = auth.current_user_db().get_resource_dbs() return flask.render_template( 'resource/resource_list.html', html_class='resource-list', title='Resource List', resource_dbs=resource_dbs, next_url=util.generate_next_url(resource_cursor), api_url=flask.url_for('api.resource.list'), )
def admin_transaction_list(): transaction_dbs, transaction_cursor = model.Transaction.get_dbs( order=util.param('order') or '-modified', ) return flask.render_template( 'transaction/admin_transaction_list.html', html_class='admin-transaction-list', title='Transaction List', transaction_dbs=transaction_dbs, next_url=util.generate_next_url(transaction_cursor), api_url=flask.url_for('api.admin.transaction.list'), )
def admin_drawing_list(): drawing_dbs, drawing_cursor = model.Drawing.get_dbs( order=util.param('order') or '-modified', ) return flask.render_template( 'drawing/admin_drawing_list.html', html_class='admin-drawing-list', title='Drawing List', drawing_dbs=drawing_dbs, next_url=util.generate_next_url(drawing_cursor), api_url=flask.url_for('api.admin.drawing.list'), )
def admin_album_list(): album_dbs, album_cursor = model.Album.get_dbs(order=util.param('order') or '-modified', ) return flask.render_template( 'album/admin_album_list.html', html_class='admin-album-list', title='Album List', album_dbs=album_dbs, next_url=util.generate_next_url(album_cursor), api_url=flask.url_for('api.admin.album.list'), )
def transaction_list(): transaction_dbs, transaction_cursor = model.Transaction.get_dbs( user_key=auth.current_user_key()) return flask.render_template( 'transaction/transaction_list.html', html_class='transaction-list', title='Transaction List', transaction_dbs=transaction_dbs, next_url=util.generate_next_url(transaction_cursor), api_url=flask.url_for('api.transaction.list'), )
def admin_song_list(): song_dbs, song_cursor = model.Song.get_dbs( order=util.param('order') or '-modified', ) return flask.render_template( 'song/admin_song_list.html', html_class='admin-song-list', title='Song List', song_dbs=song_dbs, next_url=util.generate_next_url(song_cursor), api_url=flask.url_for('api.admin.song.list'), )
def admin_project_list(): project_dbs, project_cursor = model.Project.get_dbs( order=util.param('order') or '-modified', ) return flask.render_template( 'project/admin_project_list.html', html_class='admin-project-list', title='Projects', project_dbs=project_dbs, next_url=util.generate_next_url(project_cursor), api_url=flask.url_for('api.admin.project.list'), )
def admin_member_list(): member_dbs, member_cursor = model.Member.get_dbs( order=util.param('order') or '-modified', ) return flask.render_template( 'member/admin_member_list.html', html_class='admin-member-list', title='Member List', member_dbs=member_dbs, next_url=util.generate_next_url(member_cursor), api_url=flask.url_for('api.admin.member.list'), )
def artist_list(): artist_dbs, artist_cursor = model.Artist.get_dbs( # user_key=auth.current_user_key(), ) return flask.render_template( 'artist/artist_list.html', html_class='artist-list', title='Artist List', artist_dbs=artist_dbs, next_url=util.generate_next_url(artist_cursor), )
def admin_repo_list(): repo_dbs, repo_cursor = model.Repo.get_dbs( order=util.param('order') or '-modified', ) return flask.render_template( 'repo/admin_repo_list.html', html_class='admin-repo-list', title='Repo List', repo_dbs=repo_dbs, next_url=util.generate_next_url(repo_cursor), api_url=flask.url_for('api.admin.repo.list'), )
def admin_person_list(): person_dbs, person_cursor = model.Person.get_dbs( order=util.param('order') or '-modified', ) return flask.render_template( 'person/admin_person_list.html', html_class='admin-person-list', title='Person List', person_dbs=person_dbs, next_url=util.generate_next_url(person_cursor), api_url=flask.url_for('api.admin.person.list'), )
def admin_crash_list(): crash_dbs, crash_cursor = model.Crash.get_dbs( order=util.param('order') or '-created', ) return flask.render_template( 'crash/admin_crash_list.html', html_class='admin-crash-list', title='Crash List', crash_dbs=crash_dbs, next_url=util.generate_next_url(crash_cursor), api_url=flask.url_for('api.admin.crash.list'), )
def admin_album_list(): album_dbs, album_cursor = model.Album.get_dbs( order=util.param('order') or '-modified', ) return flask.render_template( 'album/admin_album_list.html', html_class='admin-album-list', title='Album List', album_dbs=album_dbs, next_url=util.generate_next_url(album_cursor), api_url=flask.url_for('api.admin.album.list'), )
def tournament_list(): tournament_dbs, next_cursor = model.Tournament.get_dbs(is_public=True) if flask.request.path.startswith('/_s/'): return util.jsonify_model_dbs(tournament_dbs, next_cursor) return flask.render_template( 'tournament/tournament_list.html', html_class='tournament-list', title='Tournaments', tournament_dbs=tournament_dbs, next_url=util.generate_next_url(next_cursor), )
def user_list(): user_dbs, user_cursor = model.User.get_dbs(email=util.param('email')) permissions = list(UserUpdateForm._permission_choices) permissions += util.param('permissions', list) or [] return flask.render_template( 'user/user_list.html', html_class='user-list', title='User List', user_dbs=user_dbs, next_url=util.generate_next_url(user_cursor), api_url=flask.url_for('api.users'), permissions=sorted(set(permissions)), )
def my_tournament_list(): tournament_dbs, next_cursor = model.Tournament.get_dbs(user_key=auth.current_user_key()) if flask.request.path.startswith('/_s/'): return util.jsonify_model_dbs(tournament_dbs, next_cursor) return flask.render_template( 'tournament/my_tournament_list.html', html_class='my-tournament-list', title='My Tournaments', tournament_dbs=tournament_dbs, next_url=util.generate_next_url(next_cursor), )
def resource_list(): resource_dbs, resource_cursor = auth.current_user_db().get_resource_dbs() if flask.request.path.startswith('/_s/'): return util.jsonify_model_dbs(resource_dbs, resource_cursor) return flask.render_template( 'resource/resource_list.html', html_class='resource-list', title='Resource List', resource_dbs=resource_dbs, next_url=util.generate_next_url(resource_cursor), has_json=True, )
def make_response(data, marshal_table, next_cursor=None): if util.is_iterable(data): response = { 'status': 'success', 'count': len(data), 'now': datetime.utcnow().isoformat(), 'result': map(lambda l: restful.marshal(l, marshal_table), data), } if next_cursor: response['next_cursor'] = next_cursor response['next_url'] = util.generate_next_url(next_cursor) return util.jsonpify(response) return util.jsonpify({ 'status': 'success', 'now': datetime.utcnow().isoformat(), 'result': restful.marshal(data, marshal_table), })
def user_list(): user_dbs, user_cursor = model.User.get_dbs(email=util.param('email')) if flask.request.path.startswith('/_s/'): return util.jsonify_model_dbs(user_dbs, user_cursor) permissions = list(UserUpdateForm._permission_choices) permissions += util.param('permissions', list) or [] return flask.render_template( 'user/user_list.html', html_class='user-list', title='User List', user_dbs=user_dbs, next_url=util.generate_next_url(user_cursor), has_json=True, permissions=sorted(set(permissions)), )
def project_view(project_id): project_db = model.Project.get_by_id(project_id) if not project_db or project_db.user_key != auth.current_user_key(): flask.abort(404) crash_dbs, crash_cursor = project_db.get_crash_dbs( order=util.param('order') or '-created', ) return flask.render_template( 'project/project_view.html', html_class='project-view', title=project_db.name, project_db=project_db, crash_dbs=crash_dbs, next_url=util.generate_next_url(crash_cursor), api_url=flask.url_for('api.project', project_key=project_db.key.urlsafe() if project_db.key else ''), )
def admin_event_list(): event_dbs, next_cursor = util.get_dbs( model.Event.query(), limit=util.param('limit', int), cursor=util.param('cursor'), order=util.param('order') or 'user_key,-timestamp,accuracy,-created', ) if flask.request.path.startswith('/_s/'): return util.jsonify_model_dbs(event_dbs, next_cursor) return flask.render_template( 'admin/event_list.html', html_class='admin-event-list', title='Event List', event_dbs=event_dbs, next_url=util.generate_next_url(next_cursor), )
def admin_event_list(): event_dbs, next_cursor = util.get_dbs( model.Event.query(), limit=util.param("limit", int), cursor=util.param("cursor"), order=util.param("order") or "user_key,-timestamp,accuracy,-created", ) if flask.request.path.startswith("/_s/"): return util.jsonify_model_dbs(event_dbs, next_cursor) return flask.render_template( "admin/event_list.html", html_class="admin-event-list", title="Event List", event_dbs=event_dbs, next_url=util.generate_next_url(next_cursor), )
def icon_list(): col_key = util.param('collection',str) if col_key: col_db = ndb.Key(urlsafe=col_key).get() else: col_db=None icon_dbs, icon_cursor = model.Icon.get_dbs(collection=col_key) #permissions = list(UserUpdateForm._permission_choices) #permissions += util.param('permissions', list) or [] return flask.render_template( 'icon/icon_list.html', html_class='icon-list', title='Icon List', icon_dbs=icon_dbs, col_db=col_db, next_url=util.generate_next_url(icon_cursor), api_url=None#flask.url_for('api.Tag.list') )
def trips(username=None): user_db = auth.current_user_db() if username and user_db.username != username: if not user_db.admin: return flask.abort(404) user_db = model.User.get_by('username', username) if not user_db: return flask.abort(404) event_dbs, next_cursor = user_db.get_event_dbs(limit=-1, order='timestamp,-accuracy,created') return flask.render_template( 'event/trips.html', html_class='trips', title=_('My Trips'), event_dbs=event_dbs, next_url=util.generate_next_url(next_cursor), user_db=user_db, )