Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions docs/developer/django-rest-framework-utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -323,18 +323,14 @@ Usage example:


class FloorPlanOrganizationFilter(FilterDjangoByOrgManaged):
organization_slug = filters.CharFilter(
field_name="organization__slug"
)
organization_slug = filters.CharFilter(field_name="organization__slug")

class Meta:
model = FloorPlan
fields = ["organization", "organization_slug"]


class FloorPlanListCreateView(
ProtectedAPIMixin, generics.ListCreateAPIView
):
class FloorPlanListCreateView(ProtectedAPIMixin, generics.ListCreateAPIView):
serializer_class = FloorPlanSerializer
queryset = FloorPlan.objects.select_related().order_by("-created")
pagination_class = ListViewPagination
Expand All @@ -360,9 +356,7 @@ Usage example:
model = FloorPlan


class FloorPlanListCreateView(
ProtectedAPIMixin, generics.ListCreateAPIView
):
class FloorPlanListCreateView(ProtectedAPIMixin, generics.ListCreateAPIView):
serializer_class = FloorPlanSerializer
queryset = FloorPlan.objects.select_related().order_by("-created")
pagination_class = ListViewPagination
Expand Down
4 changes: 1 addition & 3 deletions docs/developer/extending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,7 @@ Once you have created the models, add the following to your
# but users are free to implement it in their projects if needed
# for more information refer to the django-organizations docs:
# https://django-organizations.readthedocs.io/
OPENWISP_USERS_ORGANIZATIONINVITATION_MODEL = (
"myusers.OrganizationInvitation"
)
OPENWISP_USERS_ORGANIZATIONINVITATION_MODEL = "myusers.OrganizationInvitation"

Substitute ``myusers`` with the name you chose in step 1.

Expand Down
8 changes: 4 additions & 4 deletions openwisp_users/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
VERSION = (1, 2, 0, 'alpha')
VERSION = (1, 2, 0, "alpha")
__version__ = VERSION # alias


def get_version():
version = '%s.%s.%s' % (VERSION[0], VERSION[1], VERSION[2])
if VERSION[3] != 'final':
version = "%s.%s.%s" % (VERSION[0], VERSION[1], VERSION[2])
if VERSION[3] != "final":
first_letter = VERSION[3][0:1]
try:
suffix = VERSION[4]
except IndexError:
suffix = 0
version = '%s%s%s' % (version, first_letter, suffix)
version = "%s%s%s" % (version, first_letter, suffix)
return version
18 changes: 9 additions & 9 deletions openwisp_users/accounts/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ def send_mail(self, template_prefix, email, context):
subject = self.format_email_subject(subject)
content = {}
errors = {}
for ext in ['html', 'txt']:
template_name = '{0}_message.{1}'.format(template_prefix, ext)
if 'activate_url' in context:
context['call_to_action_url'] = context['activate_url']
context['call_to_action_text'] = _('Confirm')
for ext in ["html", "txt"]:
template_name = "{0}_message.{1}".format(template_prefix, ext)
if "activate_url" in context:
context["call_to_action_url"] = context["activate_url"]
context["call_to_action_text"] = _("Confirm")
try:
template_name = '{0}_message.{1}'.format(template_prefix, ext)
template_name = "{0}_message.{1}".format(template_prefix, ext)
content[ext] = render_to_string(
template_name, context, self.request
).strip()
except TemplateDoesNotExist as e:
errors[ext] = e
text = content.get('txt', '')
html = content.get('html', '')
text = content.get("txt", "")
html = content.get("html", "")
# both templates fail to load, raise the exception
if len(errors.keys()) >= 2:
raise errors['txt'] from errors['html']
raise errors["txt"] from errors["html"]
send_email(subject, text, html, [email], context)
56 changes: 28 additions & 28 deletions openwisp_users/accounts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,73 +16,73 @@

from .views import password_change, password_change_success

redirect_view = RedirectView.as_view(url=reverse_lazy('admin:index'))
redirect_view = RedirectView.as_view(url=reverse_lazy("admin:index"))


