2024-12-18-Wednesday


created: 2024-12-18 05:17 tags: - daily-notes


Wednesday, December 18, 2024

<< Timestamps/2024/12-December/2024-12-17-Tuesday|Yesterday | Timestamps/2024/12-December/2024-12-19-Thursday|Tomorrow >>


🎯 Goal

  • [x] Create a page to read about the actual note itself (vault_note_detail) so that users can read the full breakdown of what I worked on that day.

🌟 Results

  • Created a page to read about the actual note itself (vault_note_detail) so that users can read the full breakdown of what I worked on that day.
  • Created a note_detail Django Template so that users could view the contents of individual Markdown notes rendered as HTML
  • Added featured vaults to the site header, under the Blog section
  • Prevented users from accessing private vaults and notes

🌱 Next Time


📝 Notes

Yesterday I worked on developing the Django Views and Django Routes to display the information about the Notes. I was also able to get django-markdownx to work so that I could render Markdown files as HTML. My Vault overview is now available here:

http://127.0.0.1:8000/blog/vault/dimmin-notes/

Now I'd like a user to be able to click into a Note to read more about what I worked on that day. I was able to add the correct links to the Note detail route with the following:

<div class="blog-post__title">
    <h2>
        <a href="{% url 'vault_note_detail' vault_slug=note.vault.slug note_slug=note.slug %}">{{ note.title }}</a>
    </h2>
</div>

I then made some updates to the Django View of the Note to clean up the code:

class NoteDetailView(DetailView):
    model = Note
    template_name = 'vault_note_detail.html'
    context_object_name = 'note'

    def get_object(self, queryset=None):
        # Fetch the note based on the vault_slug and note_slug from the URL
        vault_slug = self.kwargs['vault_slug']
        note_slug = self.kwargs['note_slug']
        return get_object_or_404(Note, vault__slug=vault_slug, slug=note_slug)

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        note = self.object

        # Add navigation links
        context['previous_note'] = note.vault.notes.filter(created_at__lt=note.created_at).order_by('-created_at').first()
        context['next_note'] = note.vault.notes.filter(created_at__gt=note.created_at).order_by('created_at').first()

        # Add linked notes
        context['outgoing_notes'] = note.get_outgoing_links()
        context['incoming_notes'] = note.get_backlinks()

        return context

In this particular case, I may want to tag these Notes as Daily Notes when I read them in, then filter them in a view so that only the daily notes are displayed.

I also added a Vault Django View so that the user can look through public vaults. Now the user can access the Vaults, then list the Vault's Notes, then view the individual Notes of that vault in the following logical flow:

vaults -> vaults/vault-name -> vaults/vault-name/vault-note

Interestingly, when I tried to add the navigation to the base.html the public_vaults context data was only available when I was at the vault route (http://127.0.0.1:8000/blog/vault/). I wanted to make this information available from any Django Route. To do this I needed to use a Django Context Processor which I created as apps/bigbrain/context_processors.py:

from .models import Vault

def public_vaults(request):
    # Return public vaults globally
    return {
        'public_vaults': Vault.objects.filter(is_private=False).order_by('name')
    }

Then in the overall project settings (config/settings.py) I added the context processor to the TEMPLATES:

TEMPLATES = [
    {
        ...
        'OPTIONS': {
            'context_processors': [
                ...
                # Other context processors
                'apps.bigbrain.context_processors.public_vaults',
            ],
        },
    },
]

This allowed that context to be propogated site-wide, allowing me to access the public Vaults in the BigBrain App from anywhere, not just on the /blog/vault/ Django Route:

--redacted--

--redacted--

Now the Django Model data is fully accessible to the user. Unfortunately, private vaults are also accessible to the user. I should return a 400 Error (specifically the 403 response) when a user attempts to access a private Vault or a private Note. I was able to handle this with the django.core.exceptions.PermissionDenied function, raising an error in the Django View when an unauthorized user tried to access a private file:

# apps/bigbrain/views.py VaultNoteListView
# Check if the vault is private and if the user is authorized
if self.vault.is_private and not self.request.user.is_staff:
    raise PermissionDenied("You do not have permission to view this vault's notes.")

Currently Django Superusers can view any vaults or notes, public or private. This is fine for now, but if other users want to join to display their own digital gardens then I would want their private data to remain their own. I've also added a couple updates to the Vault Django Model, setting its summary description to a text field and adding the boolean is_featured attribute that will be used to determine whether the vault is displayed under the site header. All public Vaults will be available, but whether it is shown off in the site header will be determined by whether is_featured is true. I also enforced that if a Vault is private, it cannot be featured in the save logic of the model.

For now I'll push these changes to Production because I'm happy with being able to see the ugly notes on the site. I can always update them later, but I want to show my WGU Mentor what information I'm interested in publishing for my program.

The next steps here are to:

  • Better process these notes via
    • Tagging notes (specifically daily notes)
    • Extracting summaries,
    • Create vaild links to notes, as well as to
  • Pretty up the display
    • Currently it's not horrible, but it could look a lot nicer
    • Maybe it would work better if I made it look similar to the components of the Taskmaster App

Notes created today

List FROM "" WHERE file.cday = date("2024-12-18") SORT file.ctime asc

Notes last touched today

List FROM "" WHERE file.mday = date("2024-12-18") SORT file.mtime asc

(Template referenced from Dann Berg, can be found here)


Previous Note 2024-12-17-Tuesday Next Note 2024-12-19-Thursday