Giter VIP home page Giter VIP logo

django-webmention's Introduction

django-webmention PyPI version Build Status

webmention for Django projects.

What this project is

This package provides a way to integrate webmention endpoint discovery and webmention receipts into your project. Once you follow the installation instructions, you should be able to use something like webmention.rocks to generate a test webmention and see it in the Django admin panel.

Once you receive a webmention, you can click through to the page the webmention was sent from and see what people are saying about your site. Afterward, you can mark the webmention as reviewed in the Django admin so you can more easily see the latest webmentions you receive.

Once you verify that you're receiving webmentions successfully, you can use the webmention information as you like. As an example, you could query the webmentions that are responses to a specific page and display them on that page.

What this project isn't

This package does not currently provide functionality for sending webmentions.

Installation

$ pip install django-webmention

  • Add 'webmention' to INSTALLED_APPS
  • Run python manage.py migrate webmention
  • Add the URL patterns to your top-level urls.py
    • path('webmention/', include('webmention.urls')) for Django >= 3.2

Usage

  • Include webmention information by either:
    • Installing the middleware in settings.py (affects all views)
      • Append webmention.middleware.webmention_middleware to your MIDDLEWARE settings
    • Decorating a specific view with webmention.middleware.include_webmention_information
  • View webmention responses in the Django admin interface and mark them as reviewed as needed

Development

Setup

Running Tests

You can run tests using tox:

$ tox --parallel=auto

django-webmention's People

Contributors

daneah avatar jamesvandyne avatar philgyford avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

django-webmention's Issues

URLs in Admin show as HTML rather than clickable links

In both the Admin list view and the create/edit view for Webmentions, the clickable links show as HTML rather than clickable links:

Screenshot 2020-08-24 at 12 42 03

Screenshot 2020-08-24 at 12 42 32

I guess they should be building the HTML using format_html(), something like in this StackOverflow answer.

I don't know if the Response body in the create/edit view is supposed to be raw HTML like that - maybe it is; if so, that's fine :)

(Django 3.1)

Migrate to GitHub Actions

This project is currently still configured to use Travis CI, but is no longer hooked up to it. The preferred flow now uses GitHub Actions—an example can be seen in code companion for Publishing Python Packages.

Outcome

  • Travis CI configuration is removed
  • GitHub Actions provides feedback on each pull request about the unit tests and linting
  • GitHub Actions triggers a PyPI release and creates a GitHub release with artifacts when an appropriate version tag is created (may require secrets to be set, which can be coordinated later)

Django 1.10 compatibility

Django: 1.10.8
Python: 3.6.3

With middleware enabled in settings.py, the following error occurs:

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x10ed9bea0>
Traceback (most recent call last):
  File "/Users/tehfink/Documents/work/mylittlepony.net/www./source/3.0/mlp_website-virtualenv/lib/python3.6/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/Users/tehfink/Documents/work/mylittlepony.net/www./source/3.0/mlp_website-virtualenv/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 142, in inner_run
    handler = self.get_handler(*args, **options)
  File "/Users/tehfink/Documents/work/mylittlepony.net/www./source/3.0/mlp_website-virtualenv/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 27, in get_handler
    handler = super(Command, self).get_handler(*args, **options)
  File "/Users/tehfink/Documents/work/mylittlepony.net/www./source/3.0/mlp_website-virtualenv/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 64, in get_handler
    return get_internal_wsgi_application()
  File "/Users/tehfink/Documents/work/mylittlepony.net/www./source/3.0/mlp_website-virtualenv/lib/python3.6/site-packages/django/core/servers/basehttp.py", line 46, in get_internal_wsgi_application
    return get_wsgi_application()
  File "/Users/tehfink/Documents/work/mylittlepony.net/www./source/3.0/mlp_website-virtualenv/lib/python3.6/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
    return WSGIHandler()
  File "/Users/tehfink/Documents/work/mylittlepony.net/www./source/3.0/mlp_website-virtualenv/lib/python3.6/site-packages/django/core/handlers/wsgi.py", line 153, in __init__
    self.load_middleware()
  File "/Users/tehfink/Documents/work/mylittlepony.net/www./source/3.0/mlp_website-virtualenv/lib/python3.6/site-packages/django/core/handlers/base.py", line 82, in load_middleware
    mw_instance = middleware(handler)
TypeError: object() takes no parameters

response_body saving bytes instead of a decoded string

I noticed a subtle bug in the resolution.py::fetch_and_validate_source.

While response.content is a bytes-string ( docs), it's never decoded before saving to the database. As a result it saves as a string into the db as follows: "b'\n<!DOCTYPE html><html><head><meta charset="utf-8" />\n<....".

Practically speaking this is fine for pure ascii data, but any unicode characters aren't be properly decoded before saving, resulting in double-escaped characters and must be corrected before you can display it properly to the user. e.g. "Çelik" will be saved as "\xc3\x87elik"

>>> b'\xc3\x87elik'  # raw bytes from response.content
b'\xc3\x87elik'
>>> str(b'\xc3\x87elik')  # raw string conversion gets double esacped
"b'\\xc3\\x87elik'" 
>>> b'\xc3\x87elik'.decode("utf-8")  # properly decoded
'Çelik'

Existing response_bodies can be fixed using ftfy package by running the string through something like this ftfy.fix_text(ftfy.fixes.decode_escapes(mention.response_body)).

Changing fetch_and_validate_source to return response.text, which is simply the decoded response.content would fix this issue. Looking for the target in str(response.content) might also have a subtle bug if you used a utf-8 domain as well, so I believe it should validate using response.text as well.

Refactored I think it should look something like this:

def fetch_and_validate_source(source, target):
    response = requests.get(source)
    if response.status_code == 200:
        if target in response.text:
            return response.text
        else:
            raise TargetNotFoundError("Source URL did not contain target URL")
    else:
        raise SourceFetchError("Could not fetch source URL")

What else is required to enable webmentions?

It would be great to have a little more documentation about what installing this does, and what else is required. I have a very rough idea of how webmentions work, but am very, very far from an expert, so forgive me if any of this is blindingly obvious to you... but I'm a bit stumped as to how to proceed.

  1. Having installed django-webmention as described in the README I'm not sure what I should expect to see happen
    1. What exactly does django-webmention do that enables Webmentions to be received or sent?
    2. I noticed that there's an HTTP Response header like Link: <https://example.org/webmention/receive>; rel="webmention". It should be mentioned that this is what happens. Does anything else happen?
    3. What, if anything, do I need to do other than decorate a view?
  2. Having created a new page featuring the 23 Discovery Test URLs on [Webmention Rocks!](Webmention Endpoint Discovery) I don't see anything appearing on that site to indicate webmentions have been sent. Should I?
  3. Doing the first "Test Your Receiver" test on that site I do receive a webmention and can see it in the admin!
    1. I guess I'm supposed to mark an incoming webmention as "Reviewed" if it's OK? What if I "review" a webmention and decide that it's unwanted or spam? Should I delete it?
    2. I assume that for any page that has webmentions enabled I should query for any Webmention objects that have a response_to attribute that matches the URL of that page, pass them to the template and display them?
  4. Should I add something else to my templates to let people know that Webmentions are accepted? If so, what?

Sorry if this is basic but having installed it I was a bit "Now what? Do I have to do anything else? Is it working? How can I tell?"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.