コード例 #1
0
def edit(request, username, tag):

    roadmap = models.load_roadmap(username, tag)
    if roadmap is None:
        return HttpResponse(status=404)

    if not roadmap.visible_to(request.user):
        return HttpResponse(status=404)

    can_edit = roadmap.editable_by(request.user)
    
    if request.method == 'POST':
        if not (request.user.is_authenticated() and can_edit):
            # TODO inform the user that they cannot edit
            return HttpResponse(status=401)
        
        form = RoadmapForm(request.POST, instance=roadmap)

        if form.is_valid():
            versions = get_versions_obj(roadmap)
            cur_vn = len(versions) + 1
            smodel = form.save(commit=False)
            smodel.version_num = cur_vn
            with reversion.create_revision():
                smodel.save()
                reversion.set_user(request.user)
                reversion.set_comment(form.cleaned_data['commit_msg'])

            return HttpResponseRedirect('/roadmaps/%s/%s' % (username, tag))

    else:
        form = RoadmapForm(instance=roadmap)
    
    
    base_url = '/roadmaps/%s/%s' % (username, tag) # TODO remove hardcoding
    edit_url = base_url + "/edit"
    history_url = base_url + "/history"

    return render(request, 'roadmap-edit.html', {
        'form': form,
        'tag': roadmap.url_tag,
        'edit_url': edit_url,
        'base_url': base_url,
        'history_url': history_url,
        'page_class': "edit",
        'roadmap': roadmap,
        'can_edit': can_edit,
        })
コード例 #2
0
def edit(request, in_username, tag):
    try:
        rm_dict = get_roadmap_objs(in_username, tag)
    except:
        return HttpResponse(status=404)

    roadmap = rm_dict["roadmap"]
    roadmap_settings = rm_dict["settings"]

    if not roadmap_settings.viewable_by(request.user):
        return HttpResponse(status=404)

    common_rm_dict = get_common_roadmap_dict(roadmap, roadmap_settings, request.user, in_username, tag)

    can_edit = roadmap_settings.editable_by(request.user)

    if request.method == 'POST':
        if not (request.user.is_authenticated() and can_edit):
            # TODO inform the user that they cannot edit
            return HttpResponse(status=401)

        form = RoadmapForm(request.POST, instance=roadmap)

        if form.is_valid():
            versions = _get_versions_obj(roadmap)
            cur_vn = len(versions) + 1
            smodel = form.save(commit=False)
            smodel.version_num = cur_vn
            with reversion.create_revision():
                smodel.save()
                reversion.set_user(request.user)
                reversion.set_comment(form.cleaned_data['commit_msg'])

            if request.POST["submitbutton"] == "Publish" and common_rm_dict['can_change_settings']:
                roadmap_settings.published = True
                roadmap_settings.save()
                return HttpResponseRedirect('/roadmaps/%s/%s' % (in_username, tag))

    elif request.method == 'GET':
        form = RoadmapForm(instance=roadmap)
    else:
        return HttpResponse(status=403)

    return render(request, 'roadmap-edit.html', dict({
        'form': form,
        'page_class': "edit",
    }, **common_rm_dict))
コード例 #3
0
def new(request):
    if not request.user.is_authenticated() or is_lazy_user(request.user):
        return HttpResponseRedirect(reverse("user:login"))

    if request.method == 'POST':
        form = RoadmapForm(request.POST)
        settings_form = RoadmapSettingsForm(request.POST)
        is_publish = request.POST["submitbutton"] == "Publish"

        if form.is_valid() and settings_form.is_valid():
            with reversion.create_revision():
                roadmap = form.save(commit=False)
                roadmap.save()
                reversion.set_user(request.user)

            rms = settings_form.save(commit=False)
            if not request.user.is_superuser:
                rms.sudo_listed_in_main = models.RoadmapSettings._meta.get_field_by_name('sudo_listed_in_main')[0].default # TODO hack

            if is_publish:
                rms.published = True

            rms.roadmap = roadmap
            prof = request.user.profile
            rms.creator = prof
            rms.save()
            rms.owners.add(prof)
            rms.save()

            return HttpResponseRedirect('/roadmaps/%s/%s'
                                        % (request.user.username,
                                           settings_form.cleaned_data['url_tag']))
    else:
        try:
            initial_txt = open(os.path.join(os.path.dirname(os.path.realpath(__file__)), "templates/roadmap-instructions.txt")).read()
        except:
            sys.stderr.write("unable to open roadmap instructions txt\n")
            initial_txt = ""
        form = RoadmapForm(initial={'body': initial_txt})
        settings_form = RoadmapSettingsForm()

    return render(request, 'roadmap-new.html', {
        'form': form,
        'settings_form': settings_form,
        'can_edit': True
        })
