This is a SCRIPT-8 cassette.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ContentView.swift | |
// AppRouterPlayground | |
// | |
// Created by Ben Cardy on 22/02/2023. | |
// | |
import SwiftUI | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// EqualWidthIcons.swift | |
// From https://bencardy.co.uk/2023/02/02/swiftui-equal-width-icons/ | |
// | |
// Created by Ben Cardy on 02/02/2023. | |
// | |
import SwiftUI | |
struct WhatsNewSection: View { |
self.request
is the way to get the request objectself.args
andself.kwargs
are the URL parameters fromurls.py
(they are also passed to almost every method, but they're not always, and some methods take anargs
andkwargs
that aren't the ones from the URL, so... just useself.
everywhere!)dispatch
is called beforeget
orpost
so is a useful place to setup stuff you need everywhere- the view object itself is available in the template as
view
, so templates can access view methods and properties - Detail and List views don't just get the template variables
object
andobject_list
, they also get<model-name>
and<model-name>_list
- Permission decorators etc are better handled by django-braces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.utils.http import urlencode | |
def reverse_querystring(view, urlconf=None, args=None, kwargs=None, current_app=None, query_kwargs=None): | |
'''Custom reverse to handle query strings. | |
Usage: | |
reverse('app.views.my_view', kwargs={'pk': 123}, query_kwargs={'search': 'Bob'}) | |
''' | |
base_url = reverse(view, urlconf=urlconf, args=args, kwargs=kwargs, current_app=current_app) | |
if query_kwargs: | |
return '{}?{}'.format(base_url, urlencode(query_kwargs)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Colours: | |
BLACK = '\033[30m' | |
BLUE = '\033[34m' | |
GREEN = '\033[32m' | |
CYAN = '\033[36m' | |
RED = '\033[31m' | |
PURPLE = '\033[35m' | |
YELLOW = '\033[33m' | |
LIGHT_GREY = '\033[37m' | |
DARK_GREY = '\033[1;30m' |