urlpatterns = [
path('signup/', redirect_view, name='account_signup'),
path('login/', views.login, name='account_login'),
path('logout/', views.logout, name='account_logout'),
path('inactive/', views.account_inactive, name='account_inactive'),
path("signup/", redirect_view, name="account_signup"),
path("login/", views.login, name="account_login"),
path("logout/", views.logout, name="account_logout"),
path("inactive/", views.account_inactive, name="account_inactive"),
# E-mail
path(
'confirm-email/',
"confirm-email/",
views.email_verification_sent,
name='account_email_verification_sent',
name="account_email_verification_sent",
),
re_path(
r'^confirm-email/(?P<key>[-:\w]+)/$',
r"^confirm-email/(?P<key>[-:\w]+)/$",
views.confirm_email,
name='account_confirm_email',
name="account_confirm_email",
),
# password change
path(
'password/change/',
"password/change/",
password_change,
name="account_change_password",
),
path(
'password/change/success/',
"password/change/success/",
password_change_success,
name='account_change_password_success',
name="account_change_password_success",
),
# password reset
path('password/reset/', views.password_reset, name='account_reset_password'),
path("password/reset/", views.password_reset, name="account_reset_password"),
path(
'password/reset/done/',
"password/reset/done/",
views.password_reset_done,
name='account_reset_password_done',
name="account_reset_password_done",
),
re_path(
r'^password/reset/key/(?P<uidb36>[0-9A-Za-z]+)-(?P<key>.+)/$',
r"^password/reset/key/(?P<uidb36>[0-9A-Za-z]+)-(?P<key>.+)/$",
views.password_reset_from_key,
name='account_reset_password_from_key',
name="account_reset_password_from_key",
),
path(
'password/reset/key/done/',
"password/reset/key/done/",
views.password_reset_from_key_done,
name='account_reset_password_from_key_done',
name="account_reset_password_from_key_done",
),
path(
'email-verification-success/',
TemplateView.as_view(template_name='account/email_verification_success.html'),
name='email_confirmation_success',
"email-verification-success/",
TemplateView.as_view(template_name="account/email_verification_success.html"),
name="email_confirmation_success",
),
path(
'logout-success/',
TemplateView.as_view(template_name='account/logout_success.html'),
name='logout_success',
"logout-success/",
TemplateView.as_view(template_name="account/logout_success.html"),
name="logout_success",
),
]

if app_settings.SOCIALACCOUNT_ENABLED:
urlpatterns += [path('social/', include('allauth.socialaccount.urls'))]
urlpatterns += [path("social/", include("allauth.socialaccount.urls"))]

for provider in providers.registry.get_class_list():
try:
prov_mod = import_module(provider.get_package() + '.urls')
prov_mod = import_module(provider.get_package() + ".urls")
except ImportError:
continue
prov_urlpatterns = getattr(prov_mod, 'urlpatterns', None)
prov_urlpatterns = getattr(prov_mod, "urlpatterns", None)
if prov_urlpatterns:
urlpatterns += prov_urlpatterns
10 changes: 5 additions & 5 deletions openwisp_users/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class ChangePasswordForm(BaseChangePasswordForm):

class PasswordChangeView(BasePasswordChangeView):
form_class = ChangePasswordForm
template_name = 'account/password_change.html'
success_url = reverse_lazy('account_change_password_success')
template_name = "account/password_change.html"
success_url = reverse_lazy("account_change_password_success")

def get_success_url(self):
if self.request.POST.get(REDIRECT_FIELD_NAME):
Expand All @@ -25,17 +25,17 @@ def get_success_url(self):

def get_initial(self):
data = super().get_initial()
data['next'] = self.request.GET.get(REDIRECT_FIELD_NAME)
data["next"] = self.request.GET.get(REDIRECT_FIELD_NAME)
return data

@sensitive_post_parameters_m
def dispatch(self, request, *args, **kwargs):
if not self.request.user.has_usable_password():
return render(self.request, 'account/password_not_required.html')
return render(self.request, "account/password_not_required.html")
return super().dispatch(request, *args, **kwargs)


password_change = login_required(PasswordChangeView.as_view())
password_change_success = login_required(
TemplateView.as_view(template_name='account/password_change_success.html')
TemplateView.as_view(template_name="account/password_change_success.html")
)
Loading
Loading