- Fixed duplicate image uploading bug (i think)
- changing community settings now redirects you, same with creating a community.
This commit is contained in:
some weird guy
2023-09-04 21:17:50 -07:00
parent b4772d0e20
commit a9bf3179f1
3 changed files with 23 additions and 13 deletions
+11 -2
View File
@@ -50,15 +50,24 @@ def compress_and_resize_content(image):
# I do want to move each and every form over to here. Not only will this trivialize making new forms, this will also make it more secure or something. # I do want to move each and every form over to here. Not only will this trivialize making new forms, this will also make it more secure or something.
class CommunitySettingForm(forms.ModelForm): class CommunitySettingForm(forms.ModelForm):
description = forms.CharField(max_length = 2200,required=False, widget=forms.Textarea(attrs={'class': 'textarea'})) description = forms.CharField(max_length = 2200,required=False, widget=forms.Textarea(attrs={'class': 'textarea'}))
def __init__(self, *args, **kwargs):
super(CommunitySettingForm, self).__init__(*args, **kwargs)
# Store the initial values of the image fields
self.initial_ico = self.instance.ico
self.initial_banner = self.instance.banner
def clean_ico(self): def clean_ico(self):
ico = self.cleaned_data.get('ico') ico = self.cleaned_data.get('ico')
if ico: # Check if the image has changed
if ico and ico != self.initial_ico:
return compress_and_resize_icon(image=ico) return compress_and_resize_icon(image=ico)
return ico return ico
def clean_banner(self): def clean_banner(self):
banner = self.cleaned_data.get('banner') banner = self.cleaned_data.get('banner')
if banner: # Check if the image has changed
if banner and banner != self.initial_banner:
return compress_and_resize_content(image=banner) return compress_and_resize_content(image=banner)
return banner return banner
+2 -2
View File
@@ -1013,7 +1013,7 @@ def community_tools_set(request, community):
return json_response(form.errors.as_text()) return json_response(form.errors.as_text())
form.save() form.save()
AuditLog.objects.create(type=4, community=the_community, user=the_community.creator, by=request.user) AuditLog.objects.create(type=4, community=the_community, user=the_community.creator, by=request.user)
return HttpResponse() return redirect(reverse('main:community-view', args=[the_community.id]))
else: else:
raise Http404() raise Http404()
@@ -1042,7 +1042,7 @@ def community_create_action(request):
community.type = 3 community.type = 3
community.creator = request.user community.creator = request.user
community.save() community.save()
return json_response('Community has been created, check the front page!', 'Done') return redirect('/')
else: else:
raise Http404() raise Http404()
@login_required @login_required
+9 -8
View File
@@ -3606,11 +3606,12 @@ mode_post = 0;
*/ */
b.router.connect("^/communities/[0-9]+/(tools)$", function(c, d, e) { b.router.connect("^/communities/[0-9]+/(tools)$", function(c, d, e) {
function f(c) { function f(c) {
var d = a(this) var d = a(this),
, e = d.closest("form"); e = d.closest("form");
b.Form.isDisabled(d) || c.isDefaultPrevented() || (c.preventDefault(), b.Form.isDisabled(d) || c.isDefaultPrevented() || (c.preventDefault(),
b.Form.submit(e, d).done(function(a) { b.Form.submit(e, d).done(function(a) {
b.Net.reload() var communityId = window.location.pathname.split('/')[2];
window.location = "/communities/" + communityId;
})) }))
} }
a(document).on("click", ".apply-button", f), a(document).on("click", ".apply-button", f),
@@ -3620,13 +3621,13 @@ mode_post = 0;
}), }),
b.router.connect("^/c/create$", function(c, d, e) { b.router.connect("^/c/create$", function(c, d, e) {
function f(c) { function f(c) {
var d = a(this) var d = a(this),
, e = d.closest("form"); e = d.closest("form");
b.Form.isDisabled(d) || c.isDefaultPrevented() || (c.preventDefault(), b.Form.isDisabled(d) || c.isDefaultPrevented() || (c.preventDefault(),
b.Form.submit(e, d).done(function(a) { b.Form.submit(e, d).done(function(a) {
b.Net.reload() window.location = "/";
})) }))
} }
a(document).on("click", ".apply-button", f), a(document).on("click", ".apply-button", f),
e.done(function() { e.done(function() {
a(document).off("click", ".apply-button", f) a(document).off("click", ".apply-button", f)