-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for ResourceLink model and view.
Closes #441
- Loading branch information
1 parent
195edcd
commit 9f3cacf
Showing
8 changed files
with
128 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Generated by Django 4.1.13 on 2025-01-07 13:52 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("home", "0029_alter_generalpage_content_listblock"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="ResourceLink", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("created", models.DateTimeField(auto_now_add=True)), | ||
("updated", models.DateTimeField(auto_now=True)), | ||
("permanent", models.BooleanField(default=False)), | ||
( | ||
"path", | ||
models.TextField( | ||
help_text="The relative path for requests to the djangonaut.space web app.", | ||
unique=True, | ||
), | ||
), | ||
( | ||
"url", | ||
models.URLField( | ||
help_text="The final URL it directs to.", max_length=2000 | ||
), | ||
), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from .blog import * | ||
from .event import * | ||
from .resource import * | ||
from .session import * | ||
from .survey import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from django.db import models | ||
|
||
|
||
class ResourceLink(models.Model): | ||
created = models.DateTimeField(auto_now_add=True) | ||
updated = models.DateTimeField(auto_now=True) | ||
permanent = models.BooleanField(default=False) | ||
path = models.TextField( | ||
help_text="The relative path for requests to the djangonaut.space web app.", | ||
unique=True, | ||
) | ||
url = models.URLField(help_text="The final URL it directs to.", max_length=2000) | ||
|
||
def __str__(self): | ||
return self.path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
|
||
from home.factories import ResourceLinkFactory | ||
|
||
|
||
class ResourceLinkViewTests(TestCase): | ||
@classmethod | ||
def setUpTestData(cls): | ||
cls.resource_link = ResourceLinkFactory.create() | ||
cls.url = reverse("resource_link", kwargs={"path": cls.resource_link.path}) | ||
|
||
def test_get(self): | ||
response = self.client.get(self.url) | ||
self.assertRedirects( | ||
response, self.resource_link.url, fetch_redirect_response=False | ||
) | ||
|
||
def test_get_not_found(self): | ||
response = self.client.get( | ||
reverse("resource_link", kwargs={"path": "not-found"}) | ||
) | ||
self.assertEqual(response.status_code, 404) | ||
|
||
def test_post(self): | ||
response = self.client.post(self.url) | ||
self.assertRedirects( | ||
response, self.resource_link.url, fetch_redirect_response=False | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters