ExplorerChangeForms, with deactivated username field.
This commit is contained in:
		| @@ -35,7 +35,19 @@ class SignupVoucherForm(UserCreationForm): | |||||||
|         fetched_voucher.delete() |         fetched_voucher.delete() | ||||||
|         return True |         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: |     class Meta: | ||||||
|         model = Explorer |         model = Explorer | ||||||
|         fields = '__all__' |         fields = '__all__' | ||||||
|   | |||||||
| @@ -0,0 +1,55 @@ | |||||||
|  | {% extends 'global.html'%} | ||||||
|  | {% load static %} | ||||||
|  | {% load i18n %} | ||||||
|  | {% load widget_tweaks %} | ||||||
|  |  | ||||||
|  | # {% block title %}{% trans 'Edit Explorer profile' %}{% endblock %} | ||||||
|  |  | ||||||
|  | {% block maincontent %} | ||||||
|  |  | ||||||
|  | <form class="LP-Form" method="POST"> | ||||||
|  |     <fieldset class="LP-Form__Fieldset"> | ||||||
|  |         <legend class="LP-Form__Legend">{% trans 'Edit Explorer profile' %}</legend> | ||||||
|  |         {% csrf_token %} | ||||||
|  |         <div class="LP-Form__Composition LP-Form__Composition--breakable"> | ||||||
|  |             <div class="LP-Form__Field"> | ||||||
|  |                 {% include 'partials/form/inputField.html' with field=explorer_user_change_form.username %} | ||||||
|  |             </div> | ||||||
|  |             <div class="LP-Form__Field"> | ||||||
|  |                 {% include 'partials/form/inputField.html' with field=explorer_user_change_form.email %} | ||||||
|  |             </div> | ||||||
|  |         </div> | ||||||
|  |         <div class="LP-Form__Composition LP-Form__Composition--breakable"> | ||||||
|  |             <div class="LP-Form__Field"> | ||||||
|  |                 {% include 'partials/form/inputField.html' with field=explorer_user_change_form.first_name %} | ||||||
|  |             </div> | ||||||
|  |             <div class="LP-Form__Field"> | ||||||
|  |                 {% include 'partials/form/inputField.html' with field=explorer_user_change_form.last_name %} | ||||||
|  |             </div> | ||||||
|  |         </div> | ||||||
|  |  | ||||||
|  |         <div class="LP-Form__Composition"> | ||||||
|  |             <div class="LP-Form__Field"> | ||||||
|  |                 {% include 'partials/form/inputField.html' with field=explorer_change_form.bio %} | ||||||
|  |             </div> | ||||||
|  |         </div> | ||||||
|  |  | ||||||
|  |         <div class="LP-Form__Composition"> | ||||||
|  |             {% if explorer_image_url %} | ||||||
|  |             <div class="LP-Form__Field"> | ||||||
|  |                 <img class="LP-Form__Field LP-Image" src="{{ explorer_image_url }}"/> | ||||||
|  |             </div> | ||||||
|  |             {% endif %} | ||||||
|  |             <div class="LP-Form__Field"> | ||||||
|  |                 {% include 'partials/form/inputField.html' with field=explorer_change_form.profile_image %} | ||||||
|  |             </div> | ||||||
|  |         </div> | ||||||
|  |  | ||||||
|  |         {% trans 'Update' as action %} | ||||||
|  |         <div class="LP-Form__Composition LP-Form__Composition--buttons"> | ||||||
|  |             {% include 'partials/form/submit.html' with referrer=request.META.HTTP_REFERER action=action %} | ||||||
|  |         </div> | ||||||
|  |     </fieldset> | ||||||
|  | </form> | ||||||
|  |  | ||||||
|  | {% endblock maincontent %} | ||||||
| @@ -18,7 +18,8 @@ from lostplaces.views import ( | |||||||
|     PlaceImageCreateView, |     PlaceImageCreateView, | ||||||
|     PlaceImageDeleteView, |     PlaceImageDeleteView, | ||||||
|     FlatView, |     FlatView, | ||||||
|     ExplorerProfileView |     ExplorerProfileView, | ||||||
|  |     ExplorerProfileUpdateView | ||||||
| ) | ) | ||||||
|  |  | ||||||
| urlpatterns = [ | urlpatterns = [ | ||||||
| @@ -39,9 +40,8 @@ urlpatterns = [ | |||||||
|     path('place/tag/delete/<int:tagged_id>/<int:tag_id>', PlaceTagDeleteView.as_view(), name='place_tag_delete'), |     path('place/tag/delete/<int:tagged_id>/<int:tag_id>', PlaceTagDeleteView.as_view(), name='place_tag_delete'), | ||||||
|      |      | ||||||
|     path('explorer/<int:explorer_id>/', ExplorerProfileView.as_view(), name='explorer_profile'), |     path('explorer/<int:explorer_id>/', ExplorerProfileView.as_view(), name='explorer_profile'), | ||||||
|  |     path('explorer/update/', ExplorerProfileUpdateView.as_view(), name='explorer_profile_update'), | ||||||
|      |      | ||||||
|     path('explorer/favorite/<int:place_id>/', PlaceFavoriteView.as_view(), name='place_favorite'), |     path('explorer/favorite/<int:place_id>/', PlaceFavoriteView.as_view(), name='place_favorite'), | ||||||
|     path('explorer/unfavorite/<int:place_id>/', PlaceUnfavoriteView.as_view(), name='place_unfavorite') |     path('explorer/unfavorite/<int:place_id>/', PlaceUnfavoriteView.as_view(), name='place_unfavorite') | ||||||
|      |  | ||||||
|      |  | ||||||
| ] | ] | ||||||
|   | |||||||
| @@ -12,6 +12,7 @@ from lostplaces.common import get_all_subclasses | |||||||
| from lostplaces.views.base_views import IsAuthenticatedMixin | from lostplaces.views.base_views import IsAuthenticatedMixin | ||||||
| from lostplaces.models.models import Explorer | from lostplaces.models.models import Explorer | ||||||
| from lostplaces.models.place import Place, PlaceAsset | from lostplaces.models.place import Place, PlaceAsset | ||||||
|  | from lostplaces.forms import ExplorerChangeForm, ExplorerUserChangeForm | ||||||
|  |  | ||||||
| class ExplorerProfileView(IsAuthenticatedMixin, View): | class ExplorerProfileView(IsAuthenticatedMixin, View): | ||||||
|     def get(self, request, explorer_id): |     def get(self, request, explorer_id): | ||||||
| @@ -39,3 +40,15 @@ class ExplorerProfileView(IsAuthenticatedMixin, View): | |||||||
|             template_name='explorer/profile.html', |             template_name='explorer/profile.html', | ||||||
|             context=context |             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) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user