~linuxgoose/bocpress

559db657d463cb32a93dd11907e5dcd84c140101 — Jordan Robinson 4 months ago 5060043
change images to be assets and allow for more file types per #25
M main/forms.py => main/forms.py +1 -1
@@ 52,7 52,7 @@ class UploadImagesForm(forms.Form):
    file = MultipleFileField(
        validators=[
            dj_validators.FileExtensionValidator(
                ["jpeg", "jpg", "png", "svg", "gif", "webp", "tiff", "tif", "bmp"]
                ["jpeg", "jpg", "png", "svg", "gif", "webp", "tiff", "tif", "bmp", "txt", "md", "rtf", "pdf", "epub", "doc", "docx", "odt", "ppt", "pptx", "odp", "xls", "xlsx", "ods", "csv", "tsv", "ics", "vcf", "log", "json", "xml", "yml", "yaml", "ini", "toml", "cfg", "conf", "mdown", "markdown"]
            )
        ],
    )

M main/templates/main/dashboard.html => main/templates/main/dashboard.html +2 -2
@@ 18,9 18,9 @@
        </a>
        <br>
        {% endif %}
        

        <a href="{% url 'homepage_update' %}">Homepage</a>
        <br><a href="{% url 'image_list' %}">Images</a>
        <br><a href="{% url 'image_list' %}">Assets</a>
        <br><a href="{% url 'post_list' %}">Posts</a>
        <br><a href="{% url 'page_list' %}">Pages</a>


M main/templates/main/guides_images.html => main/templates/main/guides_images.html +10 -10
@@ 2,36 2,36 @@

{% load static %}

{% block title %}Images Guide{% endblock %}
{% block title %}Assets Guide{% endblock %}

