Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add image upload to user profile page #466

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
18 changes: 12 additions & 6 deletions wwwapp/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def __init__(self, mce_attrs=None, **kwargs):


class UserProfilePageForm(ModelForm):
class Meta:
model = UserProfile
fields = ['profile_page']
labels = {'profile_page': "Strona profilowa"}

def __init__(self, *args, **kwargs):
super(UserProfilePageForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
Expand All @@ -45,11 +50,12 @@ def __init__(self, *args, **kwargs):
css_class='text-right'
))

class Meta:
model = UserProfile
fields = ['profile_page']
labels = {'profile_page': "Strona profilowa"}
widgets = {'profile_page': InitializedTinyMCE()}
mce_attrs = {}
if self.instance and self.instance.pk:
mce_attrs = settings.TINYMCE_DEFAULT_CONFIG_WITH_IMAGES.copy()
mce_attrs['automatic_uploads'] = True
mce_attrs['images_upload_url'] = reverse('mydata_profile_upload')
self.fields['profile_page'].widget = InitializedTinyMCE(mce_attrs=mce_attrs)


class UserCoverLetterForm(ModelForm):
Expand Down Expand Up @@ -530,4 +536,4 @@ def filter_method(self):

@property
def filter_name(self):
return self.filter_methods[self.cleaned_data['filter']][1]
return self.filter_methods[self.cleaned_data['filter']][1]
1 change: 1 addition & 0 deletions wwwapp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
path('accounts/verified/', finish_merge_verification, name='finish_merge_verification'),
path('profile/<int:user_id>/', views.profile_view, name='profile'),
path('me/profile/', views.mydata_profile_view, name='mydata_profile'),
path('me/profile/upload/', views.mydata_profile_upload_file, name='mydata_profile_upload'),
path('me/profile_page/', views.mydata_profile_page_view, name='mydata_profile_page'),
path('me/cover_letter/', views.mydata_cover_letter_view, name='mydata_cover_letter'),
path('me/status/', views.mydata_status_view, name='mydata_status'),
Expand Down
11 changes: 10 additions & 1 deletion wwwapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def workshop_participants_view(request, year, name):

for participant in context['workshop_participants']:
participant.form = WorkshopParticipantPointsForm(instance=participant, auto_id='%s_'+str(participant.id))

return render(request, 'workshopparticipants.html', context)


Expand Down Expand Up @@ -1072,3 +1072,12 @@ def workshop_edit_upload_file(request, year, name):
target_dir = "images/workshops/{}/{}/".format(workshop.year.pk, workshop.name)

return _upload_file(request, target_dir)


@login_required()
@require_POST
@csrf_exempt
def mydata_profile_upload_file(request):
target_dir = "images/profiles/{}/".format(request.user.pk)

return _upload_file(request, target_dir)