def confirm_submission(request, id): """ Loads AppPending object corresponding to 'id' passed in and verifies user is allowed to view this page and if the pom.xml file is found it is examined and key attributes are returned :param request: :param id: id of AppPending entry in database :return: html response """ pending = get_object_or_404(AppPending, id=int(id)) if not pending.can_confirm(request.user): return HttpResponseForbidden('You are not authorized to view this page') action = request.POST.get('action') if action: if action == 'cancel': return _user_cancelled(request, pending) elif action == 'accept': return _user_accepted(request, pending) pom_attrs = None if pending.pom_xml_file: pending.pom_xml_file.open(mode='r') pom_attrs = parse_pom(pending.pom_xml_file) pending.pom_xml_file.close() return html_response('confirm.html', {'pending': pending, 'pom_attrs': pom_attrs}, request)
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 submit_api(request, id): pending = get_object_or_404(AppPending, id = int(id)) if not pending.can_confirm(request.user): return HttpResponseForbidden('You are not authorized to view this page') error_msg = None if request.POST.get('dont_submit') != None: return HttpResponseRedirect(reverse('confirm-submission', args=[pending.id])) elif request.POST.get('submit') != None: pom_xml_f = request.FILES.get('pom_xml') javadocs_jar_f = request.FILES.get('javadocs_jar') if pom_xml_f and javadocs_jar_f: if not error_msg: pom_xml_f.open(mode = 'r') pom_attrs = parse_pom(pom_xml_f) if len(pom_attrs) != len(PomAttrNames): error_msg = 'pom.xml is not valid; it must have these tags under <project>: ' + ', '.join(PomAttrNames) pom_xml_f.close() if not error_msg: error_msg = _verify_javadocs_jar(javadocs_jar_f) if not error_msg: pending.pom_xml_file.save(basename(pom_xml_f.name), pom_xml_f) pending.javadocs_jar_file.save(basename(javadocs_jar_f.name), javadocs_jar_f) return HttpResponseRedirect(reverse('confirm-submission', args=[pending.id])) return html_response('submit_api.html', {'pending': pending, 'error_msg': error_msg}, request)
def submit_app(request): context = dict() if request.method == 'POST': expect_app_name = request.POST.get('expect_app_name') f = request.FILES.get('file') if f: try: fullname, version, works_with, app_dependencies, has_export_pkg = process_jar( f, expect_app_name) pending = _create_pending(request.user, fullname, version, works_with, app_dependencies, f) _send_email_for_pending(pending) version_pattern1 = "^[0-9].[0-9].[0-9]+" version_pattern1 = re.compile(version_pattern1) version_pattern2 = "^[0-9].[0-9]+" version_pattern2 = re.compile(version_pattern2) if (bool(version_pattern1.match(version)) != True and bool(version_pattern2.match(version)) != True): raise ValueError( "The version is not in proper pattern. It should have 2 order version numbering (e.g: x.y) or 3 order version numbering (e.g: x.y.z)" ) if has_export_pkg: return HttpResponseRedirect( reverse('submit-api', args=[pending.id])) else: return HttpResponseRedirect( reverse('confirm-submission', args=[pending.id])) except ValueError as e: context['error_msg'] = str(e) else: expect_app_name = request.GET.get('expect_app_name') if expect_app_name: context['expect_app_name'] = expect_app_name return html_response('upload_form.html', context, 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 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 login(request): next_url = request.GET.get('next', reverse('default-page')) if request.user.is_authenticated: return HttpResponseRedirect(next_url) return html_response('login.html', { 'navbar_selected': 'signin', 'next_url': next_url }, request)
def all_apps(request): apps = App.objects.filter(active=True).order_by('name') c = { 'apps': apps, 'navbar_selected_link': 'all', 'go_back_to': 'All Apps', } return html_response('all_apps.html', c, request, processors = (_nav_panel_context, ))
def contact(request): c = { 'footer_selected': 'contact' } if request.method == 'POST': user_email = request.POST.get('user_email') message = request.POST.get('message') no_robot = request.POST.get('no_robot') if not user_email: c['error_from'] = True elif not message: c['error_message'] = True elif not no_robot == u'6': c['error_no_robot'] = True else: send_mail('Cytoscape App Store - User Submitted Contact', 'From: %s\n\n%s' % (user_email, message), user_email, settings.CONTACT_EMAILS, fail_silently=False) return html_response('contact_thanks.html', c, request) c['user_email'] = user_email c['message'] = message return html_response('contact.html', c, request)
def _mk_app_page(app, user, request): c = { 'app': app, 'is_editor': (user and app.is_editor(user)), 'cy3_latest_release': _latest_release(app), 'go_back_to_title': _unescape_and_unquote(request.COOKIES.get('go_back_to_title')), 'go_back_to_url': _unescape_and_unquote(request.COOKIES.get('go_back_to_url')), } return html_response('app_page.html', c, request)
def login_done(request, backend, *args, **kwargs): if request.user.is_authenticated(): return associate_complete(request, backend, *args, **kwargs) else: try: return complete_process(request, backend, *args, **kwargs) except Exception, e: logger.exception(e) return html_response('login.html', {'at_login': True, 'error': str(e)}, request)
def apps_with_tag(request, tag_name): tag = get_object_or_404(Tag, name = tag_name) apps = App.objects.filter(active = True, tags = tag).order_by('name') c = { 'tag': tag, 'apps': apps, 'selected_tag_name': tag_name, 'go_back_to': '“%s” category' % tag.fullname, } return html_response('apps_with_tag.html', c, request, processors = (_nav_panel_context, ))
def apps_default(request): latest_apps = App.objects.filter(active=True).order_by('-latest_release_date')[:_DefaultConfig.num_of_top_apps] downloaded_apps = App.objects.filter(active=True).order_by('downloads').reverse()[:_DefaultConfig.num_of_top_apps] c = { 'latest_apps': latest_apps, 'downloaded_apps': downloaded_apps, 'go_back_to': 'home', } return html_response('apps_default.html', c, request, processors = (_nav_panel_context, ))
def app_stats(request, app_name): app = get_object_or_404(App, active = True, name = app_name) app_downloads_by_country = AppDownloadsByGeoLoc.objects.filter(app = app, geoloc__region = '', geoloc__city = '') releases = app.release_set.all() release_downloads_by_date = [dl for release in releases for dl in ReleaseDownloadsByDate.objects.filter(release = release)] c = { 'app': app, 'app_downloads_by_country': app_downloads_by_country, 'release_downloads_by_date': release_downloads_by_date, } return html_response('app_stats.html', c, request)
def search(request): query = request.GET.get('q', None) if not query: return HttpResponseBadRequest('"q" parameter not specified') c = { 'results': _xapian_search(query), 'search_query': query, 'go_back_to': '“%s” search results' % query, } return html_response('search.html', c, request, processors = (_nav_panel_context, ))
def cy2x_plugins(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 _Cy2xPluginsActions: return HttpResponseBadRequest('invalid action--must be: %s' % ', '.join(_Cy2xPluginsActions.keys())) return _Cy2xPluginsActions[action](request.POST) else: return html_response('cy2x_plugins.html', {}, request)
def wall_of_apps(request): nav_panel_context = _nav_panel_context(request) tags = [(tag.fullname, tag.app_set.all()) for tag in nav_panel_context['top_tags']] apps_in_not_top_tags = set() for not_top_tag in nav_panel_context['not_top_tags']: apps_in_not_top_tags.update(not_top_tag.app_set.all()) tags.append(('other', apps_in_not_top_tags)) c = { 'total_apps_count': App.objects.filter(active=True).count, 'tags': tags, 'go_back_to': 'Wall of Apps', } return html_response('wall_of_apps.html', c, request)
def apps_with_author(request, author_name): apps = App.objects.filter(active = True, authors__name__exact = author_name).order_by('name') if not apps: raise Http404('No such author "%s".' % author_name) c = { 'author_name': author_name, 'apps': apps, 'go_back_to': '%s\'s author page' % author_name, 'go_back_to_title': _unescape_and_unquote(request.COOKIES.get('go_back_to_title')), 'go_back_to_url': _unescape_and_unquote(request.COOKIES.get('go_back_to_url')), } return html_response('apps_with_author.html', c, request, processors = (_nav_panel_context, ))
def contact(request): c = {'footer_selected': 'contact'} if request.method == 'POST': user_email = request.POST.get('user_email') message = request.POST.get('message') no_robot = request.POST.get('no_robot') if not user_email: c['error_from'] = True elif not message: c['error_message'] = True elif not no_robot == u'6': c['error_no_robot'] = True else: send_mail('Cytoscape App Store - User Submitted Contact', 'From: %s\n\n%s' % (user_email, message), user_email, settings.CONTACT_EMAILS, fail_silently=False) return html_response('contact_thanks.html', c, request) c['user_email'] = user_email c['message'] = message return html_response('contact.html', c, request)
def _user_accepted(request, pending): app = get_object_or_none(App, name = fullname_to_name(pending.fullname)) if app: if not app.is_editor(request.user): return HttpResponseForbidden('You are not authorized to add releases, because you are not an editor') if not app.active: app.active = True app.save() pending.make_release(app) pending.delete_files() pending.delete() return HttpResponseRedirect(reverse('app_page_edit', args=[app.name]) + '?upload_release=true') else: return html_response('submit_done.html', {'app_name': pending.fullname}, request)
def search(request): query = request.GET.get('q', None) if not query: return HttpResponseBadRequest('"q" parameter not specified') c = { 'results': _xapian_search(query), 'search_query': query, 'go_back_to': '“%s” search results' % query, } return html_response('search.html', c, request, processors=(_nav_panel_context, ))
def confirm_submission(request, id): pending = get_object_or_404(AppPending, id = int(id)) if not pending.can_confirm(request.user): return HttpResponseForbidden('You are not authorized to view this page') action = request.POST.get('action') if action: if action == 'cancel': return _user_cancelled(request, pending) elif action == 'accept': return _user_accepted(request, pending) pom_attrs = None if pending.pom_xml_file: pending.pom_xml_file.open(mode = 'r') pom_attrs = parse_pom(pending.pom_xml_file) pending.pom_xml_file.close() return html_response('confirm.html', {'pending': pending, 'pom_attrs': pom_attrs}, request)
if f: try: fullname, version, works_with, app_dependencies, has_export_pkg = process_jar(f, expect_app_name) pending = _create_pending(request.user, fullname, version, works_with, app_dependencies, f) _send_email_for_pending(pending) if has_export_pkg: return HttpResponseRedirect(reverse('submit-api', args=[pending.id])) else: return HttpResponseRedirect(reverse('confirm-submission', args=[pending.id])) except ValueError, e: context['error_msg'] = str(e) else: expect_app_name = request.GET.get('expect_app_name') if expect_app_name: context['expect_app_name'] = expect_app_name return html_response('upload_form.html', context, request) def _user_cancelled(request, pending): pending.delete_files() pending.delete() return HttpResponseRedirect(reverse('submit-app')) def _user_accepted(request, pending): app = get_object_or_none(App, name = fullname_to_name(pending.fullname)) if app: if not app.is_editor(request.user): return HttpResponseForbidden('You are not authorized to add releases, because you are not an editor') if not app.active: app.active = True app.save() pending.make_release(app)
def getstarted_app_install(request): return html_response('getstarted_app_install.html', {}, request)
def login(request): next_url = request.GET.get('next', reverse('default-page')) if request.user.is_authenticated(): return HttpResponseRedirect(next_url) return html_response('login.html', {'navbar_selected': 'signin', 'next_url': next_url}, request)
def getstarted(request): return html_response('getstarted.html', {}, request)
def competitions(request): c = dict() c['footer_selected'] = 'competitions' return html_response('competitions.html', c, request)
def about(request): c = dict() c['footer_selected'] = 'about' c['google_api_key'] = settings.GOOGLE_API_KEY return html_response('about.html', c, request)
def md(request): return html_response('md.html', {}, request)
pending = _create_pending(request.user, fullname, version, works_with, app_dependencies, f) _send_email_for_pending(pending) if has_export_pkg: return HttpResponseRedirect( reverse('submit-api', args=[pending.id])) else: return HttpResponseRedirect( reverse('confirm-submission', args=[pending.id])) except ValueError, e: context['error_msg'] = str(e) else: expect_app_name = request.GET.get('expect_app_name') if expect_app_name: context['expect_app_name'] = expect_app_name return html_response('upload_form.html', context, request) def _user_cancelled(request, pending): pending.delete_files() pending.delete() return HttpResponseRedirect(reverse('submit-app')) def _user_accepted(request, pending): app = get_object_or_none(App, name=fullname_to_name(pending.fullname)) if app: if not app.is_editor(request.user): return HttpResponseForbidden( 'You are not authorized to add releases, because you are not an editor' )
def all_stats(request): return html_response('all_stats.html', {}, request)
def submit_api(request, id): pending = get_object_or_404(AppPending, id=int(id)) if not pending.can_confirm(request.user): return HttpResponseForbidden('You are not authorized to view this page') error_msg = None if request.POST.get('dont_submit') is not None: return HttpResponseRedirect(reverse('confirm-submission', args=[pending.id])) if request.POST.get('submit') is not None: pom_xml_f = request.FILES.get('pom_xml') javadocs_jar_f = request.FILES.get('javadocs_jar') if pom_xml_f and javadocs_jar_f: try: # verify pom.xml file has appropriate attributes pom_xml_f.open(mode='r') pom_attrs = parse_pom(pom_xml_f) if len(pom_attrs) != len(PomAttrNames): error_msg = str(pom_xml_f.name) +\ ' is not valid; it must have these ' \ 'tags under <project>: ' +\ ', '.join(PomAttrNames) if not error_msg: # no error earlier so check the javadoc jar file javadocs_jar_f.open(mode='r') error_msg = _verify_javadocs_jar(javadocs_jar_f) if not error_msg: # success cause we did not get any errors # save the pom.xml and javadoc jar file and # redirect to confirm submission pom_xml_f.open(mode='r') javadocs_jar_f.open(mode='r') pending.pom_xml_file.save(basename(pom_xml_f.name), pom_xml_f) pending.javadocs_jar_file.save(basename(javadocs_jar_f.name), javadocs_jar_f) return HttpResponseRedirect(reverse('confirm-submission', args=[pending.id])) finally: # attempt to close the pom.xml and javadocjar files try: pom_xml_f.close() except Exception as e: LOGGER.info('Not critical, but caught exception ' 'attempting to close pom.xml file : ' + str(e)) try: javadocs_jar_f.close() except Exception as e: LOGGER.info('Not critical, but caught exception ' 'attempting to close javadoc jar file : ' + str(e)) # If something went wrong, the error is in error_msg # otherwise 'submit' was not in POST so nothing changed return html_response('submit_api.html', {'pending': pending, 'error_msg': error_msg}, request)