Code Monkey home page Code Monkey logo

Comments (5)

beatonma avatar beatonma commented on July 17, 2024

Hey,

I think I know what's causing this - MentionableMixin has the fields:

allow_incoming_webmentions = models.BooleanField(default=True)
allow_outgoing_webmentions = models.BooleanField(default=False)

As you can see, allow_outgoing_webmentions defaults to False. Thank you for reminding me about this default behaviour! I definitely need to add this to the documentation because it's not at all obvious.

So for outgoing webmentions to be processed you need to set allow_outgoing_webmentions to True. How you do that depends on your preference and/or how you create your posts.

Change default behaviour

If you always want your model to process outgoing mentions you can override the field on your model:

class MyPostModel(MentionableMixin, models.Model):
    allow_outgoing_webmentions = models.BooleanField(default=True)
    ...


    def all_text(self):
        """This also needs to be implemented if you haven't already!
        It should return whatever text you want to process for
        outgoing mentions."""
        return f'{self.title} {self.content}'

(You will need to run makemigrations and migrate after doing this.)

Outgoing mentions should then be processed every time you save your post.

Keep default behaviour

Creating/editing via Django Admin pages

If you are editing your posts via the Django Admin and you are using fieldsets then add allow_outgoing_webmentions:

@admin.register(MyPostModel)
class MyPostModelAdmin(admin.ModelAdmin):
    fieldsets = (
        ...
        ('Mentions', {
            'fields': (
                'allow_incoming_webmentions',
                'allow_outgoing_webmentions',
            ),
        }),
        ...
    )

This will provide a checkbox that you can tick when you want to process outgoing mentions.

(If you are not using fieldsets then those fields should already appear on the admin page.)

Creating/editing manually

If you are creating the posts via MyPostModel.objects.create() then you will need to set the field before saving:

post = MyPostModel.objects.create(title='whatever')
post.allow_outgoing_webmentions = True
post.save()

Let me know if that fixes the issue for you. I will add this to the documentation asap.

from django-wm.

rasulkireev avatar rasulkireev commented on July 17, 2024

I will certainly adjust my model to have allow_outgoing_webmentions = models.BooleanField(default=True). However I think this is not the issue.

This is how my django-admin "Add a Post" looks like:
image

I made sure to allow outgoing webmentions before saving the post.

I will make some adjustment to my code base as you suggested. Meanwhile, do you have a suggestion as to how to debug sending and receiving webmentions? For example, do you think it would be useful to check celery logs on the server?

Thanks a ton in advance.

from django-wm.

beatonma avatar beatonma commented on July 17, 2024

Hey,

Yes, your celery logs should show several messages while the task runs. Something like:

outgoing_webmentions Checking for outgoing webmention links...
outgoing_webmentions Checking url=https://django-wm.dev
outgoing_webmentions Found webmention endpoint: https://django-wm.dev:443/webmention/
outgoing_webmentions https://django-wm.dev:443/webmention/: {'target': 'https://django-wm.dev', 'source': 'https://beatonma.org/a/190406-webmention-test'}
outgoing_webmentions Sending webmention to "https://django-wm.dev:443/webmention/" successful with status_code=202

Also, I have just published an update which adds a new model to help track the status of outgoing mentions. I've also added a log message so you can see when the process_outgoing_webmentions task is passed to Celery after saving your post.

Please update to this version, run makemigrations and migrate, reload your server and save a post with a mentionable link again. You should then see Outgoing webmention processing task added to queue... in your server log, and you should see an entry at your-server-admin-url/mentions/outgoingwebmentionstatus/ like this:

outgoing-wm-admin

Sorry for the late response - I'm off until Tuesday now so I'll be more available until then!

Michael

from django-wm.

rasulkireev avatar rasulkireev commented on July 17, 2024

What command do you use to check Celery logs on your server (or what file you look at)? I've googled this and read the documentation, but couldn't get it quite right. Thanks in advance.

from django-wm.

beatonma avatar beatonma commented on July 17, 2024

I'm not sure what the default behaviour is - you could try tail -f /var/log/syslog. If that doesn't show anything useful I'd look in /var/log/ for something like celery.log.

Otherwise, you can configure the log to go anywhere you like via the LOGGING entry in your project settings file. If you already have a LOGGING entry you can just add the following to LOGGING.loggers:

        'celery.task': {
            'handlers': ['console', 'file',],  # These are defined in LOGGING.handlers - see below if you need to add those entries
            'propagate': True,
            'level': 'DEBUG',
        },

Here's an example:

# settings.py
CELERY_LOG_PATH = '/path/to/mysite-celery.log'  # Make sure your `celery` user has write access to this file, wherever you put it!
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %($
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        },
    },
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'simple',
        },
        'file': {
            'level': 'INFO',
            'class': 'logging.handlers.RotatingFileHandler',
            'formatter': 'verbose',
            'filename': CELERY_LOG_PATH,
            'maxBytes': 1 * 1024 * 1024,
            'backupCount': 2
        },
    },

    'loggers': {
        'celery.task': {
            'handlers': ['console', 'file',],
            'propagate': True,
            'level': 'DEBUG',
        },
        # add any other app loggers you want here
    },
}

from django-wm.

Related Issues (20)

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.