def form_update(request): """Page with form to update a theme.""" if request.method == 'POST': form = ThemeFormUpdate(request.POST, request.FILES) if form.is_valid(): themefile = request.FILES['themefile'] theme = Theme.objects.get(id=form.cleaned_data['theme']) # get properties content = themefile.read().replace('\r\n', '\n') props = Theme.get_props(content) # send e-mail try: subject = 'WeeChat: new version of theme %s' % theme.name body = ( '' 'Theme : %s\n' 'Version : %s\n' 'New version: %s\n' 'Author : %s\n' 'Mail : %s\n' 'Comment :\n%s\n' % (theme.name, theme.version, props['weechat'], form.cleaned_data['author'], form.cleaned_data['mail'], form.cleaned_data['comment'])) sender = '%s <%s>' % (form.cleaned_data['author'], form.cleaned_data['mail']) email = EmailMessage(subject, body, sender, settings.THEMES_MAILTO) email.attach(theme.name, content, 'text/plain') email.send() except: # noqa: E722 return HttpResponseRedirect('/themes/updateerror/') return HttpResponseRedirect('/themes/updateok/') else: form = ThemeFormUpdate() return render( request, 'themes/update.html', { 'form': form, }, )
def form_update(request): """Page with form to update a theme.""" if request.method == 'POST': form = ThemeFormUpdate(request.POST, request.FILES) if form.is_valid(): themefile = request.FILES['themefile'] theme = Theme.objects.get(id=form.cleaned_data['theme']) # get properties content = themefile.read().replace('\r\n', '\n') props = Theme.get_props(content) # send e-mail try: subject = 'WeeChat: new version of theme %s' % theme.name body = ('' 'Theme : %s\n' 'Version : %s\n' 'New version: %s\n' 'Author : %s\n' 'Mail : %s\n' 'Comment :\n%s\n' % (theme.name, theme.version, props['weechat'], form.cleaned_data['author'], form.cleaned_data['mail'], form.cleaned_data['comment'])) sender = '%s <%s>' % (form.cleaned_data['author'], form.cleaned_data['mail']) email = EmailMessage(subject, body, sender, settings.THEMES_MAILTO) email.attach(theme.name, content, 'text/plain') email.send() except: return HttpResponseRedirect('/themes/updateerror/') return HttpResponseRedirect('/themes/updateok/') else: form = ThemeFormUpdate() return render_to_response('themes/update.html', {'form': form}, context_instance=RequestContext(request))
def form_update(request): """Page with form to update a theme.""" if request.method == 'POST': form = ThemeFormUpdate(request.POST, request.FILES) if form.is_valid(): themefile = request.FILES['themefile'] theme = Theme.objects.get(id=form.cleaned_data['theme']) # get properties content = get_theme_content(themefile) props = Theme.get_props(content) # send e-mail if not settings.THEMES_MAILTO: return HttpResponseRedirect('/themes/updateerror/') try: subject = f'WeeChat: new version of theme {theme.name}' sender = (f'{form.cleaned_data["author"]} ' f'<{form.cleaned_data["mail"]}>') body = (f'Theme : {theme.name}\n' f'Version : {theme.version}\n' f'New version: {props["weechat"]}\n' f'Author : {sender}\n' f'Comment :\n{form.cleaned_data["comment"]}\n') email = EmailMessage(subject, body, sender, settings.THEMES_MAILTO) email.attach(theme.name, content, 'text/plain') email.send() except: # noqa: E722 pylint: disable=bare-except return HttpResponseRedirect('/themes/updateerror/') return HttpResponseRedirect('/themes/updateok/') else: form = ThemeFormUpdate() return render( request, 'themes/update.html', { 'form': form, }, )
def form_add(request): """Page with form to add a theme.""" if request.method == 'POST': form = ThemeFormAdd(request.POST, request.FILES) if form.is_valid(): themefile = request.FILES['themefile'] # get properties content = themefile.read().replace('\r\n', '\n') props = Theme.get_props(content) # add theme in database now = datetime.now() theme = Theme(visible=False, name=props['name'], version=props['weechat'], desc=form.cleaned_data['description'], author=form.cleaned_data['author'], mail=form.cleaned_data['mail'], added=now, updated=now) # write theme in pending directory filename = files_path_join('themes', 'pending', theme.name) with open(filename, 'w') as _file: _file.write(content) # send e-mail try: subject = 'WeeChat: new theme %s' % theme.name body = ( '' 'Theme : %s\n' 'Version : %s\n' 'Description: %s\n' 'Author : %s\n' 'Mail : %s\n' 'Comment :\n%s\n' % (props['name'], props['weechat'], form.cleaned_data['description'], form.cleaned_data['author'], form.cleaned_data['mail'], form.cleaned_data['comment'])) sender = '%s <%s>' % (form.cleaned_data['author'], form.cleaned_data['mail']) email = EmailMessage(subject, body, sender, settings.THEMES_MAILTO) email.attach_file(filename) email.send() except: # noqa: E722 return HttpResponseRedirect('/themes/adderror/') # save theme in database theme.save() return HttpResponseRedirect('/themes/addok/') else: form = ThemeFormAdd() try: stable_version = Release.objects.get(version='stable').description release_stable = Release.objects.get(version=stable_version) except ObjectDoesNotExist: release_stable = None return render( request, 'themes/add.html', { 'release_stable': release_stable, 'form': form, }, )
def form_add(request): """Page with form to add a theme.""" if request.method == 'POST': form = ThemeFormAdd(request.POST, request.FILES) if form.is_valid(): themefile = request.FILES['themefile'] # get properties content = themefile.read().replace('\r\n', '\n') props = Theme.get_props(content) # add theme in database now = datetime.now() theme = Theme(visible=False, name=props['name'], version=props['weechat'], desc=form.cleaned_data['description'], author=form.cleaned_data['author'], mail=form.cleaned_data['mail'], added=now, updated=now) # write theme in pending directory filename = files_path_join('themes', 'pending', theme.name) with open(filename, 'w') as _file: _file.write(content) # send e-mail try: subject = 'WeeChat: new theme %s' % theme.name body = ('' 'Theme : %s\n' 'Version : %s\n' 'Description: %s\n' 'Author : %s\n' 'Mail : %s\n' 'Comment :\n%s\n' % (props['name'], props['weechat'], form.cleaned_data['description'], form.cleaned_data['author'], form.cleaned_data['mail'], form.cleaned_data['comment'])) sender = '%s <%s>' % (form.cleaned_data['author'], form.cleaned_data['mail']) email = EmailMessage(subject, body, sender, settings.THEMES_MAILTO) email.attach_file(filename) email.send() except: return HttpResponseRedirect('/themes/adderror/') # save theme in database theme.save() return HttpResponseRedirect('/themes/addok/') else: form = ThemeFormAdd() return render_to_response( 'themes/add.html', { 'release_stable': Release.objects.get(version='stable'), 'form': form, }, context_instance=RequestContext(request))
def form_add(request): """Page with form to add a theme.""" if request.method == 'POST': form = ThemeFormAdd(request.POST, request.FILES) if form.is_valid(): themefile = request.FILES['themefile'] # get properties content = get_theme_content(themefile) props = Theme.get_props(content) # add theme in database now = datetime.now() theme = Theme(visible=False, name=props['name'], version=props['weechat'], desc=form.cleaned_data['description'], author=form.cleaned_data['author'], mail=form.cleaned_data['mail'], added=now, updated=now) # write theme in pending directory filename = files_path_join('themes', 'pending', theme.name) with open(filename, 'w') as _file: _file.write(content) # send e-mail try: subject = f'WeeChat: new theme {theme.name}' sender = (f'{form.cleaned_data["author"]} ' f'<{form.cleaned_data["mail"]}>') body = (f'Theme : {props["name"]}\n' f'Version : {props["weechat"]}\n' f'Description: {form.cleaned_data["description"]}\n' f'Author : {sender}\n' f'Comment :\n{form.cleaned_data["comment"]}\n') email = EmailMessage(subject, body, sender, settings.THEMES_MAILTO) email.attach_file(filename) email.send() except: # noqa: E722 pylint: disable=bare-except return HttpResponseRedirect('/themes/adderror/') # save theme in database theme.save() return HttpResponseRedirect('/themes/addok/') else: form = ThemeFormAdd() try: stable_version = Release.objects.get(version='stable').description release_stable = Release.objects.get(version=stable_version) except ObjectDoesNotExist: release_stable = None return render( request, 'themes/add.html', { 'release_stable': release_stable, 'form': form, }, )