def edit(community):
    """Create or edit a community."""
    form = EditCommunityForm(formdata=request.values, obj=community)
    deleteform = DeleteCommunityForm()
    ctx = mycommunities_ctx()
    ctx.update({
        'form': form,
        'is_new': False,
        'community': community,
        'deleteform': deleteform,
    })

    if form.validate_on_submit():
        for field, val in form.data.items():
            setattr(community, field, val)

        file = request.files.get('logo', None)
        if file:
            if not community.save_logo(file.stream, file.filename):
                form.logo.errors.append(_(
                    'Cannot add this file as a logo. Supported formats: '
                    'PNG, JPG and SVG. Max file size: 1.5 MB.'))

        if not form.logo.errors:
            db.session.commit()
            flash("Community successfully edited.", category='success')
            return redirect(url_for('.edit', community_id=community.id))

    return render_template(
        current_app.config['COMMUNITIES_EDIT_TEMPLATE'],
        **ctx
    )