evewiki 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. evewiki-0.0.1/LICENSE +21 -0
  2. evewiki-0.0.1/PKG-INFO +136 -0
  3. evewiki-0.0.1/README.md +106 -0
  4. evewiki-0.0.1/evewiki/__init__.py +6 -0
  5. evewiki-0.0.1/evewiki/admin.py +16 -0
  6. evewiki-0.0.1/evewiki/app_settings.py +5 -0
  7. evewiki-0.0.1/evewiki/apps.py +9 -0
  8. evewiki-0.0.1/evewiki/auth_hooks.py +40 -0
  9. evewiki-0.0.1/evewiki/forms.py +51 -0
  10. evewiki-0.0.1/evewiki/migrations/0001_initial.py +190 -0
  11. evewiki-0.0.1/evewiki/migrations/0002_page_is_public.py +21 -0
  12. evewiki-0.0.1/evewiki/migrations/__init__.py +0 -0
  13. evewiki-0.0.1/evewiki/models/__init__.py +0 -0
  14. evewiki-0.0.1/evewiki/models/logs.py +15 -0
  15. evewiki-0.0.1/evewiki/models/page_versions.py +48 -0
  16. evewiki-0.0.1/evewiki/models/pages.py +261 -0
  17. evewiki-0.0.1/evewiki/models/settings.py +35 -0
  18. evewiki-0.0.1/evewiki/static/css/easymde.min.css +7 -0
  19. evewiki-0.0.1/evewiki/static/css/evewiki.css +67 -0
  20. evewiki-0.0.1/evewiki/static/js/easymde.min.js +7 -0
  21. evewiki-0.0.1/evewiki/static/js/evewiki.js +201 -0
  22. evewiki-0.0.1/evewiki/tasks.py +12 -0
  23. evewiki-0.0.1/evewiki/templates/evewiki/base.html +11 -0
  24. evewiki-0.0.1/evewiki/templates/evewiki/error.html +13 -0
  25. evewiki-0.0.1/evewiki/templates/evewiki/help.html +16 -0
  26. evewiki-0.0.1/evewiki/templates/evewiki/index.html +185 -0
  27. evewiki-0.0.1/evewiki/templates/evewiki/page.html +100 -0
  28. evewiki-0.0.1/evewiki/templates/evewiki/page_delete.html +41 -0
  29. evewiki-0.0.1/evewiki/templates/evewiki/page_tree.html +21 -0
  30. evewiki-0.0.1/evewiki/templates/evewiki/public.html +80 -0
  31. evewiki-0.0.1/evewiki/templates/evewiki/sidebar.html +5 -0
  32. evewiki-0.0.1/evewiki/tests/__init__.py +0 -0
  33. evewiki-0.0.1/evewiki/tests/test_tasks.py +11 -0
  34. evewiki-0.0.1/evewiki/urls.py +17 -0
  35. evewiki-0.0.1/evewiki/views.py +184 -0
  36. evewiki-0.0.1/pyproject.toml +77 -0