{% block content %}
<main>

    <h1>Images Guide</h1>
    <h1>Assets Guide</h1>
    <p>
        Even though we are very text focused, we do support image uploading and hosting.
        Even though we are very text focused, we do support asset uploading and hosting.
        The limits are:
    </p>
    <ul>
        <li>Max file size is 1MB</li>
        <li>Max file size is 5MB</li>
        <li>Total hosting up to 100MB</li>
        <li>Total image count up to 1000</li>
        <li>Total asset count up to 1000</li>
        <li>Bandwidth 100GB per year</li>
    </ul>

    <h2>Upload</h2>
    <p>
        There are two ways to upload an image. Either via the
        <a href="{% url 'image_list' %}">image dashboard</a>, or via any post or page editing page.
        There are two ways to upload an asset. Either via the
        <a href="{% url 'image_list' %}">assets dashboard</a>, or via any post or page editing page.
    </p>
    <p><b>Image dashboard</b>: To upload, use the file selector at the <a href="{% url 'image_list' %}">top</a>.</p>
    <p><b>Assets dashboard</b>: To upload, use the file selector at the <a href="{% url 'image_list' %}">top</a>.</p>
    <p>
        <b>Post/page edit</b>: To upload, just drag and drop onto the text area of the new post or page.
    </p>

    <h2>Show images</h2>
    <h2>Show assets</h2>
    <p>
        To show the uploaded images on a BōcPress blog post or page, one can write the following:
        To show the uploaded assets on a BōcPress blog post or page, one can write the following:
        <br><code>![image description here](https://mataroa.blog/images/896f9b41.png)</code>
    </p>
    <p>

M main/templates/main/image_confirm_delete.html => main/templates/main/image_confirm_delete.html +1 -1
@@ 4,7 4,7 @@

{% block content %}
<main class="delete">
    <h1>Delete {{ image.name }} for sure?</h1>
    <h1>Are you sure you want to delete {{ image.name }}?</h1>
    <form method="post">
        {% csrf_token %}
        <input type="submit" value="Yes, delete for sure" class="type-danger">

M main/templates/main/image_detail.html => main/templates/main/image_detail.html +3 -3
@@ 7,14 7,14 @@
    <h1>{{ image.name }}</h1>

    <div class="images-item-byline">
        <a class="images-item-back" href="{% url 'image_list' %}">« all images</a>
        <a class="images-item-back" href="{% url 'image_list' %}">« all assets</a>
        — Uploaded on <time datetime="{{ image.uploaded_at|date:'Y-m-d' }}">{{ image.uploaded_at|date:'F j, Y' }}</time>
        | <a href="{% url 'image_update' image.slug %}">Edit image</a>
        | <a href="{% url 'image_update' image.slug %}">Edit asset</a>
        | <a href="{% url 'image_delete' image.slug %}">Delete</a>
    </div>

    <p>
        Use markdown syntax to add this image in a post:
        Use markdown syntax to add this asset in a post as an image:
    </p>
    <code>
        ![{{ image.name }}]({{ request.scheme }}:{{ image.raw_url_absolute }})

M main/templates/main/image_form.html => main/templates/main/image_form.html +2 -2
@@ 1,10 1,10 @@
{% extends 'main/layout.html' %}

{% block title %}Editing {{ form.name.value }} image — {{ request.user.username }}{% endblock %}
{% block title %}Editing {{ form.name.value }} asset — {{ request.user.username }}{% endblock %}

{% block content %}
<main>
    <h1>Editing image</h1>
    <h1>Editing asset</h1>

    <form method="post">
        {{ form.as_p }}

M main/templates/main/image_list.html => main/templates/main/image_list.html +3 -3
@@ 1,10 1,10 @@
{% extends 'main/layout.html' %}

{% block title %}Images — {{ request.user.username }}{% endblock %}
{% block title %}Assets — {{ request.user.username }}{% endblock %}

{% block content %}
<main>
    <h1>Images</h1>
    <h1>Assets</h1>
    <form method="post" enctype="multipart/form-data">
        {{ form.non_field_errors }}
        <p>


@@ 22,7 22,7 @@

<section>
    <p>
        <strong>Using:</strong> {{ images|length }} out of 1000 images.
        <strong>Using:</strong> {{ images|length }} out of 1000 assets.
        {{ total_quota }}MB out of 1000MB.
    </p>
</section>

M main/templates/main/landing.html => main/templates/main/landing.html +1 -1
@@ 41,7 41,7 @@
        </li>

        <li>
            <a href="{% url 'guides_images' %}">Image hosting is included</a>
            <a href="{% url 'guides_images' %}">Assets hosting is included</a>
        </li>
        <li>Feed Subscriptions available for readers</li>
        <ul>

M main/templates/main/moderation_images.html => main/templates/main/moderation_images.html +3 -3
@@ 1,10 1,10 @@
{% extends 'main/layout.html' %}

{% block title %}Moderation Images{% endblock %}
{% block title %}Moderation Assets{% endblock %}

{% block content %}
<main>
    <h1>Moderation Images</h1>
    <h1>Moderation Assets</h1>
</main>

<section class="moderation-content" style="max-width: 700px;">


@@ 25,7 25,7 @@
    <div style="display: grid; grid-template-columns: 80px 1fr 120px 140px 120px; gap: 8px; align-items: center;">
        <div><strong>ID</strong></div>
        <div><strong>User</strong></div>
        <div style="text-align: right;"><strong>Images</strong></div>
        <div style="text-align: right;"><strong>Assets</strong></div>
        <div style="text-align: right;"><strong>Size (MB)</strong></div>
        <div style="text-align: right;"><strong>Joined</strong></div>


M main/urls.py => main/urls.py +8 -8
@@ 15,7 15,7 @@ urlpatterns = [
    path("about/transparency/", general.transparency, name="transparency"),
    path("about/comparisons/", general.comparisons, name="comparisons"),
    path("guides/markdown/", general.guides_markdown, name="guides_markdown"),
    path("guides/images/", general.guides_images, name="guides_images"),
    path("guides/assets/", general.guides_images, name="guides_images"),
    path(
        "guides/custom-domain/", general.guides_customdomain, name="guides_customdomain"
    ),


@@ 46,7 46,7 @@ urlpatterns += [
    path("moderation/index/", moderation.index, name="moderation_index"),
    path("moderation/cards/", moderation.user_cards, name="moderation_user_cards"),
    path("moderation/users/", moderation.user_list, name="moderation_user_list"),
    path("moderation/images/", moderation.images_leaderboard, name="moderation_images"),
    path("moderation/assets/", moderation.images_leaderboard, name="moderation_images"),
    path("moderation/posts/", moderation.posts_leaderboard, name="moderation_posts"),
    path("moderation/stats/", moderation.stats, name="moderation_stats"),
    path(


@@ 231,20 231,20 @@ urlpatterns += [
    ),
]

# images
# assets (images and other files)
urlpatterns += [
    path("images/<slug:slug>.<slug:extension>", general.image_raw, name="image_raw"),
    path("assets/<slug:slug>.<slug:extension>", general.image_raw, name="image_raw"),
    re_path(
        r"^images/(?P<options>\?[\w\=]+)?$",  # e.g. images/ or images/?raw=true
        r"^assets/(?P<options>\?[\w\=]+)?$",  # e.g. assets/ or assets/?raw=true
        general.ImageList.as_view(),
        name="image_list",
    ),
    path("images/<slug:slug>/", general.ImageDetail.as_view(), name="image_detail"),
    path("assets/<slug:slug>/", general.ImageDetail.as_view(), name="image_detail"),
    path(
        "images/<slug:slug>/edit/", general.ImageUpdate.as_view(), name="image_update"
        "assets/<slug:slug>/edit/", general.ImageUpdate.as_view(), name="image_update"
    ),
    path(
        "images/<slug:slug>/delete/",
        "assets/<slug:slug>/delete/",
        general.ImageDelete.as_view(),
        name="image_delete",
    ),

M main/views/general.py => main/views/general.py +3 -3
@@ 811,8 811,8 @@ class ImageList(LoginRequiredMixin, FormView):
                data = f.read()

                # check for file limit
                if len(data) > 1.1 * 1000 * 1000:
                    form.add_error("file", "File too big. Limit is 1MB.")
                if len(data) > 5 * 1024 * 1024:
                    form.add_error("file", "File too big. Limit is 5MB.")
                    return self.form_invalid(form)

                # quota limit 1GB total per user


@@ 868,7 868,7 @@ class ImageDetail(LoginRequiredMixin, DetailView):
        # find posts that use this image
        context["used_by_posts"] = []
        for post in models.Post.objects.filter(owner=self.request.user):
            if "/images/" + self.object.filename in post.body:
            if "/assets/" + self.object.filename in post.body:
                context["used_by_posts"].append(post)

        return context