コード例 #4
0
def edit(request, in_username, tag):
    try:
        rm_dict = get_roadmap_objs(in_username, tag)
    except:
        return HttpResponse(status=404)

    roadmap = rm_dict["roadmap"]
    roadmap_settings = rm_dict["settings"]

    if not roadmap_settings.viewable_by(request.user):
        return HttpResponse(status=404)

    common_rm_dict = get_common_roadmap_dict(roadmap, roadmap_settings,
                                             request.user, in_username, tag)

    can_edit = roadmap_settings.editable_by(request.user)

    if request.method == 'POST':
        if not (request.user.is_authenticated() and can_edit):
            # TODO inform the user that they cannot edit
            return HttpResponse(status=401)

        form = RoadmapForm(request.POST, instance=roadmap)

        if form.is_valid():
            versions = _get_versions_obj(roadmap)
            cur_vn = len(versions) + 1
            smodel = form.save(commit=False)
            smodel.version_num = cur_vn
            with reversion.create_revision():
                smodel.save()
                reversion.set_user(request.user)
                reversion.set_comment(form.cleaned_data['commit_msg'])

            if request.POST["submitbutton"] == "Publish" and common_rm_dict[
                    'can_change_settings']:
                roadmap_settings.published = True
                roadmap_settings.save()
                return HttpResponseRedirect('/roadmaps/%s/%s' %
                                            (in_username, tag))

    elif request.method == 'GET':
        form = RoadmapForm(instance=roadmap)
    else:
        return HttpResponse(status=403)

    return render(
        request, 'roadmap-edit.html',
        dict({
            'form': form,
            'page_class': "edit",
        }, **common_rm_dict))
コード例 #5
0
def new(request):
    if not request.user.is_authenticated() or is_lazy_user(request.user):
        return HttpResponseRedirect(reverse("user:login"))

    if request.method == 'POST':
        form = RoadmapForm(request.POST)
        settings_form = RoadmapSettingsForm(request.POST)
        is_publish = request.POST["submitbutton"] == "Publish"

        if form.is_valid() and settings_form.is_valid():
            with reversion.create_revision():
                roadmap = form.save(commit=False)
                roadmap.save()
                reversion.set_user(request.user)

            rms = settings_form.save(commit=False)
            if not request.user.is_superuser:
                rms.sudo_listed_in_main = models.RoadmapSettings._meta.get_field_by_name(
                    'sudo_listed_in_main')[0].default  # TODO hack

            if is_publish:
                rms.published = True

            rms.roadmap = roadmap
            prof = request.user.profile
            rms.creator = prof
            rms.save()
            rms.owners.add(prof)
            rms.save()

            return HttpResponseRedirect(
                '/roadmaps/%s/%s' %
                (request.user.username, settings_form.cleaned_data['url_tag']))
    else:
        try:
            initial_txt = open(
                os.path.join(os.path.dirname(os.path.realpath(__file__)),
                             "templates/roadmap-instructions.txt")).read()
        except:
            sys.stderr.write("unable to open roadmap instructions txt\n")
            initial_txt = ""
        form = RoadmapForm(initial={'body': initial_txt})
        settings_form = RoadmapSettingsForm()

    return render(request, 'roadmap-new.html', {
        'form': form,
        'settings_form': settings_form,
        'can_edit': True
    })
コード例 #6
0
def edit(request, username, tag):

    roadmap = models.load_roadmap(username, tag)
    if roadmap is None:
        return HttpResponse(status=404)

    if not roadmap.visible_to(request.user):
        return HttpResponse(status=404)

    can_edit = roadmap.editable_by(request.user)

    if request.method == 'POST':
        if not (request.user.is_authenticated() and can_edit):
            # TODO inform the user that they cannot edit
            return HttpResponse(status=401)

        form = RoadmapForm(request.POST, instance=roadmap)

        if form.is_valid():
            versions = get_versions_obj(roadmap)
            cur_vn = len(versions) + 1
            smodel = form.save(commit=False)
            smodel.version_num = cur_vn
            with reversion.create_revision():
                smodel.save()
                reversion.set_user(request.user)
                reversion.set_comment(form.cleaned_data['commit_msg'])

            return HttpResponseRedirect('/roadmaps/%s/%s' % (username, tag))

    else:
        form = RoadmapForm(instance=roadmap)

    base_url = '/roadmaps/%s/%s' % (username, tag)  # TODO remove hardcoding
    edit_url = base_url + "/edit"
    history_url = base_url + "/history"

    return render(
        request, 'roadmap-edit.html', {
            'form': form,
            'tag': roadmap.url_tag,
            'edit_url': edit_url,
            'base_url': base_url,
            'history_url': history_url,
            'page_class': "edit",
            'roadmap': roadmap,
            'can_edit': can_edit,
        })
