diff --git a/django_lostplaces/lostplaces/forms.py b/django_lostplaces/lostplaces/forms.py index 89a95ab..491bcd0 100644 --- a/django_lostplaces/lostplaces/forms.py +++ b/django_lostplaces/lostplaces/forms.py @@ -35,7 +35,19 @@ class SignupVoucherForm(UserCreationForm): fetched_voucher.delete() return True -class ProfileChangeForm(forms.ModelForm): +class ExplorerUserChangeForm(UserChangeForm): + class Meta: + model = User + fields = [ 'username', 'first_name', 'last_name', 'email' ] + password = None + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields['username'].required = False + self.fields['username'].help_text = None + self.fields['username'].widget.attrs['disabled'] = 'disabled' + +class ExplorerChangeForm(forms.ModelForm): class Meta: model = Explorer fields = '__all__' diff --git a/django_lostplaces/lostplaces/templates/explorer/profile_update.html b/django_lostplaces/lostplaces/templates/explorer/profile_update.html new file mode 100644 index 0000000..0da5ec8 --- /dev/null +++ b/django_lostplaces/lostplaces/templates/explorer/profile_update.html @@ -0,0 +1,55 @@ +{% extends 'global.html'%} +{% load static %} +{% load i18n %} +{% load widget_tweaks %} + +# {% block title %}{% trans 'Edit Explorer profile' %}{% endblock %} + +{% block maincontent %} + +
+
+ {% trans 'Edit Explorer profile' %} + {% csrf_token %} +
+
+ {% include 'partials/form/inputField.html' with field=explorer_user_change_form.username %} +
+
+ {% include 'partials/form/inputField.html' with field=explorer_user_change_form.email %} +
+
+
+
+ {% include 'partials/form/inputField.html' with field=explorer_user_change_form.first_name %} +
+
+ {% include 'partials/form/inputField.html' with field=explorer_user_change_form.last_name %} +
+
+ +
+
+ {% include 'partials/form/inputField.html' with field=explorer_change_form.bio %} +
+
+ +
+ {% if explorer_image_url %} +
+ +
+ {% endif %} +
+ {% include 'partials/form/inputField.html' with field=explorer_change_form.profile_image %} +
+
+ + {% trans 'Update' as action %} +
+ {% include 'partials/form/submit.html' with referrer=request.META.HTTP_REFERER action=action %} +
+
+
+ +{% endblock maincontent %} diff --git a/django_lostplaces/lostplaces/urls.py b/django_lostplaces/lostplaces/urls.py index 0e38282..bcfb646 100644 --- a/django_lostplaces/lostplaces/urls.py +++ b/django_lostplaces/lostplaces/urls.py @@ -18,7 +18,8 @@ from lostplaces.views import ( PlaceImageCreateView, PlaceImageDeleteView, FlatView, - ExplorerProfileView + ExplorerProfileView, + ExplorerProfileUpdateView ) urlpatterns = [ @@ -39,9 +40,8 @@ urlpatterns = [ path('place/tag/delete//', PlaceTagDeleteView.as_view(), name='place_tag_delete'), path('explorer//', ExplorerProfileView.as_view(), name='explorer_profile'), + path('explorer/update/', ExplorerProfileUpdateView.as_view(), name='explorer_profile_update'), path('explorer/favorite//', PlaceFavoriteView.as_view(), name='place_favorite'), path('explorer/unfavorite//', PlaceUnfavoriteView.as_view(), name='place_unfavorite') - - ] diff --git a/django_lostplaces/lostplaces/views/explorer_views.py b/django_lostplaces/lostplaces/views/explorer_views.py index 0197faa..9faf5b1 100644 --- a/django_lostplaces/lostplaces/views/explorer_views.py +++ b/django_lostplaces/lostplaces/views/explorer_views.py @@ -12,6 +12,7 @@ from lostplaces.common import get_all_subclasses from lostplaces.views.base_views import IsAuthenticatedMixin from lostplaces.models.models import Explorer from lostplaces.models.place import Place, PlaceAsset +from lostplaces.forms import ExplorerChangeForm, ExplorerUserChangeForm class ExplorerProfileView(IsAuthenticatedMixin, View): def get(self, request, explorer_id): @@ -39,3 +40,15 @@ class ExplorerProfileView(IsAuthenticatedMixin, View): template_name='explorer/profile.html', context=context ) + +class ExplorerProfileUpdateView(IsAuthenticatedMixin, View): + success_message = '' + permission_denied_message = '' + + def get(self, request, *args, **kwargs): + context = { + 'explorer_image_url': request.user.explorer.profile_image.url, + 'explorer_user_change_form': ExplorerUserChangeForm(instance=request.user), + 'explorer_change_form': ExplorerChangeForm(instance=request.user.explorer) + } + return render(request, 'explorer/profile_update.html', context)