Skip to content

Commit

Permalink
Merge branch 'develop' into feature/add-moment
Browse files Browse the repository at this point in the history
  • Loading branch information
VolodiaKhl committed Jan 11, 2019
2 parents 8ffea58 + d7717b4 commit c7e9f4a
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 64 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

Always reference the ticket number at the end of the issue description.

## Pending

### Fixed

- Do not logout logged-in users which visit the login view, but redirect them to home

## 1.3.5 (2018-12-21)

### Fixed

- Confirmation dialog title shows object name instead of object representation [#324][324]

### Changed

- Added wrapper classes to the different blocks in the templates, this improves
javascript manipulation of pages [#322][322]
- Added ability to select custom class on action links

[324]: //github.com/sanoma/django-arctic/issues/324
[322]: //github.com/sanoma/django-arctic/issues/322


## 1.3.4 (2018-11-06)

### Fixed
Expand Down
17 changes: 16 additions & 1 deletion arctic/generics.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def get_context_data(self, **kwargs):
context["SITE_NAME"] = self.get_site_name()
context["SITE_TITLE"] = self.get_site_title()
context["SITE_LOGO"] = self.get_site_logo()
context["SITE_FAVICON"] = self.get_site_favicon()
context["SIDEBAR_BACKGROUND"] = self.get_sidebar_background()
context["SIDEBAR_COLOR"] = self.get_sidebar_color()
context["SIDEBAR_ALT_COLOR"] = self.get_sidebar_alt_color()
Expand Down Expand Up @@ -181,6 +182,9 @@ def get_page_description(self):
def get_site_logo(self):
return arctic_setting("ARCTIC_SITE_LOGO")

def get_site_favicon(self):
return getattr(settings, "ARCTIC_SITE_FAVICON", None)

def get_site_name(self):
return arctic_setting("ARCTIC_SITE_NAME")

Expand Down Expand Up @@ -906,7 +910,12 @@ def get_context_data(self, **kwargs):
return context

def get(self, request, *args, **kwargs):
logout(request)
# If the logout url is the login url, log the user out of the system
if settings.LOGOUT_URL == settings.LOGIN_URL:
logout(request)
# Else redirect a logged in user to the homepage
elif request.user.is_authenticated:
return redirect("/")
return super(LoginView, self).get(request, *args, **kwargs)

def post(self, request, *args, **kwargs):
Expand All @@ -928,3 +937,9 @@ def post(self, request, *args, **kwargs):
return render(
request, self.template_name, self.get_context_data(**kwargs)
)


class LogoutView(View):
def dispatch(self, request, *args, **kwargs):
logout(request)
return redirect(settings.LOGIN_URL)
6 changes: 5 additions & 1 deletion arctic/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ def _get_field_actions(self, obj):
{
"label": field_action["label"],
"icon": field_action["icon"],
"class": field_action['class'],
"url": self.in_modal(
reverse_url(
field_action["url"], obj, self.primary_key
Expand Down Expand Up @@ -713,14 +714,17 @@ def get_action_links(self):

def _build_action_link(self, action_link):
icon, attributes = None, None
attributes_class = generate_id('action', action_link[0])
if len(action_link) == 3:
# icon can be 3-rd arg of link or specified inside inside dict with same index
if isinstance(action_link[2], str):
icon = action_link[2]
elif isinstance(action_link[2], dict):
icon = action_link[2].get('icon_class', None)
attributes = action_link[2].get('attributes', None)
return {"label": action_link[0], "url": action_link[1],
if attributes and attributes.get('class', None) and isinstance(attributes.get('class', None), list):
attributes_class = " ".join(attributes.get('class'))
return {"label": action_link[0], "url": action_link[1], 'class': attributes_class,
"icon": icon, "attributes": attributes}

def get_tool_links(self):
Expand Down
3 changes: 2 additions & 1 deletion arctic/project_template/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@

STATIC_URL = "/static/"

LOGIN_URL = LOGOUT_URL = "login"
LOGIN_URL = "login"
LOGOUT_URL = "logout"

# Arctic configuration
ARCTIC_SITE_NAME = "{{ project_name }}'s Arctic website"
Expand Down
123 changes: 67 additions & 56 deletions arctic/templates/arctic/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,71 +43,82 @@ <h3 class="header__title">
</header>
{% endblock %}
<div class="content-wrapper">
{% block breadcrumbs%}
{% if breadcrumbs %}
<nav class="breadcrumb">
{% for breadcrumb in breadcrumbs %}
{% if forloop.last %}
<span class="breadcrumb-item active">
{{ breadcrumb.name }}
</span>
{% else %}
<a class="breadcrumb-item" href="{{ breadcrumb.url }}">
{{ breadcrumb.name }}
</a>
{% endif %}
{% endfor %}
</nav>
{% else %}
&nbsp;
{% endif %}
{% endblock %}
<div class="breadcrumb-block">
{% block breadcrumbs%}
{% if breadcrumbs %}
<nav class="breadcrumb">
{% for breadcrumb in breadcrumbs %}
{% if forloop.last %}
<span class="breadcrumb-item active">
{{ breadcrumb.name }}
</span>
{% else %}
<a class="breadcrumb-item" href="{{ breadcrumb.url }}">
{{ breadcrumb.name }}
</a>
{% endif %}
{% endfor %}
</nav>
{% else %}
&nbsp;
{% endif %}
{% endblock %}
</div>

{# page page description #}
{% if page_description %}
<div class="row">
<small>{{ page_description }}</small>
<div class="page-description-block">
{% block page_description %}
{% if page_description %}
<div class="row">
<small>{{ page_description }}</small>
</div>
{% endif %}
{% endblock %}
</div>
{% endif %}

{% block tabs %}
{% if tabs %}
<div class="row">
<div class="col-sm-12 col">
<ul class="nav nav-tabs" id="table-tabs" role="tablist">
{% for tab in tabs %}
<li class="nav-item">
{% if tab.active %}
<a class="nav-link active" href="javascript:">{{ tab.name }}</a></li>
{% else %}
<a class="nav-link" href="{{ tab.url }}">{{ tab.name }}</a></li>
{% endif %}
</li>
{% endfor %}
</ul>
<div class="tabs-block">
{% block tabs %}
{% if tabs %}
<div class="row">
<div class="col-sm-12 col">
<ul class="nav nav-tabs" id="table-tabs" role="tablist">
{% for tab in tabs %}
<li class="nav-item">
{% if tab.active %}
<a class="nav-link active" href="javascript:">{{ tab.name }}</a></li>
{% else %}
<a class="nav-link" href="{{ tab.url }}">{{ tab.name }}</a></li>
{% endif %}
</li>
{% endfor %}
</ul>
</div>
</div>
{% endif %}
{% endblock %}
</div>
{% endif %}
{% endblock %}

{% block messages %}
{% if messages %}
{% for message in messages %}
<div class="row">
<div class="col">
<div class="alert alert-{{ message.tags }}" data-closable>
{{ message }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<div class="messages-block">
{% block messages %}
{% if messages %}
{% for message in messages %}
<div class="row">
<div class="col">
<div class="alert alert-{{ message.tags }}" data-closable>
{{ message }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
</div>
</div>
{% endfor %}
{% endif %}
{% endblock %}
</div>

<div class="content-block">
{% block content %}content here{% endblock %}
</div>
{% endfor %}
{% endif %}
{% endblock %}

{% block content %}content here{% endblock %}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion arctic/templates/arctic/partials/base_data_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ <h4 class="arctic-card__title">
{% block list_actions %}
<div class="list-actions">
{% for action in row.actions %}
<a href="{{ action.url }}" class="action-{{ action.label }} btn btn-secondary btn-sm show-on-hover" title="{{ action.label|capfirst }}"
<a href="{{ action.url }}" class="{{ action.class }} btn btn-secondary btn-sm show-on-hover" title="{{ action.label|capfirst }}"
{% include 'arctic/partials/modal_attributes.html' with modal=action.modal %}
{% if action.attributes %}
{% for attr_name, attr_value in action.attributes.items %}
Expand Down
4 changes: 4 additions & 0 deletions arctic/templates/arctic/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<meta name="description" content="">
<meta name="author" content="">

{% if SITE_FAVICON %}
<link rel="shortcut icon" href="{% static SITE_FAVICON %}"/>
{% endif %}

<title>
{% block title %}
{{ SITE_TITLE }} – {{ page_title }}
Expand Down
12 changes: 10 additions & 2 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ if not provided, a default color will be used.
String representing the foreground color of the sidebar, for example '#ffffff',
if not provided, a default color will be used.

## `ARCTIC_SITE_FAVICON`
The url of favicon.

## `ARCTIC_SITE_LOGO`

The url of the logo to be displayed on every page, it will also be the link to
Expand Down Expand Up @@ -119,6 +122,10 @@ Being a pure Django settings, LOGIN_URL and LOGOUT_URL used in Arctic to display
login and logout links. Both items supposed to be names of URLs. Defaults are 'login'
and 'logout'. Could be set to `None` if you don't want to use authentication in your app.

If the LOGIN_URL and LOGOUT_URL are the same, the LoginView will automatically logout
the user when he visits the login page. If they are different, a logged in user will be
redirected to the homepage of the CMS and not be logged out.

# Generic Class Based Views

Arctic provides a number of class based views that add integration with the
Expand Down Expand Up @@ -317,8 +324,9 @@ optional list of `('name', 'base_url', 'optional icon class')` links, that
appear on the last column of the table and can apply a certain action, such
as delete.
In case if some custom attributes required, they can be specified as last argument in form of dict. In this case
optional icon class can be provided as part of that argument dict
`('name', 'base_url', 'optional icon class', {'icon_class': 'fa', 'attributes': {'custom_attr_name': 'custom_attr_value'}})`
optional icon class can be provided as part of that argument dict.
Classes for action link can be specified as a list.
`('name', 'base_url', 'optional icon class', {'icon_class': 'fa', 'attributes': {'class': ['class0', 'class1'], 'custom_attr_name': 'custom_attr_value'}})`

### `get_field_actions(row)`

Expand Down
3 changes: 2 additions & 1 deletion example/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@
MEDIA_ROOT = location("media")
MEDIA_URL = "/media/"

LOGIN_URL = LOGOUT_URL = "login"
LOGIN_URL = "login"
LOGOUT_URL = "logout"


try:
Expand Down
3 changes: 2 additions & 1 deletion example/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.conf.urls import include, url
from django.conf.urls.static import static

from arctic.generics import LoginView
from arctic.generics import LoginView, LogoutView
from arctic.views import handler400, handler403, handler404, handler500 # noqa

from countries.views import CountryAPIView, CountryListView
Expand All @@ -14,6 +14,7 @@
urlpatterns = [
url(r"^$", DashboardView.as_view(), name="index"),
url(r"^login/$", LoginView.as_view(), name="login"),
url(r"^logout/$", LogoutView.as_view(), name="logout"),
url(r"^articles/", include("articles.urls", "articles")),
url(r"^users/", include("arctic.users.urls", namespace="users")),
url(r"^countries/$", CountryListView.as_view(), name="countries-list"),
Expand Down

0 comments on commit c7e9f4a

Please sign in to comment.