Exemple #1
0
    def handle(self, *args, **kwargs):
        filepath = kwargs['file']
        username = kwargs['user']
        with open(filepath) as html_file:
            html = html_file.read()
        user = User.objects.get(username=username)

        import_netscape_html(html, user)
Exemple #2
0
def bookmark_import(request):
    try:
        import_file = request.FILES.get('import_file')
        content = import_file.read()
        import_netscape_html(content, request.user)
        messages.success(request, 'Bookmarks were successfully imported.',
                         'bookmark_import')
    except Exception:
        messages.error(request, 'An error occurred during bookmark import.',
                       'bookmark_import')
        pass

    return HttpResponseRedirect(reverse('bookmarks:settings.index'))
Exemple #3
0
def bookmark_import(request):
    import_file = request.FILES.get('import_file')

    if import_file is None:
        messages.error(request, 'Please select a file to import.',
                       'bookmark_import_errors')
        return HttpResponseRedirect(reverse('bookmarks:settings.index'))

    try:
        content = import_file.read()
        result = import_netscape_html(content, request.user)
        success_msg = str(
            result.success) + ' bookmarks were successfully imported.'
        messages.success(request, success_msg, 'bookmark_import_success')
        if result.failed > 0:
            err_msg = str(
                result.failed
            ) + ' bookmarks could not be imported. Please check the logs for more details.'
            messages.error(request, err_msg, 'bookmark_import_errors')
    except:
        logging.exception('Unexpected error during bookmark import')
        messages.error(request, 'An error occurred during bookmark import.',
                       'bookmark_import_errors')
        pass

    return HttpResponseRedirect(reverse('bookmarks:settings.index'))