Skip to content

Add management command and update to v0.3.0 #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.3.0] - 2019-10-30
### Added
- Added `generate_default_bootstraptheme` management command

### Changed
- Added more informative error messages when using template tags without a theme

## [0.2.0] - 2019-10-02
### Changed
- Updated to Bootstrap 4.3.1
Expand Down
2 changes: 1 addition & 1 deletion bootstrap_customizer/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.2.0'
__version__ = '0.3.0'
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.core.management.base import BaseCommand, CommandError
from bootstrap_customizer.models import BootstrapTheme
from bootstrap_customizer.models import SiteBootstrapTheme

class Command(BaseCommand):
help = 'Creates a BootstrapTheme and SiteBootstrapTheme if none exist'

def handle(self, *args, **options):
theme_count = BootstrapTheme.objects.count()
if theme_count > 0:
raise CommandError('A BootstrapTheme already exists')
site_theme_count = SiteBootstrapTheme.objects.count()
if theme_count > 0:
raise CommandError('A SiteBootstrapTheme already exists')

self.stdout.write('Creating BootstrapTheme and SiteBootstrapTheme')
theme = BootstrapTheme()
theme.save()
site_theme = SiteBootstrapTheme(bootstrap_theme=theme, site_id=1)
site_theme.save()

self.stdout.write(self.style.SUCCESS('Successfully created BootstrapTheme'))

22 changes: 19 additions & 3 deletions bootstrap_customizer/templatetags/bootstrap_customizer.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
from django import template
from django.core.exceptions import ImproperlyConfigured
from django.urls import reverse
from django.utils.safestring import mark_safe


register = template.Library()

missing_theme_message = (
"Could not find a BootstrapTheme for this site. "
"Create a BootstrapTheme entry in the admin or run "
"the create_default_bootstraptheme management command."
)


@register.simple_tag(takes_context=True)
def bootstrap_theme_css_above_the_fold(context):
bootstrap_theme = context['request'].bootstrap_theme
try:
bootstrap_theme = context['request'].bootstrap_theme
except AttributeError:
raise ImproperlyConfigured(missing_theme_message)
return mark_safe(bootstrap_theme.css_above_the_fold)


@register.simple_tag(takes_context=True)
def bootstrap_theme_css_below_the_fold(context):
bootstrap_theme = context['request'].bootstrap_theme
try:
bootstrap_theme = context['request'].bootstrap_theme
except AttributeError:
raise ImproperlyConfigured(missing_theme_message)
return mark_safe(bootstrap_theme.css_below_the_fold)


@register.simple_tag(takes_context=True)
def bootstrap_theme_css_below_the_fold_url(context):
bootstrap_theme = context['request'].bootstrap_theme
try:
bootstrap_theme = context['request'].bootstrap_theme
except AttributeError:
raise ImproperlyConfigured(missing_theme_message)
return reverse('bootstrap_customizer:bootstrap_css_below_the_fold', kwargs=dict(
hash=bootstrap_theme.get_hash()
))
7 changes: 6 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Enjoy tailored Bootstrap CSS without having to set up a Node front-end assets pi
## Pages

- [Models](models.md)
- [Management Commands](management_commands.md)
- [Template Tags](template_tags.md)
- [Views](views.md)
- [Middleware](middleware.md)
Expand Down Expand Up @@ -72,7 +73,11 @@ urlpatterns = [
]
```

Create a [`BootstrapTheme`](models.md#bootstraptheme) and [`SiteBootstrapTheme`](models.md#sitebootstraptheme) from the Django admin.
Create a [`BootstrapTheme`](models.md#bootstraptheme) and [`SiteBootstrapTheme`](models.md#sitebootstraptheme) from the Django admin or use the management command:

```console
./manage.py create_default_bootstraptheme
```

Add above-the-fold and below-the-fold CSS to your template:

Expand Down
13 changes: 13 additions & 0 deletions docs/management_commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Management Commands

## `create_default_bootstraptheme`

This management command creates an initial [`BootstrapTheme`](./models.md#bootstraptheme) and [`SiteBootstrapTheme`](./models.md#sitebootstraptheme).

Usage:

```console
$ ./manage.py create_default_bootstraptheme
Creating BootstrapTheme and SiteBootstrapTheme
Successfully created BootstrapTheme
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ repo_url: 'https://github.com/johnfraney/django-bootstrap-customizer'
nav:
- Home: index.md
- Models: models.md
- Management Commands: management_commands.md
- Template Tags: template_tags.md
- Views: views.md
- Middleware: middleware.md
Expand Down