コード例 #7
0
def landing_page(request, page):
    content_model = page.get_content_model()
    edit_resource = page_processors.check_resource_mode(request)

    if not edit_resource:
        # get the context from hs_core
        context = page_processors.get_page_context(page, request.user,
                                                   resource_edit=edit_resource,
                                                   extended_metadata_layout=None,
                                                   request=request)
        extended_metadata_exists = False
        if content_model.metadata.url_base or content_model.metadata.version:
            extended_metadata_exists = True

        new_supported_res_types_array = []
        if content_model.metadata.supported_resource_types:
            extended_metadata_exists = True
            supported_res_types_str = content_model.metadata. \
                supported_resource_types.get_supported_res_types_str()
            supported_res_types_array = supported_res_types_str.split(',')
            for type_name in supported_res_types_array:
                for class_verbose_list in get_SupportedResTypes_choices():
                    if type_name.lower() == class_verbose_list[0].lower():
                        new_supported_res_types_array += [class_verbose_list[1]]
                        break

            context['supported_res_types'] = ", ".join(new_supported_res_types_array)

        new_supported_agg_types_array = []
        if content_model.metadata.supported_aggregation_types:
            extended_metadata_exists = True
            supported_agg_types_str = content_model.metadata. \
                supported_aggregation_types.get_supported_agg_types_str()
            supported_agg_types_array = supported_agg_types_str.split(',')
            for type_name in supported_agg_types_array:
                for class_verbose_list in get_SupportedAggTypes_choices():
                    if type_name.lower() == class_verbose_list[0].lower():
                        new_supported_agg_types_array += [class_verbose_list[1]]
                        break

            context['supported_agg_types'] = ", ".join(new_supported_agg_types_array)

        if content_model.metadata.supported_sharing_status is not None:
            extended_metadata_exists = True
            sharing_status_str = content_model.metadata.supported_sharing_status \
                .get_sharing_status_str()
            context['supported_sharing_status'] = sharing_status_str

        if content_model.metadata.app_icon:
            context['tool_icon_url'] = content_model.metadata.app_icon.data_url

        if content_model.metadata.supported_file_extensions:
            context['supported_file_extensions'] = content_model.metadata.supported_file_extensions

        context['extended_metadata_exists'] = extended_metadata_exists

        context['url_base'] = content_model.metadata.url_base
        context['url_base_aggregation'] = content_model.metadata.url_base_aggregation
        context['url_base_file'] = content_model.metadata.url_base_file
        context['version'] = content_model.metadata.version
        context['homepage_url'] = content_model.metadata.app_home_page_url
        context['testing_protocol_url'] = content_model.metadata.testing_protocol_url.first()
        context['help_page_url'] = content_model.metadata.help_page_url.first()
        context['source_code_url'] = content_model.metadata.source_code_url.first()
        context['issues_page_url'] = content_model.metadata.issues_page_url.first()
        context['mailing_list_url'] = content_model.metadata.mailing_list_url.first()
        context['roadmap'] = content_model.metadata.roadmap.first()
        # context['show_on_open_with_list'] = content_model.metadata.show_on_open_with_list.first()

    else:
        url_base = content_model.metadata.url_base
        url_base_form = UrlBaseForm(instance=url_base,
                                    res_short_id=content_model.short_id,
                                    element_id=url_base.id
                                    if url_base else None)

        url_base_aggregation = content_model.metadata.url_base_aggregation
        url_base_aggregation_form = UrlBaseAggregationForm(instance=url_base_aggregation,
                                                           res_short_id=content_model.short_id,
                                                           element_id=url_base_aggregation.id
                                                           if url_base_aggregation else None)

        url_base_file = content_model.metadata.url_base_file
        url_base_file_form = UrlBaseFileForm(instance=url_base_file,
                                             res_short_id=content_model.short_id,
                                             element_id=url_base_file.id
                                             if url_base_file else None)

        supported_file_extensions = content_model.metadata.supported_file_extensions
        supported_file_extensions_form = \
            SupportedFileExtensionsForm(instance=supported_file_extensions,
                                        res_short_id=content_model.short_id,
                                        element_id=supported_file_extensions.id
                                        if supported_file_extensions else None)

        homepage_url = content_model.metadata.app_home_page_url
        homepage_url_form = \
            AppHomePageUrlForm(instance=homepage_url,
                               res_short_id=content_model.short_id,
                               element_id=homepage_url.id
                               if homepage_url else None)

        testing_protocol_url = content_model.metadata.testing_protocol_url.first()
        testing_protocol_url_form = TestingProtocolUrlForm(instance=testing_protocol_url,
                                                           res_short_id=content_model.short_id,
                                                           element_id=testing_protocol_url.id
                                                           if testing_protocol_url else None)

        help_page_url = content_model.metadata.help_page_url.first()
        help_page_url_form = HelpPageUrlForm(instance=help_page_url,
                                             res_short_id=content_model.short_id,
                                             element_id=help_page_url.id
                                             if help_page_url else None)

        source_code_url = content_model.metadata.source_code_url.first()
        source_code_url_form = SourceCodeUrlForm(instance=source_code_url,
                                                 res_short_id=content_model.short_id,
                                                 element_id=source_code_url.id
                                                 if source_code_url else None)

        issues_page_url = content_model.metadata.issues_page_url.first()
        issues_page_url_form = IssuesPageUrlForm(instance=issues_page_url,
                                                 res_short_id=content_model.short_id,
                                                 element_id=issues_page_url.id
                                                 if issues_page_url else None)

        mailing_list_url = content_model.metadata.mailing_list_url.first()
        mailing_list_url_form = MailingListUrlForm(instance=mailing_list_url,
                                                   res_short_id=content_model.short_id,
                                                   element_id=mailing_list_url.id
                                                   if mailing_list_url else None)

        roadmap = content_model.metadata.roadmap.first()
        roadmap_form = RoadmapForm(instance=roadmap,
                                   res_short_id=content_model.short_id,
                                   element_id=roadmap.id
                                   if roadmap else None)

        # show_on_open_with_list = content_model.metadata.show_on_open_with_list.first()
        # show_on_open_with_list_form = ShowOnOpenWithListForm(instance=show_on_open_with_list,
        #                                                      res_short_id=content_model.short_id,
        #                                                      element_id=show_on_open_with_list.id
        #                                                      if show_on_open_with_list else None)

        version = content_model.metadata.version
        version_form = VersionForm(instance=version,
                                   res_short_id=content_model.short_id,
                                   element_id=version.id
                                   if version else None)

        supported_res_types_obj = content_model.metadata.supported_resource_types
        supported_res_types_form = SupportedResTypesForm(instance=supported_res_types_obj,
                                                         res_short_id=content_model.short_id,
                                                         element_id=supported_res_types_obj.id
                                                         if supported_res_types_obj else None)

        supported_agg_types_obj = content_model.metadata.supported_aggregation_types
        supported_agg_types_form = SupportedAggTypesForm(instance=supported_agg_types_obj,
                                                         res_short_id=content_model.short_id,
                                                         element_id=supported_agg_types_obj.id
                                                         if supported_agg_types_obj else None)

        sharing_status_obj = content_model.metadata.supported_sharing_status
        sharing_status_obj_form = \
            SupportedSharingStatusForm(instance=sharing_status_obj,
                                       res_short_id=content_model.short_id,
                                       element_id=sharing_status_obj.id
                                       if sharing_status_obj else None)

        tool_icon_obj = content_model.metadata.app_icon
        tool_icon_form = ToolIconForm(instance=tool_icon_obj,
                                      res_short_id=content_model.short_id,
                                      element_id=tool_icon_obj.id
                                      if tool_icon_obj else None)

        ext_md_layout = Layout(
            HTML('<div class="form-group col-lg-6 col-xs-12" id="SupportedResTypes"> '
                 '{% load crispy_forms_tags %} '
                 '{% crispy supported_res_types_form %} '
                 '</div> '),
            HTML('<div class="form-group col-lg-6 col-xs-12" id="SupportedAggTypes"> '
                 '{% load crispy_forms_tags %} '
                 '{% crispy supported_agg_types_form %} '
                 '</div> '),
            HTML('<div class="form-group col-lg-6 col-xs-12" id="SupportedSharingStatus"> '
                 '{% load crispy_forms_tags %} '
                 '{% crispy sharing_status_obj_form %} '
                 '</div> '),
            HTML("<div class='form-group col-lg-6 col-xs-12' id='supported_file_extensions'> "
                 '{% load crispy_forms_tags %} '
                 '{% crispy supported_file_extensions_form %} '
                 '</div>'),
            HTML("<div class='form-group col-lg-6 col-xs-12' id='homepage_url'> "
                 '{% load crispy_forms_tags %} '
                 '{% crispy homepage_url_form %} '
                 '</div>'),
            HTML("<div class='form-group col-lg-6 col-xs-12' id='url_bases'> "
                 '{% load crispy_forms_tags %} '
                 '{% crispy url_base_form %} '
                 '</div>'),
            HTML("<div class='form-group col-lg-6 col-xs-12' id='url_bases_aggregation'> "
                 '{% load crispy_forms_tags %} '
                 '{% crispy url_base_aggregation_form %} '
                 '</div>'),
            HTML("<div class='form-group col-lg-6 col-xs-12' id='url_bases_file'> "
                 '{% load crispy_forms_tags %} '
                 '{% crispy url_base_file_form %} '
                 '</div>'),
            HTML('<div class="form-group col-lg-6 col-xs-12" id="version"> '
                 '{% load crispy_forms_tags %} '
                 '{% crispy version_form %} '
                 '</div> '),
            HTML('<div class="form-group col-lg-6 col-xs-12" id="tool_icon"> '
                 '{% load crispy_forms_tags %} '
                 '{% crispy tool_icon_form %} '
                 '</div> '),
            HTML("<div class='form-group col-lg-6 col-xs-12' id='testing_protocol_url'> "
                 '{% load crispy_forms_tags %} '
                 '{% crispy testing_protocol_url_form %} '
                 '</div>'),
            HTML("<div class='form-group col-lg-6 col-xs-12' id='help_page_url'> "
                 '{% load crispy_forms_tags %} '
                 '{% crispy help_page_url_form %} '
                 '</div>'),
            HTML("<div class='form-group col-lg-6 col-xs-12' id='source_code_url'> "
                 '{% load crispy_forms_tags %} '
                 '{% crispy source_code_url_form %} '
                 '</div>'),
            HTML("<div class='form-group col-lg-6 col-xs-12' id='issues_page_url'> "
                 '{% load crispy_forms_tags %} '
                 '{% crispy issues_page_url_form %} '
                 '</div>'),
            HTML("<div class='form-group col-lg-6 col-xs-12' id='mailing_list_url'> "
                 '{% load crispy_forms_tags %} '
                 '{% crispy mailing_list_url_form %} '
                 '</div>'),
            HTML("<div class='form-group col-lg-6 col-xs-12' id='roadmap'> "
                 '{% load crispy_forms_tags %} '
                 '{% crispy roadmap_form %} '
                 '</div>'),
            # HTML("<div class='form-group col-lg-6 col-xs-12' id='show_on_open_with_list'> "
            #      '{% load crispy_forms_tags %} '
            #      '{% crispy show_on_open_with_list_form %} '
            #      '</div>'),
        )

        # get the context from hs_core
        context = page_processors.get_page_context(page, request.user,
                                                   resource_edit=edit_resource,
                                                   extended_metadata_layout=ext_md_layout,
                                                   request=request)
        context['url_base_form'] = url_base_form
        context['url_base_aggregation_form'] = url_base_aggregation_form
        context['url_base_file_form'] = url_base_file_form
        context['supported_file_extensions_form'] = supported_file_extensions_form
        context['homepage_url_form'] = homepage_url_form
        context['version_form'] = version_form
        context['supported_res_types_form'] = supported_res_types_form
        context['supported_agg_types_form'] = supported_agg_types_form
        context['tool_icon_form'] = tool_icon_form
        context['sharing_status_obj_form'] = sharing_status_obj_form
        context['testing_protocol_url_form'] = testing_protocol_url_form
        context['help_page_url_form'] = help_page_url_form
        context['source_code_url_form'] = source_code_url_form
        context['issues_page_url_form'] = issues_page_url_form
        context['mailing_list_url_form'] = mailing_list_url_form
        context['roadmap_form'] = roadmap_form
        # context['show_on_open_with_list_form'] = show_on_open_with_list_form

    hs_core_dublin_context = add_generic_context(request, page)
    context.update(hs_core_dublin_context)

    return context