示例#1
0
def ajax_close(request, object_key):
    """
    Render the html to replace existing when closing via ajax the private editor
    """
    obj = get_object_from_str(object_key)
    return render(request, 'private/edit_private_ajax_onclose.html', dict(
        obj_type = get_app_and_model(obj)[1],
        object = obj,
    ))
示例#2
0
文件: views.py 项目: waytai/Repos.io
def ajax_close(request, object_key):
    """
    Render the html to replace existing when closing via ajax the private editor
    """
    obj = get_object_from_str(object_key)
    return render(request, 'private/edit_private_ajax_onclose.html',
                  dict(
                      obj_type=get_app_and_model(obj)[1],
                      object=obj,
                  ))
示例#3
0
def edit_private(object_str):
    """
    Display the the private editor for the given object. `object_str` is the object
    representaiton as defined by the `simple_str` method in the core module.
    """
    if not (object_str and globals.user and globals.user.is_authenticated()):
        return {}

    try:
        # find the object
        edit_object = get_object_from_str(object_str)
        app_label, model_name = get_app_and_model(edit_object)

        # get private data
        note = edit_object.get_user_note()
        private_tags = edit_object.get_user_tags()

        # special tags
        flags_and_tags = split_tags_and_flags(private_tags, model_name)

        # get other private tags
        other_tags = Tag.objects.filter(
                **{'private_%s_tags__owner' % model_name:globals.user})
        if private_tags:
            other_tags = other_tags.exclude(
                    id__in=[t.id for t in private_tags])
        if flags_and_tags['special']:
            other_tags = other_tags.exclude(
                    slug__in=[t['slug'] for t in flags_and_tags['special']])
        other_tags = other_tags.distinct()

        # for tags url
        if model_name == 'account':
            model_name_plural = 'accounts'
        else:
            model_name_plural = 'repositories'

        # urls for edit link and when_finished link
        if globals.request.is_ajax():
            when_finished = globals.request.META.get('HTTP_REFERER')
            if when_finished:
                host = 'http%s://%s' % (
                    's' if globals.request.is_secure() else '',
                    globals.request.get_host()
                )
                if when_finished.startswith(host):
                    when_finished = when_finished[len(host):]
                else:
                    when_finished = None
            if not when_finished:
                when_finished = edit_object.get_absolute_url()
            edit_url = when_finished + '%sedit_extra=%s&when_finished=%s' % (
                '&' if '?' in when_finished else '?',
                edit_object.simple_str(),
                urlquote(when_finished),
            )
        else:
            when_finished = get_request_param(globals.request, 'when_finished')
            edit_url = get_request_param(globals.request, 'edit_url', globals.request.get_full_path())

        return dict(
            edit_object = edit_object,
            note_save_form = NoteForm(instance=note) if note else NoteForm(noted_object=edit_object),
            note_delete_form = NoteDeleteForm(instance=note) if note else None,
            tag_save_form = TagsBaseForm(tagged_object=edit_object),
            tags_delete_form = TagsDeleteForm(tagged_object=edit_object) if private_tags else None,
            private_tags = flags_and_tags['normal'],
            other_tags = other_tags,
            special_tags = flags_and_tags['special'],
            used_special_tags = flags_and_tags['special_used'],
            url_tags = reverse('dashboard_tags', kwargs=dict(obj_type=model_name_plural)),
            edit_url = edit_url,
            when_finished = when_finished,
        )

    except:
        return {}
示例#4
0
def edit_private(object_str):
    """
    Display the the private editor for the given object. `object_str` is the object
    representaiton as defined by the `simple_str` method in the core module.
    """
    if not (object_str and globals.user and globals.user.is_authenticated()):
        return {}

    try:
        # find the object
        edit_object = get_object_from_str(object_str)
        app_label, model_name = get_app_and_model(edit_object)

        # get private data
        note = edit_object.get_user_note()
        private_tags = edit_object.get_user_tags()

        # special tags
        flags_and_tags = split_tags_and_flags(private_tags, model_name)

        # get other private tags
        other_tags = Tag.objects.filter(
            **{'private_%s_tags__owner' % model_name: globals.user})
        if private_tags:
            other_tags = other_tags.exclude(
                id__in=[t.id for t in private_tags])
        if flags_and_tags['special']:
            other_tags = other_tags.exclude(
                slug__in=[t['slug'] for t in flags_and_tags['special']])
        other_tags = other_tags.distinct()

        # for tags url
        if model_name == 'account':
            model_name_plural = 'accounts'
        else:
            model_name_plural = 'repositories'

        # urls for edit link and when_finished link
        if globals.request.is_ajax():
            when_finished = globals.request.META.get('HTTP_REFERER')
            if when_finished:
                host = 'http%s://%s' % ('s' if globals.request.is_secure() else
                                        '', globals.request.get_host())
                if when_finished.startswith(host):
                    when_finished = when_finished[len(host):]
                else:
                    when_finished = None
            if not when_finished:
                when_finished = edit_object.get_absolute_url()
            edit_url = when_finished + '%sedit_extra=%s&when_finished=%s' % (
                '&' if '?' in when_finished else '?',
                edit_object.simple_str(),
                urlquote(when_finished),
            )
        else:
            when_finished = get_request_param(globals.request, 'when_finished')
            edit_url = get_request_param(globals.request, 'edit_url',
                                         globals.request.get_full_path())

        return dict(
            edit_object=edit_object,
            note_save_form=NoteForm(instance=note) if note else NoteForm(
                noted_object=edit_object),
            note_delete_form=NoteDeleteForm(instance=note) if note else None,
            tag_save_form=TagsBaseForm(tagged_object=edit_object),
            tags_delete_form=TagsDeleteForm(
                tagged_object=edit_object) if private_tags else None,
            private_tags=flags_and_tags['normal'],
            other_tags=other_tags,
            special_tags=flags_and_tags['special'],
            used_special_tags=flags_and_tags['special_used'],
            url_tags=reverse('dashboard_tags',
                             kwargs=dict(obj_type=model_name_plural)),
            edit_url=edit_url,
            when_finished=when_finished,
        )

    except:
        return {}