evewiki-0.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ryan Cunning
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
evewiki-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,136 @@
1
+ Metadata-Version: 2.4
2
+ Name: evewiki
3
+ Version: 0.0.1
4
+ Summary: Wiki plugin app for Alliance Auth.
5
+ Author-email: Ryan Cunning <ryan.cunning@gmail.com>
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+ Classifier: Environment :: Web Environment
9
+ Classifier: Framework :: Django
10
+ Classifier: Framework :: Django :: 4.0
11
+ Classifier: Framework :: Django :: 4.2
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Topic :: Internet :: WWW/HTTP
21
+ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
22
+ License-File: LICENSE
23
+ Requires-Dist: allianceauth>=3
24
+ Project-URL: Changelog, https://gitlab.com/cunningdesigns/evewiki/-/blob/main/CHANGELOG.md
25
+ Project-URL: Documentation, https://gitlab.com/cunningdesigns/evewiki/-/tree/main/docs?ref_type=heads
26
+ Project-URL: Homepage, https://gitlab.com/cunningdesigns/evewiki
27
+ Project-URL: Source, https://gitlab.com/cunningdesigns/evewiki
28
+ Project-URL: Tracker, https://gitlab.com/cunningdesigns/evewiki/-/issues
29
+
30
+ # evewiki
31
+
32
+ Wiki plugin for [AllianceAuth](https://gitlab.com/allianceauth/allianceauth) to curate content.
33
+
34
+ [Documentation](https://gitlab.com/cunningdesigns/evewiki/-/tree/main/docs?ref_type=heads)
35
+
36
+ ## Features
37
+
38
+ - Collaborative editing for editors
39
+ - Create and organise pages in a hierarchical structure using `slugs`
40
+ - Supports markdown with both rich and raw editing modes
41
+ - Version History
42
+ - Event logging
43
+ - Restrict content by user's `groups` and/or `states`
44
+ - Publish public pages
45
+
46
+ ## Installation
47
+
48
+ ### Step 1 - Pre_Requisites
49
+
50
+ Evewiki is an App for Alliance Auth, Please make sure you have this installed. Evewiki is not a standalone Django Application
51
+
52
+ ### Step 2 - Install app
53
+
54
+ pip install evewiki
55
+
56
+ ### Step 3 - Configure Auth settings
57
+
58
+ Configure your Auth settings (`local.py`) as follows:
59
+
60
+ - Add `evewiki` to `INSTALLED_APPS` in `local.py`
61
+
62
+ ```python
63
+ INSTALLED_APPS += [
64
+ 'evewiki',
65
+ ...
66
+ ```
67
+
68
+ - Optional: Add `evewiki` to `APPS_WITH_PUBLIC_VIEWS` in `local.py`
69
+ To enable public pages
70
+ ```python
71
+ APPS_WITH_PUBLIC_VIEWS = [
72
+ 'evewiki',
73
+ ]
74
+ ```
75
+
76
+ ### Step 4 - Maintain Alliance Auth
77
+
78
+ - Run migrations `python manage.py migrate`
79
+ - Gather your staticfiles `python manage.py collectstatic`
80
+ - Restart Alliance Auth
81
+
82
+ Run migrations `python manage.py migrate`
83
+ Restart Alliance Auth
84
+
85
+ ### Step 5
86
+
87
+ In AA admin site add Permissions
88
+ - `evewiki | general | Can access this app`
89
+ - `evewiki | general | Can edit this app`
90
+ to the desired `States` / `Groups`
91
+
92
+ i.e. you may wish to create a `wiki_editors` group to restrict the `Can edit this app` controls.
93
+
94
+ ## Permissions
95
+
96
+ Users need to have at least `basic_access` interactions with the application
97
+
98
+ | Name | Description |
99
+ |-----------------------|----------------------------------------------------------|
100
+ | `basic_access` | Basic access to load content |
101
+ | `editor_access` | Grant the necessary controls and access to edit content |
102
+
103
+
104
+ ## Settings
105
+
106
+ List of settings that can be modified for the application
107
+ You can alter them by adding a record to the `Settings` section/table in the `evewiki` section of the Admin site
108
+
109
+ | Name | Description | Default |
110
+ |-------------------------------|--------------------------------------------------------------------------------------------------|---------|
111
+ | `hierarchy_max_display_depth` | Limit the depth of the tree for the hierarchy on the main display | 10 |
112
+ | `max_versions` | No one has infinite disk space, a sensible limit which can be modified to clear down the history | 1000 |
113
+
114
+ # Screenshots
115
+
116
+ **View Mode**
117
+
118
+ ![View Mode](https://i.imgur.com/gjt5Qw2.png)
119
+
120
+ **Edit Mode**
121
+
122
+ ![Edit Mode](https://i.imgur.com/4yxQss7.png)
123
+
124
+ **Raw Mode**
125
+
126
+ ![Raw Mode](https://i.imgur.com/qr5Vepq.png)
127
+
128
+ **Public badge**
129
+
130
+ ![Public](https://i.imgur.com/MH1YwfT.png)
131
+
132
+ **Page Details**
133
+
134
+ ![Page Details](https://i.imgur.com/0AznIH0.png)
135
+
136
+
@@ -0,0 +1,106 @@
1
+ # evewiki
2
+
3
+ Wiki plugin for [AllianceAuth](https://gitlab.com/allianceauth/allianceauth) to curate content.
4
+
5
+ [Documentation](https://gitlab.com/cunningdesigns/evewiki/-/tree/main/docs?ref_type=heads)
6
+
7
+ ## Features
8
+
9
+ - Collaborative editing for editors
10
+ - Create and organise pages in a hierarchical structure using `slugs`
11
+ - Supports markdown with both rich and raw editing modes
12
+ - Version History
13
+ - Event logging
14
+ - Restrict content by user's `groups` and/or `states`
15
+ - Publish public pages
16
+
17
+ ## Installation
18
+
19
+ ### Step 1 - Pre_Requisites
20
+
21
+ Evewiki is an App for Alliance Auth, Please make sure you have this installed. Evewiki is not a standalone Django Application
22
+
23
+ ### Step 2 - Install app
24
+
25
+ pip install evewiki
26
+
27
+ ### Step 3 - Configure Auth settings
28
+
29
+ Configure your Auth settings (`local.py`) as follows:
30
+
31
+ - Add `evewiki` to `INSTALLED_APPS` in `local.py`
32
+
33
+ ```python
34
+ INSTALLED_APPS += [
35
+ 'evewiki',
36
+ ...
37
+ ```
38
+
39
+ - Optional: Add `evewiki` to `APPS_WITH_PUBLIC_VIEWS` in `local.py`
40
+ To enable public pages
41
+ ```python
42
+ APPS_WITH_PUBLIC_VIEWS = [
43
+ 'evewiki',
44
+ ]
45
+ ```
46
+
47
+ ### Step 4 - Maintain Alliance Auth
48
+
49
+ - Run migrations `python manage.py migrate`
50
+ - Gather your staticfiles `python manage.py collectstatic`
51
+ - Restart Alliance Auth
52
+
53
+ Run migrations `python manage.py migrate`
54
+ Restart Alliance Auth
55
+
56
+ ### Step 5
57
+
58
+ In AA admin site add Permissions
59
+ - `evewiki | general | Can access this app`
60
+ - `evewiki | general | Can edit this app`
61
+ to the desired `States` / `Groups`
62
+
63
+ i.e. you may wish to create a `wiki_editors` group to restrict the `Can edit this app` controls.
64
+
65
+ ## Permissions
66
+
67
+ Users need to have at least `basic_access` interactions with the application
68
+
69
+ | Name | Description |
70
+ |-----------------------|----------------------------------------------------------|
71
+ | `basic_access` | Basic access to load content |
72
+ | `editor_access` | Grant the necessary controls and access to edit content |
73
+
74
+
75
+ ## Settings
76
+
77
+ List of settings that can be modified for the application
78
+ You can alter them by adding a record to the `Settings` section/table in the `evewiki` section of the Admin site
79
+
80
+ | Name | Description | Default |
81
+ |-------------------------------|--------------------------------------------------------------------------------------------------|---------|
82
+ | `hierarchy_max_display_depth` | Limit the depth of the tree for the hierarchy on the main display | 10 |
83
+ | `max_versions` | No one has infinite disk space, a sensible limit which can be modified to clear down the history | 1000 |
84
+
85
+ # Screenshots
86
+
87
+ **View Mode**
88
+
89
+ ![View Mode](https://i.imgur.com/gjt5Qw2.png)
90
+
91
+ **Edit Mode**
92
+
93
+ ![Edit Mode](https://i.imgur.com/4yxQss7.png)
94
+
95
+ **Raw Mode**
96
+
97
+ ![Raw Mode](https://i.imgur.com/qr5Vepq.png)
98
+
99
+ **Public badge**
100
+
101
+ ![Public](https://i.imgur.com/MH1YwfT.png)
102
+
103
+ **Page Details**
104
+
105
+ ![Page Details](https://i.imgur.com/0AznIH0.png)
106
+
@@ -0,0 +1,6 @@
1
+ """Wiki plugin app for Alliance Auth."""
2
+
3
+ # pylint: disable = invalid-name
4
+ default_app_config = "evewiki.apps.EveWikiConfig"
5
+
6
+ __version__ = "0.0.1"
@@ -0,0 +1,16 @@
1
+ """Admin site."""
2
+
3
+ from django.contrib import admin
4
+
5
+ from .models.logs import Log
6
+ from .models.page_versions import PageVersion
7
+ from .models.pages import Page
8
+ from .models.settings import Setting
9
+
10
+ # from django.contrib import admin
11
+
12
+ # Register your models for the admin site here.
13
+ admin.site.register(Page)
14
+ admin.site.register(Setting)
15
+ admin.site.register(PageVersion)
16
+ admin.site.register(Log)
@@ -0,0 +1,5 @@
1
+ """App settings."""
2
+
3
+ from django.conf import settings
4
+
5
+ EXAMPLE_SETTING_ONE = getattr(settings, "EXAMPLE_SETTING_ONE", None)
@@ -0,0 +1,9 @@
1
+ from django.apps import AppConfig
2
+
3
+ from . import __version__
4
+
5
+
6
+ class EveWikiConfig(AppConfig):
7
+ name = "evewiki"
8
+ label = "evewiki"
9
+ verbose_name = f"evewiki v{__version__}"
@@ -0,0 +1,40 @@
1
+ from django.utils.translation import gettext_lazy as _
2
+
3
+ from allianceauth import hooks
4
+ from allianceauth.services.hooks import MenuItemHook, UrlHook
5
+
6
+ from evewiki import urls
7
+
8
+
9
+ class EveWikiMenuItem(MenuItemHook):
10
+ """This class ensures only authorized users will see the menu entry"""
11
+
12
+ def __init__(self):
13
+ # setup menu entry for sidebar
14
+ MenuItemHook.__init__(
15
+ self,
16
+ _("Wiki"),
17
+ "fas fa-tree fa-fw",
18
+ "evewiki:index",
19
+ navactive=["evewiki:"],
20
+ )
21
+
22
+ def render(self, request):
23
+ if request.user.has_perm("evewiki.basic_access"):
24
+ return MenuItemHook.render(self, request)
25
+ return ""
26
+
27
+
28
+ @hooks.register("menu_item_hook")
29
+ def register_menu():
30
+ return EveWikiMenuItem()
31
+
32
+
33
+ @hooks.register("url_hook")
34
+ def register_urls():
35
+ return UrlHook(
36
+ urls,
37
+ "evewiki",
38
+ r"^evewiki/",
39
+ excluded_views=["evewiki.views.public"],
40
+ )
@@ -0,0 +1,51 @@
1
+ from django import forms
2
+
3
+ from .models.pages import Page
4
+
5
+
6
+ class PageForm(forms.ModelForm):
7
+
8
+ try:
9
+ # Customised ddl inferring additional context via text-indentation
10
+ parent = forms.ChoiceField(
11
+ choices=Page.list(),
12
+ required=False,
13
+ label="Path",
14
+ help_text=Page._meta.get_field("parent").help_text,
15
+ )
16
+
17
+ class Meta:
18
+ model = Page
19
+ fields = [
20
+ "title",
21
+ "parent",
22
+ "slug",
23
+ "priority",
24
+ "states",
25
+ "groups",
26
+ "is_public",
27
+ ]
28
+
29
+ def __init__(self, *args, **kwargs):
30
+ super().__init__(*args, **kwargs)
31
+ self.fields["parent"].choices = Page.list()
32
+
33
+ for name, field in self.fields.items():
34
+ if name == "is_public":
35
+ continue
36
+ existing_classes = field.widget.attrs.get("class", "")
37
+ field.widget.attrs["class"] = f"{existing_classes} form-control w-auto"
38
+
39
+ def clean(self):
40
+ """
41
+ Django needs a little help to turn the custom `parent` field back into a model.
42
+ """
43
+ cleaned_data = super().clean()
44
+ parent_id = cleaned_data["parent"]
45
+ cleaned_data["parent"] = (
46
+ Page.objects.get(pk=int(parent_id)) if parent_id else None
47
+ )
48
+ return cleaned_data
49
+
50
+ except Exception as e:
51
+ print(f"setup required: {e}")
@@ -0,0 +1,190 @@
1
+ # Generated by Django 4.2.21 on 2025-05-27 00:35
2
+
3
+ import django.db.models.deletion
4
+ from django.db import migrations, models
5
+
6
+
7
+ class Migration(migrations.Migration):
8
+
9
+ initial = True
10
+
11
+ dependencies = [
12
+ ("auth", "0012_alter_user_first_name_max_length"),
13
+ ("authentication", "0024_alter_userprofile_language"),
14
+ ]
15
+
16
+ operations = [
17
+ migrations.CreateModel(
18
+ name="General",
19
+ fields=[
20
+ (
21
+ "id",
22
+ models.AutoField(
23
+ auto_created=True,
24
+ primary_key=True,
25
+ serialize=False,
26
+ verbose_name="ID",
27
+ ),
28
+ ),
29
+ ],
30
+ options={
31
+ "permissions": (
32
+ ("basic_access", "Can access this app"),
33
+ ("editor_access", "Can edit this app"),
34
+ ),
35
+ "managed": False,
36
+ "default_permissions": (),
37
+ },
38
+ ),
39
+ migrations.CreateModel(
40
+ name="Log",
41
+ fields=[
42
+ (
43
+ "id",
44
+ models.AutoField(
45
+ auto_created=True,
46
+ primary_key=True,
47
+ serialize=False,
48
+ verbose_name="ID",
49
+ ),
50
+ ),
51
+ ("user", models.TextField(blank=True, default="", null=True)),
52
+ ("action", models.TextField(blank=True, default="", null=True)),
53
+ ("details", models.TextField(blank=True, default="", null=True)),
54
+ ("created", models.DateTimeField(auto_now_add=True)),
55
+ ],
56
+ ),
57
+ migrations.CreateModel(
58
+ name="Page",
59
+ fields=[
60
+ (
61
+ "id",
62
+ models.AutoField(
63
+ auto_created=True,
64
+ primary_key=True,
65
+ serialize=False,
66
+ verbose_name="ID",
67
+ ),
68
+ ),
69
+ (
70
+ "title",
71
+ models.CharField(
72
+ help_text="Required: Displayed above content and in menu",
73
+ max_length=255,
74
+ ),
75
+ ),
76
+ (
77
+ "slug",
78
+ models.CharField(
79
+ help_text="Required: Indentifier for path and links",
80
+ max_length=255,
81
+ ),
82
+ ),
83
+ (
84
+ "priority",
85
+ models.IntegerField(
86
+ default=10,
87
+ help_text="Required: Sort order for pages on the same path",
88
+ ),
89
+ ),
90
+ ("content", models.TextField(blank=True, default="", null=True)),
91
+ (
92
+ "groups",
93
+ models.ManyToManyField(
94
+ blank=True,
95
+ default=None,
96
+ help_text="Optional: Restrict Page to specific Groups",
97
+ related_name="+",
98
+ to="auth.group",
99
+ verbose_name="groups",
100
+ ),
101
+ ),
102
+ (
103
+ "parent",
104
+ models.ForeignKey(
105
+ blank=True,
106
+ help_text="Required: Oragnise page hierarchy",
107
+ null=True,
108
+ on_delete=django.db.models.deletion.PROTECT,
109
+ related_name="children",
110
+ to="evewiki.page",
111
+ ),
112
+ ),
113
+ (
114
+ "states",
115
+ models.ManyToManyField(
116
+ blank=True,
117
+ default=None,
118
+ help_text="Optional: Restrict Page to specific States",
119
+ related_name="+",
120
+ to="authentication.state",
121
+ verbose_name="states",
122
+ ),
123
+ ),
124
+ ],
125
+ ),
126
+ migrations.CreateModel(
127
+ name="Setting",
128
+ fields=[
129
+ (
130
+ "id",
131
+ models.AutoField(
132
+ auto_created=True,
133
+ primary_key=True,
134
+ serialize=False,
135
+ verbose_name="ID",
136
+ ),
137
+ ),
138
+ (
139
+ "hierarchy_max_display_depth",
140
+ models.IntegerField(
141
+ default=10,
142
+ help_text="Limit the depth of the tree for the hierarchy on the main display",
143
+ ),
144
+ ),
145
+ (
146
+ "max_versions",
147
+ models.IntegerField(
148
+ default=1000,
149
+ help_text="No one has infinite disk space, a sensible limit which can be modified to clear down the history",
150
+ ),
151
+ ),
152
+ ],
153
+ ),
154
+ migrations.CreateModel(
155
+ name="PageVersion",
156
+ fields=[
157
+ (
158
+ "id",
159
+ models.AutoField(
160
+ auto_created=True,
161
+ primary_key=True,
162
+ serialize=False,
163
+ verbose_name="ID",
164
+ ),
165
+ ),
166
+ ("content", models.TextField(blank=True, default="", null=True)),
167
+ ("created", models.DateTimeField(auto_now_add=True)),
168
+ (
169
+ "page",
170
+ models.ForeignKey(
171
+ blank=True,
172
+ help_text="Page being edited",
173
+ null=True,
174
+ on_delete=django.db.models.deletion.SET_NULL,
175
+ to="evewiki.page",
176
+ ),
177
+ ),
178
+ (
179
+ "user",
180
+ models.ForeignKey(
181
+ blank=True,
182
+ help_text="User editing the page",
183
+ null=True,
184
+ on_delete=django.db.models.deletion.SET_NULL,
185
+ to="authentication.userprofile",
186
+ ),
187
+ ),
188
+ ],
189
+ ),
190
+ ]
@@ -0,0 +1,21 @@
1
+ # Generated by Django 4.2.21 on 2025-05-29 21:23
2
+
3
+ from django.db import migrations, models
4
+
5
+
6
+ class Migration(migrations.Migration):
7
+
8
+ dependencies = [
9
+ ("evewiki", "0001_initial"),
10
+ ]
11
+
12
+ operations = [
13
+ migrations.AddField(
14
+ model_name="page",
15
+ name="is_public",
16
+ field=models.BooleanField(
17
+ default=False,
18
+ help_text="Optional: Make page publicly accessible via it's [path]/[slug]",
19
+ ),
20
+ ),
21
+ ]
File without changes
File without changes
@@ -0,0 +1,15 @@
1
+ from django.db import models
2
+
3
+
4
+ class Log(models.Model):
5
+ """
6
+ No relationships just a log.
7
+ """
8
+
9
+ user = models.TextField(default="", blank=True, null=True)
10
+
11
+ action = models.TextField(default="", blank=True, null=True)
12
+
13
+ details = models.TextField(default="", blank=True, null=True)
14
+
15
+ created = models.DateTimeField(auto_now_add=True)
@@ -0,0 +1,48 @@
1
+ from django.db import models
2
+
3
+ from allianceauth.authentication.models import UserProfile
4
+
5
+ from .pages import Page
6
+ from .settings import Setting
7
+
8
+
9
+ class PageVersion(models.Model):
10
+ """
11
+ Previous edits have value
12
+ """
13
+
14
+ page = models.ForeignKey(
15
+ Page,
16
+ on_delete=models.SET_NULL,
17
+ null=True,
18
+ blank=True,
19
+ help_text="Page being edited",
20
+ )
21
+
22
+ user = models.ForeignKey(
23
+ UserProfile,
24
+ on_delete=models.SET_NULL,
25
+ null=True,
26
+ blank=True,
27
+ help_text="User editing the page",
28
+ )
29
+
30
+ content = models.TextField(default="", blank=True, null=True)
31
+
32
+ created = models.DateTimeField(auto_now_add=True)
33
+
34
+ def save(self, *args, **kwargs):
35
+ """
36
+ Clean up old versions when saving
37
+ """
38
+ super().save(*args, **kwargs)
39
+ if self.page_id:
40
+ # Get the IDs of old versions to delete
41
+ settings = Setting.get_settings()
42
+ old_version_ids = list(
43
+ PageVersion.objects.filter(page=self.page)
44
+ .order_by("-created")
45
+ .values_list("id", flat=True)[settings.max_versions :]
46
+ )
47
+ if old_version_ids:
48
+ PageVersion.objects.filter(id__in=old_version_ids).delete()