Example #1
0
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)
Example #2
0
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)
Example #3
0
def _pending_app_accept(pending, request):
    name = fullname_to_name(pending.fullname)
    # we always create a new app, because only new apps require accepting
    app = App.objects.create(fullname = pending.fullname, name = name)
    app.active = True
    app.editors.add(pending.submitter)
    app.save()

    pending.make_release(app)
    pending.delete_files()
    pending.delete()

    server_url = _get_server_url(request)
    _send_email_for_accepted_app(pending.submitter.email, settings.CONTACT_EMAIL, app.fullname, app.name, server_url)
Example #4
0
def _pending_app_accept(pending, request):
    name = fullname_to_name(pending.fullname)
    # we always create a new app, because only new apps require accepting
    app = App.objects.create(fullname = pending.fullname, name = name)
    app.active = True
    app.editors.add(pending.submitter)
    app.save()

    pending.make_release(app)
    pending.delete_files()
    pending.delete()

    server_url = _get_server_url(request)
    _send_email_for_accepted_app(pending.submitter.email, settings.CONTACT_EMAIL, app.fullname, app.name, server_url)
Example #5
0
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)
Example #6
0
def _create_pending(submitter, fullname, version, cy_works_with,
                    app_dependencies, release_file):
    """
    Creates an AppPending object with information passed in and
    saves it to the database

    :param submitter: User that made request.
    :param fullname: Full name of app
    :type fullname: str
    :param version:
    :type version: str
    :param cy_works_with:
    :type cy_works_with: str
    :param app_dependencies: Release objects
    :type app_dependencies: list
    :param release_file: release jar file
    :type :py:class:`django.core.files.base.File`
    :return: Pending App object
    :rtype :py:class:`submit_app.models.AppPending`
    :raises ValueError: If App already exists and 'submitter' is not allowed
                        to edit. Will also be raised if Release matching name
                        exists that is active.
    """
    name = fullname_to_name(fullname)
    app = get_object_or_none(App, name=name)
    if app:
        if not app.is_editor(submitter):
            raise ValueError('cannot be accepted because you are not '
                             'an editor')
        release = get_object_or_none(Release, app=app, version=version)
        if release and release.active:
            raise ValueError('cannot be accepted because the app %s already'
                             ' has a release with version %s. You can delete '
                             'this version by going to the Release History '
                             'tab in the app edit page' % (app.fullname,
                                                           version))

    pending = AppPending.objects.create(submitter=submitter,
                                        fullname=fullname,
                                        version=version,
                                        cy_works_with=cy_works_with)
    for dependency in app_dependencies:
        pending.dependencies.add(dependency)
    pending.release_file.save(basename(release_file.name), release_file)
    pending.save()
    return pending
Example #7
0
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)
Example #8
0
def _create_pending(submitter, fullname, version, cy_works_with, app_dependencies, release_file):
    name = fullname_to_name(fullname)
    app = get_object_or_none(App, name = name)
    if app:
        if not app.is_editor(submitter):
            raise ValueError('cannot be accepted because you are not an editor')
        release = get_object_or_none(Release, app = app, version = version)
        if release and release.active:
            raise ValueError('cannot be accepted because the app %s already has a release with version %s. You can delete this version by going to the Release History tab in the app edit page' % (app.fullname, version))

    pending = AppPending.objects.create(submitter      = submitter,
                                        fullname       = fullname,
                                        version        = version,
                                        cy_works_with  = cy_works_with)
    for dependency in app_dependencies:
        pending.dependencies.add(dependency)
    pending.release_file.save(basename(release_file.name), release_file)
    pending.save()
    return pending
Example #9
0
def _create_pending(submitter, fullname, version, cy_works_with, app_dependencies, release_file):
    name = fullname_to_name(fullname)
    app = get_object_or_none(App, name = name)
    if app:
        if not app.is_editor(submitter):
            raise ValueError('cannot be accepted because you are not an editor')
        release = get_object_or_none(Release, app = app, version = version)
        if release and release.active:
            raise ValueError('cannot be accepted because the app %s already has a release with version %s. You can delete this version by going to the Release History tab in the app edit page' % (app.fullname, version))

    pending = AppPending.objects.create(submitter      = submitter,
                                        fullname       = fullname,
                                        version        = version,
                                        cy_works_with  = cy_works_with)
    for dependency in app_dependencies:
        pending.dependencies.add(dependency)
    pending.release_file.save(basename(release_file.name), release_file)
    pending.save()
    return pending
Example #10
0
def _save_tags(app, request):
    tag_count = request.POST.get('tag_count')
    if not tag_count:
        raise ValueError('no tag_count specified')
    try:
        tag_count = int(tag_count)
    except ValueError:
        raise ValueError('tag_count is not an integer')

    tags = []
    for i in range(tag_count):
        tag_key = 'tag_' + str(i)
        tag = request.POST.get(tag_key)
        if not tag:
            raise ValueError('expected ' + tag_key)
        tags.append(tag)

    app.tags.clear()
    for tag in tags:
        tag_obj, _ = Tag.objects.get_or_create(fullname = tag, name = fullname_to_name(tag))
        app.tags.add(tag_obj)

    _flush_tag_caches()
Example #11
0
def _save_tags(app, request):
	tag_count = request.POST.get('tag_count')
	if not tag_count:
		raise ValueError('no tag_count specified')
	try:
		tag_count = int(tag_count)
	except ValueError:
		raise ValueError('tag_count is not an integer')
	
	tags = []
	for i in range(tag_count):
		tag_key = 'tag_' + str(i)
		tag = request.POST.get(tag_key)
		if not tag:
			raise ValueError('expected ' + tag_key)
		tags.append(tag)
	
	app.tags.clear()
	for tag in tags:
		tag_obj, _ = Tag.objects.get_or_create(fullname = tag, name = fullname_to_name(tag))
		app.tags.add(tag_obj)
	
	_flush_tag_caches()
Example #12
0
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})
Example #13
0
 def is_new_app(self):
    name = fullname_to_name(self.fullname)
    return get_object_or_none(App, name = name) == None
Example #14
0
 def is_new_app(self):
     name = fullname_to_name(self.fullname)
     return get_object_or_none(App, name=name) == None
Example #15
0
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})