diff --git a/DATABASE.adoc b/DATABASE.adoc index c5a911d..46c5055 100644 --- a/DATABASE.adoc +++ b/DATABASE.adoc @@ -124,6 +124,14 @@ cd /path/to/FlatGov/server_py pip install -r requirements.txt ``` +## Load fixtures + +The About page is created as a fixture. To load it, run +``` +cd server_py/flatgov +python manage.py loaddata about_us.json +``` + ## Create billsMeta.json file via Django command. * Add data to database diff --git a/server_py/flatgov/about_us.json b/server_py/flatgov/about_us.json new file mode 100644 index 0000000..77c36a5 --- /dev/null +++ b/server_py/flatgov/about_us.json @@ -0,0 +1 @@ +[{"model": "home.aboutpage", "pk": 1, "fields": {"title": "About page content", "content": "
Flatgov is a project of Demand Progress Education Fund in partnership with GovTrack.us. Its purpose is to demonstrate how we can use existing information to provide additional context and new insights into the legislative process that are useful for congressional experts.
\r\n\r\nFlatgov was built through a human-centered design process intended to surface the needs of different kinds of expert users that interact with legislative information.
\r\n\r\nThe key insight behind Flatgov is that legislating is an iterative process. Legislation embodies ideas that arise over multiple Congresses and in multiple contexts.
\r\n\r\nFor example, similar or identical legislation is reintroduced every Congress. How do we identify those identical or similar bills when they reappear?
\r\n\r\nIn addition, the same legislative idea can be embodied in multiple bills in the same Congress. Sometimes a smaller bill is rolled into larger legislation. How do we know that the larger bill carries legislative ideas that originated in other legislation?
\r\n\r\nWhen we connect identical or similar bills across the same Congress or across multiple Congresses, we gain a greater understanding of the strengths and weaknesses of the legislation, its likely supporters and opponents, and surface the discussion around those legislative ideas.
\r\n\r\nFor example, if you can connect related legislation, you can gain important insights:
\r\n\r\nThe work to create Flatgov proceeded along several parallel tracks.
\r\n\r\nWe are publishing the code for Flatgov online for free, without a license, for anyone to use. Our hope is to spur others to repurpose the code for their own uses. We also seek to encourage the Library of Congress to enhance their premier website, Congress.gov, to maximize the value that people can derive from information on their website by putting legislation in the appropriate temporal context and supporting users in their efforts to connect the dots among legislative actions.
\r\n\r\nFlatgov was supposed through a one-time grant. There is more work to do, but we hope our work thus far points the way forward.
\r\n\r\n", "created_at": "2021-04-30T18:02:02.777Z", "updated_at": "2021-04-30T18:50:24.597Z"}}] \ No newline at end of file diff --git a/server_py/flatgov/flatgov/settings.py b/server_py/flatgov/flatgov/settings.py index 68415ed..0550799 100644 --- a/server_py/flatgov/flatgov/settings.py +++ b/server_py/flatgov/flatgov/settings.py @@ -60,6 +60,7 @@ 'bills', 'uscongress', + 'home', 'rest_framework', 'django_tables2', @@ -67,6 +68,9 @@ 'crs', # by Dmitry 'statementAdminPolicy', 'committeeReport', + 'ckeditor', + "ckeditor_uploader", + ] MIDDLEWARE = [ @@ -219,4 +223,85 @@ BILL_SUMMARY_DEFAULT_TEXT = 'Bill Summary Default Text' -PROPUBLICA_CONGRESS_API_KEY = os.getenv('PROPUBLICA_CONGRESS_API_KEY', "") \ No newline at end of file +PROPUBLICA_CONGRESS_API_KEY = os.getenv('PROPUBLICA_CONGRESS_API_KEY', "") + + + +CKEDITOR_UPLOAD_PATH = "media/" +CKEDITOR_IMAGE_BACKEND = "pillow" +CKEDITOR_THUMBNAIL_SIZE = (300, 300) +CKEDITOR_IMAGE_QUALITY = 40 +CKEDITOR_BROWSE_SHOW_DIRS = True +CKEDITOR_ALLOW_NONIMAGE_FILES = True + + +# CKEDITOR +CKEDITOR_CONFIGS = { + 'default': { + 'skin': 'moono-lisa', + # 'skin': 'office2013', + 'toolbar_Basic': [ + ['Source', '-', 'Bold', 'Italic'] + ], + 'toolbar_Full': [ + {'name': 'document', 'items': ['Source', '-', 'Save', 'NewPage', 'Preview', 'Print', '-', 'Templates']}, + {'name': 'clipboard', 'items': ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo']}, + {'name': 'editing', 'items': ['Link', 'Anchor', 'Find', 'Replace', '-', 'SelectAll']}, + # {'name': 'forms', + # 'items': ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', + # 'HiddenField']}, + '/', + {'name': 'basicstyles', + 'items': ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat']}, + {'name': 'paragraph', + 'items': ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', + 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl', + 'Language']}, + {'name': 'links', 'items': ['Link', 'Unlink', 'Anchor']}, + {'name': 'insert', + 'items': ['Image','Table', 'HorizontalRule','SpecialChar', 'PageBreak', 'Iframe']}, + '/', + {'name': 'styles', 'items': ['Styles', 'Format', 'Font', 'FontSize']}, + {'name': 'colors', 'items': ['TextColor', 'BGColor']}, + {'name': 'tools', 'items': ['Maximize', 'ShowBlocks']}, + {'name': 'about', 'items': ['About']}, + '/', # put this to force next toolbar on new line + {'name': 'yourcustomtools', 'items': [ + # put the name of your editor.ui.addButton here + 'Preview', + 'Maximize', + + ]}, + ], + 'toolbar': 'Full', # put selected toolbar config here + # 'toolbarGroups': [{ 'name': 'document', 'groups': [ 'mode', 'document', 'doctools' ] }], + "height": 291, + "width": 835, + 'filebrowserWindowHeight': 725, + 'filebrowserWindowWidth': 940, + # 'toolbarCanCollapse': True, + # 'mathJaxLib': '//cdn.mathjax.org/mathjax/2.2-latest/MathJax.js?config=TeX-AMS_HTML', + 'tabSpaces': 4, + 'extraPlugins': ','.join([ + "image2", + "codesnippet", + # 'uploadimage', # the upload image feature + # your extra plugins here + 'div', + 'autolink', + 'autoembed', + 'embedsemantic', + 'autogrow', + # 'devtools', + 'widget', + 'lineutils', + 'clipboard', + 'dialog', + 'dialogui', + 'elementspath', + + ]), + "removePlugins": ",".join(["image"]), + "codeSnippet_theme": "xcode", + } +} diff --git a/server_py/flatgov/flatgov/urls.py b/server_py/flatgov/flatgov/urls.py index 8d63a7f..4e7b7ac 100644 --- a/server_py/flatgov/flatgov/urls.py +++ b/server_py/flatgov/flatgov/urls.py @@ -21,7 +21,7 @@ urlpatterns = [ re_path(r'^$', RedirectView.as_view(url='home/', permanent=False), name='index'), path('bills/', include('bills.urls')), - path('home/', include('home.urls')), + path('', include('home.urls')), path('uscongress/debug/', include('uscongress.urls')), path('admin/', admin.site.urls), path('crs/', include('crs.urls')), diff --git a/server_py/flatgov/home/admin.py b/server_py/flatgov/home/admin.py index 8c38f3f..62af8bf 100644 --- a/server_py/flatgov/home/admin.py +++ b/server_py/flatgov/home/admin.py @@ -1,3 +1,18 @@ from django.contrib import admin -# Register your models here. +from .models import ( + AboutPage +) + + +class AboutPageAdmin(admin.ModelAdmin): + class Meta: + model = AboutPage + + def has_add_permission(self, request): + if self.model.objects.count() >= 1: + return False + return super().has_add_permission(request) + + +admin.site.register(AboutPage, AboutPageAdmin) diff --git a/server_py/flatgov/home/migrations/0001_initial.py b/server_py/flatgov/home/migrations/0001_initial.py new file mode 100644 index 0000000..24f4270 --- /dev/null +++ b/server_py/flatgov/home/migrations/0001_initial.py @@ -0,0 +1,25 @@ +# Generated by Django 3.1 on 2021-04-30 17:43 + +import ckeditor.fields +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='AboutPage', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(blank=True, default='About page content', max_length=127, null=True)), + ('content', ckeditor.fields.RichTextField()), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + ] diff --git a/server_py/flatgov/home/models.py b/server_py/flatgov/home/models.py index 71a8362..c0126f7 100644 --- a/server_py/flatgov/home/models.py +++ b/server_py/flatgov/home/models.py @@ -1,3 +1,12 @@ from django.db import models +from ckeditor.fields import RichTextField -# Create your models here. +class AboutPage(models.Model): + title = models.CharField(max_length=127, null=True, blank=True, default='About page content') + content = RichTextField() + + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) + + def __str__(self): + return f'{self.title} updated on {self.updated_at}' diff --git a/server_py/flatgov/home/urls.py b/server_py/flatgov/home/urls.py index 646436d..d2a159a 100644 --- a/server_py/flatgov/home/urls.py +++ b/server_py/flatgov/home/urls.py @@ -4,19 +4,22 @@ from . import views +app_name = 'home' + urlpatterns = [ # path('', views.index, name='index'), path( "robots.txt", TemplateView.as_view(template_name="robots.txt", content_type="text/plain"), ), - path('', views.home_view, name='home'), + path('home/', views.home_view, name='home'), + path('about/', views.AboutView.as_view(), name='about'), ] api_urlpatterns = [ - path('bill-list/', never_cache(views.BillListAPIView.as_view()), name='bill-list'), - path('bill-titles/