-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update account templates and base template
- Loading branch information
1 parent
ca8c3ac
commit 33e0827
Showing
4 changed files
with
58 additions
and
30 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 |
---|---|---|
@@ -1,6 +1,28 @@ | ||
from typing import Any | ||
|
||
from django.conf import settings | ||
from django.contrib.auth import get_user_model | ||
from django.views.generic import TemplateView | ||
|
||
|
||
class BaseAccountView(TemplateView): | ||
class BaseTemplateView(TemplateView): | ||
user_model = get_user_model() | ||
title: str = "" | ||
|
||
def _get_checked_property(self, property_name: str, default_value: str) -> Any: | ||
is_production: bool = settings.ENVIRONMENT == "development" | ||
|
||
if not hasattr(self, property_name) and not is_production: | ||
raise AttributeError(f"Property '{property_name}' is missing in '{self.__class__.__name__}'.") | ||
|
||
if not (property_value := getattr(self, property_name)) and not is_production: | ||
raise ValueError(f"Property '{property_name}' in '{self.__class__.__name__}' is empty.") | ||
|
||
return property_value or default_value | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super().get_context_data(**kwargs) | ||
|
||
context["title"] = self._get_checked_property("title", "redirectioneaza.ro") | ||
|
||
return context |
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