def update_about_photos(request): if not Permissions.can_manage_website(request.user): request.session['error_message']='You are not authorized to update about page photos' return redirect('about:index') AboutPhotoForm = modelformset_factory(AboutSlideShowPhoto, can_delete=True) if request.method=='POST': formset = AboutPhotoForm(request.POST,request.FILES,prefix='about_photo') if formset.is_valid(): instances = formset.save() request.session['success_message']='About page photos successfully updated.' return redirect('about:index') else: request.session['error_message']='Your submision contained errors, please correct and resubmit.' else: formset=AboutPhotoForm(prefix='about_photo') context_dict = { 'formset':formset, 'prefix':'about_photo', 'subnav':'about', 'has_files':True, 'submit_name':'Update About Page Photos', 'back_button':{'link':reverse('about:index'),'text':'To About Page'}, 'form_title':'Edit About Page Photos', 'help_text':'These are the photos shown in the about page photo slideshow. You can omit a photo from being displayed by unchecking the \"Active\" option.', 'can_add_row':True, 'base':'about/base_about.html', } context_dict.update(get_common_context(request)) context_dict.update(get_permissions(request.user)) context = RequestContext(request, context_dict) template = loader.get_template('generic_formset.html') return HttpResponse(template.render(context))
def get_permissions(user): """ Standardized way of querying user permissions across the website. Permissions for the entire (or most of it) module are loaded into a dictionary that gets merged with the template context to provide the template with a list of permissions so as to generate the page correctly. """ permission_dict={ 'can_edit_about_photos':Permissions.can_manage_website(user), } return permission_dict
def get_permissions(user): """ Standardized way of querying user permissions across the website. Permissions for the entire (or most of it) module are loaded into a dictionary that gets merged with the template context to provide the template with a list of permissions so as to generate the page correctly. """ permission_dict = { 'can_edit_about_photos': Permissions.can_manage_website(user), 'can_edit_bylaws': Permissions.can_manage_bylaws(user), } return permission_dict
def update_about_photos(request): """ Standard form view based on the generic_formset. Used to update the photos in the about landing page. """ denied_message = 'You are not authorized to update about page photos' if not Permissions.can_manage_website(request.user): request.session['error_message'] = denied_message return redirect('about:index') # messages and static text: success_msg = 'About page photos successfully updated.' help_text = ('These are the photos shown in the about page photo ' 'slideshow. You can omit a photo from being displayed by ' 'unchecking the \"Active\" option.') prefix = 'about_photo' AboutPhotoForm = modelformset_factory(AboutSlideShowPhoto, can_delete=True, exclude=[]) if request.method == 'POST': formset = AboutPhotoForm(request.POST, request.FILES, prefix=prefix) if formset.is_valid(): instances = formset.save() request.session['success_message'] = success_msg return redirect('about:index') else: request.session['error_message'] = FORM_ERROR else: formset = AboutPhotoForm(prefix=prefix) context_dict = { 'formset': formset, 'prefix': prefix, 'subnav': 'about', 'has_files': True, 'submit_name': 'Update About Page Photos', 'back_button': {'link': reverse('about:index'), 'text': 'To About Page'}, 'form_title': 'Edit About Page Photos', 'help_text': help_text, 'can_add_row': True, 'base': 'about/base_about.html', } context_dict.update(get_common_context(request)) context_dict.update(get_permissions(request.user)) context = RequestContext(request, context_dict) template = loader.get_template('generic_formset.html') return HttpResponse(template.render(context))
def update_about_photos(request): """ Standard form view based on the generic_formset. Used to update the photos in the about landing page. """ denied_message = 'You are not authorized to update about page photos' if not Permissions.can_manage_website(request.user): request.session['error_message'] = denied_message return redirect('about:index') # messages and static text: success_msg = 'About page photos successfully updated.' help_text = ('These are the photos shown in the about page photo ' 'slideshow. You can omit a photo from being displayed by ' 'unchecking the \"Active\" option.') prefix = 'about_photo' AboutPhotoForm = modelformset_factory(AboutSlideShowPhoto, can_delete=True, exclude=[]) if request.method == 'POST': formset = AboutPhotoForm(request.POST, request.FILES, prefix=prefix) if formset.is_valid(): instances = formset.save() request.session['success_message'] = success_msg return redirect('about:index') else: request.session['error_message'] = FORM_ERROR else: formset = AboutPhotoForm(prefix=prefix) context_dict = { 'formset': formset, 'prefix': prefix, 'subnav': 'about', 'has_files': True, 'submit_name': 'Update About Page Photos', 'back_button': {'link': reverse('about:index'), 'text': 'To About Page'}, 'form_title': 'Edit About Page Photos', 'help_text': help_text, 'can_add_row': True, 'base': 'about/base_about.html', } context_dict.update(get_common_context(request)) context_dict.update(get_permissions(request.user)) template = loader.get_template('generic_formset.html') return HttpResponse(template.render(context_dict,request))
def get_permissions(user): permission_dict={ 'can_edit_about_photos':Permissions.can_manage_website(user), } return permission_dict