Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ab8bd1e

Browse files
🧁 Replace url template tags with methods [skip ci]
1 parent b046507 commit ab8bd1e

File tree

5 files changed

+82
-17
lines changed

5 files changed

+82
-17
lines changed

‎src/blog/models.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,25 @@ def get_absolute_url(self):
6565
"slug": self.slug,
6666
},
6767
)
68+
69+
def get_update_url(self):
70+
"""Return URL to update page of Post"""
71+
return reverse(
72+
"post_update",
73+
kwargs={
74+
"year": self.pub_date.year,
75+
"month": self.pub_date.month,
76+
"slug": self.slug,
77+
},
78+
)
79+
80+
def get_delete_url(self):
81+
"""Return URL to delete page of Post"""
82+
return reverse(
83+
"post_delete",
84+
kwargs={
85+
"year": self.pub_date.year,
86+
"month": self.pub_date.month,
87+
"slug": self.slug,
88+
},
89+
)

‎src/organizer/models.py‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ def get_absolute_url(self):
5757
"tag_detail", kwargs={"slug": self.slug}
5858
)
5959

60+
def get_update_url(self):
61+
"""Return URL to update page of Tag"""
62+
return reverse(
63+
"tag_update", kwargs={"slug": self.slug}
64+
)
65+
66+
def get_delete_url(self):
67+
"""Return URL to delete page of Tag"""
68+
return reverse(
69+
"tag_delete", kwargs={"slug": self.slug}
70+
)
71+
6072

6173
class Startup(Model):
6274
"""Data about a Startup company"""
@@ -88,6 +100,25 @@ def get_absolute_url(self):
88100
"startup_detail", kwargs={"slug": self.slug}
89101
)
90102

103+
def get_update_url(self):
104+
"""Return URL to update page of Startup"""
105+
return reverse(
106+
"startup_update", kwargs={"slug": self.slug}
107+
)
108+
109+
def get_delete_url(self):
110+
"""Return URL to delete page of Startup"""
111+
return reverse(
112+
"startup_delete", kwargs={"slug": self.slug}
113+
)
114+
115+
def get_newslink_create_url(self):
116+
"""Return URL to detail page of Startup"""
117+
return reverse(
118+
"newslink_create",
119+
kwargs={"startup_slug": self.slug},
120+
)
121+
91122

92123
class NewsLink(Model):
93124
"""Link to external sources about a Startup"""
@@ -115,3 +146,23 @@ def get_absolute_url(self):
115146
"startup_detail",
116147
kwargs={"slug": self.startup.slug},
117148
)
149+
150+
def get_update_url(self):
151+
"""Return URL to update page of Startup"""
152+
return reverse(
153+
"newslink_update",
154+
kwargs={
155+
"startup_slug": self.startup.slug,
156+
"newslink_slug": self.slug,
157+
},
158+
)
159+
160+
def get_delete_url(self):
161+
"""Return URL to delete page of Startup"""
162+
return reverse(
163+
"newslink_delete",
164+
kwargs={
165+
"startup_slug": self.startup.slug,
166+
"newslink_slug": self.slug,
167+
},
168+
)

‎src/templates/post/detail.html‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ <h2>{{ post.title|title }}</h2>
1818
{{ post.text|linebreaks }}
1919
<ul>
2020
<li>
21-
{# Wouldn't a model method be nicer than the call below? #}
22-
<a href="{% url 'post_update' post.pub_date.year post.pub_date.month post.slug %}">
21+
<a href="{{ post.get_update_url }}">
2322
Update
2423
</a>
2524
</li>
2625
<li>
27-
{# Wouldn't a model method be nicer than the call below? #}
28-
<a href="{% url 'post_delete' post.pub_date.year post.pub_date.month post.slug %}">
26+
<a href="{{ post.get_delete_url }}">
2927
Delete
3028
</a>
3129
</li>

‎src/templates/startup/detail.html‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
<h2>{{ startup.name }}</h2>
99
<ul>
1010
<li>
11-
{# Wouldn't a model method be nicer than the call below? #}
12-
<a href="{% url 'startup_update' startup.slug %}">
11+
<a href="{{ startup.get_update_url }}">
1312
Update
1413
</a>
1514
</li>
1615
<li>
17-
{# Wouldn't a model method be nicer than the call below? #}
18-
<a href="{% url 'startup_delete' startup.slug %}">
16+
<a href="{{ startup.get_delete_url }}">
1917
Delete
2018
</a>
2119
</li>
@@ -39,19 +37,17 @@ <h2>{{ startup.name }}</h2>
3937
</dl>
4038
{{ startup.description|linebreaks }}
4139
<section>
42-
{# Wouldn't a model method be nicer than the call below? #}
43-
<p><a href="{% url 'newslink_create' startup.slug %}">
40+
<p><a href="{{ startup.get_newslink_create_url }}">
4441
Add link to article
4542
</a></p>
4643
<ul>
4744
{% for newslink in startup.newslink_set.all %}
4845
<li>
4946
<a href="{{ newslink.link }}">
5047
{{ newslink.title|title }}</a>
51-
{# Wouldn't model methods be nicer than the calls below? #}
52-
<a href="{% url 'newslink_update' startup.slug newslink.slug %}">
48+
<a href="{{ newslink.get_update_url }}">
5349
[Modify Link]</a>
54-
<a href="{% url 'newslink_delete' startup.slug newslink.slug %}">
50+
<a href="{{ newslink.get_delete_url }}">
5551
[Delete Link]</a>
5652
</li>
5753
{% endfor %}

‎src/templates/tag/detail.html‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
<h2>{{ tag.name|title }}</h2>
99
<ul>
1010
<li>
11-
{# Wouldn't a model method be nicer than the call below? #}
12-
<a href="{% url 'tag_update' tag.slug %}">
11+
<a href="{{ tag.get_update_url }}">
1312
Update
1413
</a>
1514
</li>
1615
<li>
17-
{# Wouldn't a model method be nicer than the call below? #}
18-
<a href="{% url 'tag_delete' tag.slug %}">
16+
<a href="{{ tag.get_delete_url }}">
1917
Delete
2018
</a>
2119
</li>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /