1
Fork 0
recovering-deleted-wagtail-.../slides.md

216 lines
3.3 KiB
Markdown
Raw Normal View History

2024-04-05 18:01:50 +01:00
---
title: Recovering deleted Wagtail pages and Django models
class: text-center
highlighter: shiki
transition: slide-left
2024-04-18 17:05:39 +01:00
mdc: true
themeConfig:
primary: '#fd5765'
2024-04-05 18:01:50 +01:00
---
2024-04-18 17:05:39 +01:00
# Recovering [deleted]{style="color: #fd5765"} Wagtail pages and Django models
2024-04-05 18:01:50 +01:00
2024-04-18 17:05:39 +01:00
### Jake Howard{style="color: #e85537;" }
2024-04-05 18:01:50 +01:00
2024-04-18 17:05:39 +01:00
<ul class="list-none! text-sm [&>li]:m-0! mt-1 uppercase font-light">
<li><em>Senior Systems Engineer</em> @ Torchbox</li>
<li><em>Security Team</em> & <em>Performance Working Group</em> @ Wagtail</li>
</ul>
<ul class="list-none! text-sm [&>li]:m-0! mt-3">
<li><mdi-earth /> theorangeone.net</li>
<li><mdi-twitter /> @RealOrangeOne</li>
<li><mdi-github /> @RealOrangeOne</li>
<li><mdi-mastodon /> @jake@theorangeone.net</li>
</ul>
2024-04-05 18:01:50 +01:00
---
layout: cover
background: https://cdn.jsdelivr.net/gh/wagtail/wagtail@main/.github/wagtail-screenshot-with-browser.png
---
# Setting the scene
---
layout: cover
---
# Site history report
---
2024-05-10 17:53:24 +01:00
layout: section
2024-04-05 18:01:50 +01:00
---
# Restoring from backups
---
2024-05-10 17:53:24 +01:00
layout: section
2024-04-05 18:01:50 +01:00
---
# _Partial_ restores from backups
---
2024-05-10 17:53:24 +01:00
layout: section
2024-04-05 18:01:50 +01:00
---
2024-05-10 17:53:24 +01:00
## 1.
# Spin up a database backup
2024-04-05 18:01:50 +01:00
---
2024-05-10 17:53:24 +01:00
layout: section
2024-04-05 18:01:50 +01:00
---
2024-05-10 17:53:24 +01:00
## 2.
# Locate the page models
2024-04-05 18:01:50 +01:00
<div class="pt-5">
```python
from wagtail.models import Page
sysadmin_page = Page.objects.get(id=91)
child_pages = sysadmin_page.get_descendants()
```
</div>
<style>
pre.shiki {
2024-05-10 17:53:24 +01:00
font-size: 1.4rem !important;
text-align: left;
2024-04-05 18:01:50 +01:00
}
</style>
2024-05-10 17:53:24 +01:00
---
layout: section
---
## 3.
# Locate what was deleted
2024-04-05 18:01:50 +01:00
<div class="pt-5">
```python
from django.contrib.admin.utils import NestedObjects
collector = NestedObjects()
collector.collect(list(child_pages) + [sysadmin_page])
```
</div>
<style>
pre.shiki {
2024-05-10 17:53:24 +01:00
font-size: 1.4rem !important;
text-align: left;
2024-04-05 18:01:50 +01:00
}
</style>
2024-05-10 17:53:24 +01:00
---
layout: section
---
2024-04-05 18:01:50 +01:00
# 4. Serialize
<div class="pt-5">
```python
from django.core import serializers
class NoM2MSerializer(Serializer):
def handle_m2m_field(self, obj, field):
pass
def get_model_instances():
for qs in collector.data.values():
yield from qs
with open("deleted-models.json", "w") as f:
NoM2MSerializer().serialize(
get_model_instances(),
stream=f
)
```
</div>
2024-05-10 17:53:24 +01:00
<style>
pre.shiki {
font-size: 1rem !important;
text-align: left;
}
</style>
2024-04-05 18:01:50 +01:00
---
2024-05-10 17:53:24 +01:00
layout: section
2024-04-05 18:01:50 +01:00
---
2024-05-10 17:53:24 +01:00
## 4a.
# Deserialize
2024-04-05 18:01:50 +01:00
---
layout: center
---
2024-05-10 17:53:24 +01:00
# `restore-deleted-pages.py`
```python {all}{lines:true}
from django.contrib.admin.utils import NestedObjects
from django.core import serializers
from wagtail.models import Page
class NoM2MSerializer(Serializer):
def handle_m2m_field(self, obj, field):
pass
sysadmin_page = Page.objects.get(id=91)
child_pages = sysadmin_page.get_descendants()
collector = NestedObjects()
collector.collect(list(child_pages) + [sysadmin_page])
def get_model_instances():
for qs in collector.data.values():
yield from qs
with open("deleted-models.json", "w") as f:
NoM2MSerializer().serialize(
get_model_instances(),
stream=f
)
```
---
layout: section
---
#### 5.
### Test
## Test
# **Test!**
2024-04-05 18:01:50 +01:00
---
2024-05-10 17:53:24 +01:00
layout: image-right
image: /red-button.png
class: flex justify-center flex-col items-center
2024-04-05 18:01:50 +01:00
---
2024-05-10 17:53:24 +01:00
### 6.
# Showtime!
2024-04-05 18:01:50 +01:00
---
2024-05-10 17:53:24 +01:00
layout: cover
background: https://cdn.jsdelivr.net/gh/wagtail/wagtail@main/.github/wagtail-screenshot-with-browser.png
2024-04-05 18:01:50 +01:00
---
# Conclusion
2024-05-10 17:53:24 +01:00
---
layout: end
---