So when pushing to Github I've all of a sudden started to receive the following issue.
remote: Password authentication is temporarily disabled as part of a brownout. Please use a personal access token instead.
remote: Please see https://github.blog/2020-07-30-token-authentication-requirements-for-api-and-git-operations/ for more information.
fatal: unable to access 'https://github.com/flowmoco/siaf.git/': The requested URL returned error: 403
The first thing you'll need to do is set up Personal Access Token in Github. Following the instructions here to do that. Add a Personal Access Token to Github
After that I have read that you can then open 'Keychain Access' and search for github.
Next you should be able to right click that and delete it.
Then you'll be able to 'git push' and you'll be asked for your Username and Token Access.
However deleting the keychain for me didn't work. If the same happens for you then this worked for me.
Double click on the 'github.com' in the Name column.
From here you can change the 'Kind' to 'access token' and the Password to the Keychain password that you've been given.
This task ran me around in circles somewhat, until we found the solution which was literally 1 line of code. Hopefully if you've stumbled across this blog it may save you losing the time that I did on it.
Let's have a closer look at the problem we're looking to fix here.
So let's say we have a 'ElectricCarPage' and when creating the Page one of our fields is for 'Manufacturer' . Which we are using Snippets for. On the 'ElectricCarPage' we have this set as 'required' . So one has to be added, however there is a way that the Administration could leave our Page without a Manufacturer ( and possible breaking the site ) . And that would be to do through the Snippets admin and remove the Snippet here
The Solution ___________
So let's cut straight to the chase and give you the solution and then I'll go through the other methods that I'd been through and their gotchas.
+ Add 'on_delete=models.PROTECT' to the Manufacturer field in the 'ElectricCarPage' class. Like
class CarPage(Page): manufacturer = ForeignKeyField(
"car.Manufacturer",
verbose_name=_("Manufacturer"),
on_delete=models.PROTECT,
related_name="manufacturer",
required=True,
help_text=_(
"The car manufacturer "
),
)
This solution gives you the above screen when you try and delete the Snippet.
This is to be added in the GamePage model like so.
class CarPage(Page): manufacturer = ForeignKeyField(
"car.Manufacturer",
verbose_name=_("Manufacturer"),
on_delete=models.RESTRICT,
related_name="manufacturer",
required=True,
help_text=_(
"The car manufacturer "
),
)
However rather than the screenshot above after you try and delete it throws an error.
FIX ATTEMPT 2
The next solution is to use the following code in the Developer Snippet
1def delete(self, *args, **kwargs):
2 CarPage = apps.get_model("cars", "CarPage")
3 carpages = CarPage.objects.filter(manufacturer=self)
4 if carpages:
5 print("@todo Let the user know that they can't delete!")
6 return
7 else:
8 super().delete(*args, **kwargs)
However I met another brick wall when trying to complete this and that’s in that I can output to a message as there is no request to use in this method.
I really feel that there should be a way to resolve this method, so if you have one then please let me know, it'd be very useful for future development.
FIX ATTEMPT 3
1from django.http import HttpResponse
23from wagtail.core import hooks
45@hooks.register('before_delete_snippet')
6def before_snippet_delete(request, instances):
7 # "instances" is a QuerySet
8 total = len(instances)
910 if request.method == 'POST':
11 # Override the deletion behaviour
12 instances.delete()
1314 return HttpResponse(f"{total} snippets have been deleted", content_type="text/plain")
That hook works if you go through 'Admin>Snippets>Manufacturer' . However I also have a custom Admin menu items for ' Manufacturer' and if you navigate through that way the hook isn't called.
I think this is a real bug for Snippet Hooks. Even if you’re not using separate Admin menu items then whose not to say it may not be requested in the future.