From 07ba81ecbabf4e72c8a9b138fd1ea9ab344b868a Mon Sep 17 00:00:00 2001 From: Ari Hershowitz Date: Tue, 4 May 2021 17:13:29 -0700 Subject: [PATCH] Feature/enhancements cherrypick 2 (#342) * Update DATABASE.adoc to load about us fixture * Update docs Co-authored-by: ayeshamk --- DATABASE.adoc | 8 ++ server_py/flatgov/about_us.json | 1 + server_py/flatgov/flatgov/settings.py | 87 ++++++++++++++++++- server_py/flatgov/flatgov/urls.py | 2 +- server_py/flatgov/home/admin.py | 17 +++- .../flatgov/home/migrations/0001_initial.py | 25 ++++++ server_py/flatgov/home/models.py | 11 ++- server_py/flatgov/home/urls.py | 11 ++- server_py/flatgov/home/views.py | 10 +++ server_py/flatgov/static/css/style.css | 1 + server_py/flatgov/static/docs/BILL_MODEL.html | 2 +- .../flatgov/static/docs/CRS_REPORTS.html | 2 +- server_py/flatgov/static/docs/DATABASE.html | 17 +++- .../flatgov/static/docs/DATA_BACKGROUND.html | 2 +- server_py/flatgov/static/docs/DEPLOYMENT.html | 2 +- .../flatgov/static/docs/ES_SIMILARITY.html | 2 +- server_py/flatgov/static/docs/README.html | 2 +- server_py/flatgov/static/docs/SCRAPING.html | 2 +- .../flatgov/static/docs/UPDATES_CELERY.html | 2 +- .../static/docs/USCONGRESS_SCRAPER.html | 2 +- server_py/flatgov/static/docs/index.html | 2 +- server_py/flatgov/templates/bills/detail.html | 17 ++-- server_py/flatgov/templates/home/about.html | 20 +++++ server_py/flatgov/templates/navbar.html | 7 +- server_py/requirements.txt | 1 + setup.py | 4 +- 26 files changed, 227 insertions(+), 32 deletions(-) create mode 100644 server_py/flatgov/about_us.json create mode 100644 server_py/flatgov/home/migrations/0001_initial.py create mode 100644 server_py/flatgov/templates/home/about.html 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\n

Flatgov 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\n

The 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\n

For example, similar or identical legislation is reintroduced every Congress. How do we identify those identical or similar bills when they reappear? 

\r\n\r\n

In 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\n

When 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\n

For example, if you can connect related legislation, you can gain important insights:

\r\n\r\n\r\n\r\n

The work to create Flatgov proceeded along several parallel tracks.

\r\n\r\n\r\n\r\n

We 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\n

Flatgov 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/', never_cache(views.BillListTitleAPIView.as_view()), name='bill-titles'), - path('bill-title//', never_cache(views.GetBillTitleAPIView.as_view()), name='bill-title'), + path('home/bill-list/', never_cache(views.BillListAPIView.as_view()), name='bill-list'), + path('home/bill-titles/', never_cache(views.BillListTitleAPIView.as_view()), name='bill-titles'), + path('home/bill-title//', never_cache(views.GetBillTitleAPIView.as_view()), name='bill-title'), ] urlpatterns += api_urlpatterns diff --git a/server_py/flatgov/home/views.py b/server_py/flatgov/home/views.py index cc45866..e7638ba 100644 --- a/server_py/flatgov/home/views.py +++ b/server_py/flatgov/home/views.py @@ -5,11 +5,13 @@ from django.http import HttpResponse, JsonResponse from django.db.models.functions import Concat from django.views import View +from django.views.generic import TemplateView from common.constants import START_CONGRESS, CURRENT_CONGRESS from home.forms import QueryForm from bills.models import Bill +from .models import AboutPage def index(request): return HttpResponse("Hello, world. You're at the home index.") @@ -31,6 +33,14 @@ def home_view(request): context = {'form': form, 'congressrange': list(reversed(list(range(START_CONGRESS, CURRENT_CONGRESS +1))))} return render(request, 'home/home.html', context) +class AboutView(TemplateView): + template_name = 'home/about.html' + + def get_context_data(self, **kwargs): + context = super(AboutView, self).get_context_data(**kwargs) + context['about'] = AboutPage.objects.first() + return context + class BillListAPIView(View): diff --git a/server_py/flatgov/static/css/style.css b/server_py/flatgov/static/css/style.css index 0ff1217..ead2186 100644 --- a/server_py/flatgov/static/css/style.css +++ b/server_py/flatgov/static/css/style.css @@ -289,6 +289,7 @@ span.twitter-typeahead .tt-suggestion:focus { /* Tooltip text */ /* See https://www.w3schools.com/css/css_tooltip.asp */ .toolt .tooltiptext { + font-size: 14px; visibility: hidden; width: 500px; background-color: rgb(165, 165, 165); diff --git a/server_py/flatgov/static/docs/BILL_MODEL.html b/server_py/flatgov/static/docs/BILL_MODEL.html index 68ef42d..6a44c2a 100644 --- a/server_py/flatgov/static/docs/BILL_MODEL.html +++ b/server_py/flatgov/static/docs/BILL_MODEL.html @@ -641,7 +641,7 @@ diff --git a/server_py/flatgov/static/docs/CRS_REPORTS.html b/server_py/flatgov/static/docs/CRS_REPORTS.html index b424523..a5ceddd 100644 --- a/server_py/flatgov/static/docs/CRS_REPORTS.html +++ b/server_py/flatgov/static/docs/CRS_REPORTS.html @@ -490,7 +490,7 @@

Collecting the data

diff --git a/server_py/flatgov/static/docs/DATABASE.html b/server_py/flatgov/static/docs/DATABASE.html index 5409bc1..6af0f42 100644 --- a/server_py/flatgov/static/docs/DATABASE.html +++ b/server_py/flatgov/static/docs/DATABASE.html @@ -454,6 +454,7 @@

Setting up the FlatGov db for Django

  • Create db migration
  • +
  • Load fixtures
  • Create billsMeta.json file via Django command.
  • Review Models with Django Admin
  • Review data from the Django shell
  • @@ -647,6 +648,20 @@

    Create db migration

    +

    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.

    @@ -748,7 +763,7 @@

    Review data from the Django shell diff --git a/server_py/flatgov/static/docs/DATA_BACKGROUND.html b/server_py/flatgov/static/docs/DATA_BACKGROUND.html index 6e6ca91..8c5d645 100644 --- a/server_py/flatgov/static/docs/DATA_BACKGROUND.html +++ b/server_py/flatgov/static/docs/DATA_BACKGROUND.html @@ -847,7 +847,7 @@

    Committee Documents

    diff --git a/server_py/flatgov/static/docs/DEPLOYMENT.html b/server_py/flatgov/static/docs/DEPLOYMENT.html index 23afbfe..d94de6e 100644 --- a/server_py/flatgov/static/docs/DEPLOYMENT.html +++ b/server_py/flatgov/static/docs/DEPLOYMENT.html @@ -1157,7 +1157,7 @@

    Provide sudoer

    diff --git a/server_py/flatgov/static/docs/ES_SIMILARITY.html b/server_py/flatgov/static/docs/ES_SIMILARITY.html index 0f0de0e..c917635 100644 --- a/server_py/flatgov/static/docs/ES_SIMILARITY.html +++ b/server_py/flatgov/static/docs/ES_SIMILARITY.html @@ -664,7 +664,7 @@

    Install Logstash

    diff --git a/server_py/flatgov/static/docs/README.html b/server_py/flatgov/static/docs/README.html index 4ba5bec..4ff1320 100644 --- a/server_py/flatgov/static/docs/README.html +++ b/server_py/flatgov/static/docs/README.html @@ -908,7 +908,7 @@

    Relevant Committee Documents

    diff --git a/server_py/flatgov/static/docs/SCRAPING.html b/server_py/flatgov/static/docs/SCRAPING.html index e5fd193..c10a127 100644 --- a/server_py/flatgov/static/docs/SCRAPING.html +++ b/server_py/flatgov/static/docs/SCRAPING.html @@ -761,7 +761,7 @@

    Relevant Committee Documents

    diff --git a/server_py/flatgov/static/docs/UPDATES_CELERY.html b/server_py/flatgov/static/docs/UPDATES_CELERY.html index 6fb0a31..7c19fbc 100644 --- a/server_py/flatgov/static/docs/UPDATES_CELERY.html +++ b/server_py/flatgov/static/docs/UPDATES_CELERY.html @@ -984,7 +984,7 @@

    Statements of Administration Polic diff --git a/server_py/flatgov/static/docs/USCONGRESS_SCRAPER.html b/server_py/flatgov/static/docs/USCONGRESS_SCRAPER.html index 442f6e7..2b58fa5 100644 --- a/server_py/flatgov/static/docs/USCONGRESS_SCRAPER.html +++ b/server_py/flatgov/static/docs/USCONGRESS_SCRAPER.html @@ -545,7 +545,7 @@

    Initialize data for Congresse diff --git a/server_py/flatgov/static/docs/index.html b/server_py/flatgov/static/docs/index.html index 1c43b56..29e7d07 100644 --- a/server_py/flatgov/static/docs/index.html +++ b/server_py/flatgov/static/docs/index.html @@ -644,7 +644,7 @@

    Legislative Calendar

    diff --git a/server_py/flatgov/templates/bills/detail.html b/server_py/flatgov/templates/bills/detail.html index b3dc8bc..6e8b6e4 100644 --- a/server_py/flatgov/templates/bills/detail.html +++ b/server_py/flatgov/templates/bills/detail.html @@ -38,35 +38,34 @@
    Bill Summary:
    {% else %}
    {{ bill.summary |truncatewords_html:100 }}
    {% endif %} - + {% if bill.get_related_bill_numbers %}
    Related Bills:
    {% for rel_bill in bill.get_related_bill_numbers|billnumbers_by_congress:bill.congress|billnumbers_display %} -
    ...
    {{rel_bill}}
    {% if not forloop.last %}, {% endif %} +
    ...
    {{rel_bill}}
    {% if not forloop.last %}, {% endif %} {% endfor %} {% endif %} - -
    Recent Actions (in focus):
    -

    NA

    +
    Recent Actions (in focus):
    +

    No info available

    Prognosis:

    Prognosis will appear here

    - +
    -

    Committees and Cosponsors

    +

    Committees and Sponsors


    -
    Committees of Jurisdiction:
    +
    Committees
    of Jurisdiction:
    {% for committeeItem in committees_dict_deduped %} {{committeeItem.committee}}{% if not forloop.last %}, {% endif %} {% endfor %} diff --git a/server_py/flatgov/templates/home/about.html b/server_py/flatgov/templates/home/about.html new file mode 100644 index 0000000..8e83965 --- /dev/null +++ b/server_py/flatgov/templates/home/about.html @@ -0,0 +1,20 @@ +{% extends 'base.html' %} + +{% block content %} + +
    +
    +
    +

    About us

    +
    + {{ about.content|safe }} +
    +
    + +
    + +{% endblock content %} \ No newline at end of file diff --git a/server_py/flatgov/templates/navbar.html b/server_py/flatgov/templates/navbar.html index cbe0fc2..9112a80 100644 --- a/server_py/flatgov/templates/navbar.html +++ b/server_py/flatgov/templates/navbar.html @@ -2,6 +2,9 @@ {% load rest_framework %} {% load render_attrs %} +{% url '/home' as home_path %} +{% url '/about' as about_path %} +