def _all_geography_downloads(app): dls = AppDownloadsByGeoLoc.objects.filter(app=app) response = [[ dl.geoloc.country, dl.geoloc.region, dl.geoloc.city, dl.count ] for dl in dls] response.insert(0, ['Country', 'Region', 'City', 'Downloads']) return json_response(response)
def app_page_edit(request, app_name): app = get_object_or_404(App, active = True, name = app_name) if not app.is_editor(request.user): return HttpResponseForbidden() if request.method == 'POST': action = request.POST.get('action') if not action: return HttpResponseBadRequest('no action specified') if not action in _AppEditActions: return HttpResponseBadRequest('action "%s" invalid--must be: %s' % (action, ', '.join(_AppEditActions))) try: result = _AppEditActions[action](app, request) except ValueError as e: return HttpResponseBadRequest(str(e)) app.save() if request.is_ajax(): return json_response(result) all_tags = [tag.fullname for tag in Tag.objects.all()] c = { 'app': app, 'all_tags': all_tags, 'max_file_img_size_b': _AppPageEditConfig.max_img_size_b, 'max_icon_dim_px': _AppPageEditConfig.max_icon_dim_px, 'thumbnail_height_px': _AppPageEditConfig.thumbnail_height_px, 'app_description_maxlength': _AppPageEditConfig.app_description_maxlength, 'release_uploaded': request.GET.get('upload_release') == 'true', } return html_response('app_page_edit.html', c, request)
def _country_downloads(app, country_code): cities = AppDownloadsByGeoLoc.objects.filter(app=app, geoloc__country=country_code, geoloc__city__gt='') response = [[city.geoloc.city, city.count] for city in cities] response.insert(0, ['City', 'Downloads']) return json_response(response)
def pending_apps(request): if not request.user.is_staff: return HttpResponseForbidden() if request.method == 'POST': action = request.POST.get('action') if not action: return HttpResponseBadRequest('action must be specified') if not action in _PendingAppsActions: return HttpResponseBadRequest( 'invalid action--must be: %s' % ', '.join(_PendingAppsActions.keys())) pending_id = request.POST.get('pending_id') if not pending_id: return HttpResponseBadRequest('pending_id must be specified') try: pending_app = AppPending.objects.get(id=int(pending_id)) except AppPending.DoesNotExist as ValueError: return HttpResponseBadRequest('invalid pending_id') _PendingAppsActions[action](pending_app, request) if request.is_ajax(): return json_response(True) pending_apps = AppPending.objects.all() return html_response('pending_apps.html', {'pending_apps': pending_apps}, request)
def app_stats_timeline(request, app_name): app = get_object_or_404(App, active = True, name = app_name) releases = app.release_set.all() response = dict() for release in releases: dls = ReleaseDownloadsByDate.objects.filter(release = release) response[release.version] = [[dl.when.isoformat(), dl.count] for dl in dls] return json_response(response)
def _world_downloads(app): countries = AppDownloadsByGeoLoc.objects.filter(app=app, geoloc__region='', geoloc__city='') response = [[country.geoloc.country, country.count] for country in countries] response.insert(0, ['Country', 'Downloads']) return json_response(response)
def artifact_exists(request): if request.method != 'POST': return HttpResponseBadRequest('no data') postLookup = request.POST.get groupId, artifactId, version = postLookup('groupId'), postLookup('artifactId'), postLookup('version') if not groupId or not artifactId or not version: return HttpResponseBadRequest('groupId, artifactId, or version not specified') deployUrl = _get_deploy_url(groupId, artifactId, version) return json_response(_url_exists(deployUrl))
def all_apps_func(request): """ Gets all App objects that are active with releases :param request: :return: active App objects with releases in json format """ all_apps = App.objects.filter(active=True) all_apps_fmt = [_app_to_obj(app) for app in all_apps if app.has_releases] return json_response(all_apps_fmt)
def _update_app_page(request_post): fullname = request_post.get('fullname') if not fullname: return HttpResponseBadRequest('"fullname" not specified') name = fullname_to_name(fullname) app = get_object_or_none(App, name=name) if app: app.active = True else: app = App.objects.create(name=name, fullname=fullname) details = request_post.get('details') if details: app.details = details cy2x_plugin_download = request_post.get('cy2x_plugin_download') if cy2x_plugin_download: app.cy_2x_plugin_download = cy2x_plugin_download cy2x_plugin_version = request_post.get('cy2x_plugin_version') if cy2x_plugin_download: app.cy_2x_plugin_version = cy2x_plugin_version cy_versions = request_post.get('cy_versions') if cy2x_plugin_download: app.cy_2x_versions = cy_versions release_date = request_post.get('release_date') if cy2x_plugin_download: app.cy_2x_plugin_release_date = _parse_iso_date(release_date) author_count = request_post.get('author_count') if author_count: author_count = int(author_count) for i in range(author_count): name = request_post.get('author_' + str(i)) if not name: return HttpResponseBadRequest('no such author at index ' + str(i)) institution = request_post.get('institution_' + str(i)) author, _ = Author.objects.get_or_create(name=name, institution=institution) author_order = OrderedAuthor.objects.create(app=app, author=author, author_order=i) app.save() return json_response(True)
def _update_app_page(request_post): fullname = request_post.get('fullname') if not fullname: return HttpResponseBadRequest('"fullname" not specified') name = fullname_to_name(fullname) app = get_object_or_none(App, name = name) if app: app.active = True else: app = App.objects.create(name = name, fullname = fullname) details = request_post.get('details') if details: app.details = details cy2x_plugin_download = request_post.get('cy2x_plugin_download') if cy2x_plugin_download: app.cy_2x_plugin_download = cy2x_plugin_download cy2x_plugin_version = request_post.get('cy2x_plugin_version') if cy2x_plugin_download: app.cy_2x_plugin_version = cy2x_plugin_version cy_versions = request_post.get('cy_versions') if cy2x_plugin_download: app.cy_2x_versions = cy_versions release_date = request_post.get('release_date') if cy2x_plugin_download: app.cy_2x_plugin_release_date = _parse_iso_date(release_date) author_count = request_post.get('author_count') if author_count: author_count = int(author_count) for i in range(author_count): name = request_post.get('author_' + str(i)) if not name: return HttpResponseBadRequest('no such author at index ' + str(i)) institution = request_post.get('institution_' + str(i)) author, _ = Author.objects.get_or_create(name = name, institution = institution) author_order = OrderedAuthor.objects.create(app = app, author = author, author_order = i) app.save() return json_response(True)
def app_page(request, app_name): app = get_object_or_404(App, active=True, name=app_name) user = request.user if request.user.is_authenticated else None if request.method == 'POST': action = request.POST.get('action') if not action: return HttpResponseBadRequest('no action specified') if not action in _AppActions: return HttpResponseBadRequest('action "%s" invalid--must be: %s' % (action, ', '.join(_AppActions))) try: result = _AppActions[action](app, user, request.POST) except ValueError as e: return HttpResponseBadRequest(str(e)) if isinstance(result, HttpResponse): return result if request.is_ajax(): return json_response(result) return _mk_app_page(app, user, request)
def app_page(request, app_name): app = get_object_or_404(App, active = True, name = app_name) user = request.user if request.user.is_authenticated() else None if request.method == 'POST': action = request.POST.get('action') if not action: return HttpResponseBadRequest('no action specified') if not action in _AppActions: return HttpResponseBadRequest('action "%s" invalid--must be: %s' % (action, ', '.join(_AppActions))) try: result = _AppActions[action](app, user, request.POST) except ValueError as e: return HttpResponseBadRequest(str(e)) if isinstance(result, HttpResponse): return result if request.is_ajax(): return json_response(result) return _mk_app_page(app, user, request)
def pending_apps(request): if not request.user.is_staff: return HttpResponseForbidden() if request.method == 'POST': action = request.POST.get('action') if not action: return HttpResponseBadRequest('action must be specified') if not action in _PendingAppsActions: return HttpResponseBadRequest('invalid action--must be: %s' % ', '.join(_PendingAppsActions.keys())) pending_id = request.POST.get('pending_id') if not pending_id: return HttpResponseBadRequest('pending_id must be specified') try: pending_app = AppPending.objects.get(id = int(pending_id)) except AppPending.DoesNotExist, ValueError: return HttpResponseBadRequest('invalid pending_id') _PendingAppsActions[action](pending_app, request) if request.is_ajax(): return json_response(True)
def all_stats_timeline(request): dls = ReleaseDownloadsByDate.objects.filter(release = None) response = {'Total': [[dl.when.isoformat(), dl.count] for dl in dls]} return json_response(response)
def _country_downloads(app, country_code): cities = AppDownloadsByGeoLoc.objects.filter(app = app, geoloc__country = country_code, geoloc__city__gt = '') response = [[city.geoloc.city, city.count] for city in cities] response.insert(0, ['City', 'Downloads']) return json_response(response)
def _world_downloads(app): countries = AppDownloadsByGeoLoc.objects.filter(app = app, geoloc__region = '', geoloc__city = '') response = [[country.geoloc.country, country.count] for country in countries] response.insert(0, ['Country', 'Downloads']) return json_response(response)
def _all_geography_downloads(app): dls = AppDownloadsByGeoLoc.objects.filter(app = app) response = [[dl.geoloc.country, dl.geoloc.region, dl.geoloc.city, dl.count] for dl in dls] response.insert(0, ['Country', 'Region', 'City', 'Downloads']) return json_response(response)
def _app_info(request_post): fullname = request_post.get('app_fullname') name = fullname_to_name(fullname) url = reverse('app_page', args=(name,)) exists = App.objects.filter(name = name, active = True).count() > 0 return json_response({'url': url, 'exists': exists})
def all(request): all_apps = App.objects.filter(active = True) all_apps_fmt = [_app_to_obj(app) for app in all_apps if app.has_releases] return json_response(all_apps_fmt)
def institution_names(app, request): names = [a.institution for a in Author.objects.exclude(institution__isnull=True)] return json_response(names)
def author_names(app, request): names = [a.name for a in Author.objects.exclude(name__isnull=True)] return json_response(names)
def _app_info(request_post): fullname = request_post.get('app_fullname') name = fullname_to_name(fullname) url = reverse('app_page', args=(name, )) exists = App.objects.filter(name=name, active=True).count() > 0 return json_response({'url': url, 'exists': exists})
def all(request): all_apps = App.objects.filter(active=True) all_apps_fmt = [_app_to_obj(app) for app in all_apps if app.has_releases] return json_response(all_apps_fmt)