Skip to content
This repository has been archived by the owner on Sep 3, 2022. It is now read-only.

Commit

Permalink
Front end base (#24)
Browse files Browse the repository at this point in the history
Summary of changes:
- Instructions for setting up a SQLite database
- Settings files for development and production
- Add admin view to create Petition and Tag objects
- Basic index page, closes #12 
- Base for create petition page
- Small changes to model and static files
  • Loading branch information
garoller committed Mar 6, 2019
1 parent f0439e6 commit a577ed9
Show file tree
Hide file tree
Showing 32 changed files with 810 additions and 58 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Expand Up @@ -2,3 +2,9 @@ petitions-env/
conf.json
__pycache__
*/__pycache__
.vscode
*.sh
*.OTF
*.otf
petitions/settings.py
mydatabase
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -12,6 +12,7 @@ env:
global:
- PIPENV_IGNORE_VIRTUALENVS=1
- SECRET_KEY='sosecret'
- DJANGO_SETTINGS_MODULE='petitions.settings.dev'

before_install:
- pip install pipenv
Expand Down
2 changes: 2 additions & 0 deletions Pipfile
Expand Up @@ -8,5 +8,7 @@ verify_ssl = true
[packages]
django = "~=2.1"
black = "==18.9b0"
dj-database-url = "*"
psycopg2 = "*"

[requires]
46 changes: 45 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 37 additions & 16 deletions README.md
@@ -1,35 +1,58 @@
Check the [Wiki](https://github.com/wtg/petitions-rewrite/wiki) for Django references and more documentation.

#### Installation:

1. Clone the repository and switch into the new directory:
```
git clone https://github.com/wtg/petitions-rewrite.git
cd petitions-rewrite
```
```
git clone https://github.com/wtg/petitions-rewrite.git
cd petitions-rewrite
```

2. Install the python 3.6 or greater
```sudo apt install python<python_version> python3-pip -y```
```
sudo apt install python<python_version> python3-pip -y
```

3. Install [pipenv](https://pipenv.readthedocs.io/en/latest/)

4. Create pipenv with python 3.6 or greater and install dependencies
```
pipenv install --python <python_version>
```
```
pipenv install --python <python_version>
```

5. Activate the virtual environment ```pipenv shell```

6. Set a secret key environment variable
```
export SECRET_KEY="any string will work for development"
```
```
export SECRET_KEY="any string will work for development"
```

7. Run the site: ```python manage.py runserver```
Navigate to http://127.0.0.1:8000 to view
7. Set up the local database

* Install [SQLite](https://www.sqlite.org/) for your operating system.

* Set the `DJANGO_SETTINGS_MODULE` environment variable to use the settings file for development (petitions/settings/dev.py):
```
export DJANGO_SETTINGS_MODULE='petitions.settings.dev'
```

* Make migrations:
```
python manage.py makemigrations index
python manage.py migrate
```

* Add an admin user - `python manage.py createsuperuser`

7. Run the site:
```
python manage.py runserver
```
Navigate to http://localhost:8000 to view. Go to http://localhost:8000/admin to add test data.

#### Making changes:

The code formatter, [Python Black](https://black.readthedocs.io/en/stable/) is now enforced on Travis builds.

To format one file, run
```
black <path to file>
Expand All @@ -39,5 +62,3 @@ or to format all python files your current directory, run
black .
```
Then commit and push any changed files.

Check the [Wiki](https://github.com/wtg/petitions-rewrite/wiki) for Django references and more documentation.
13 changes: 12 additions & 1 deletion index/admin.py
@@ -1,3 +1,14 @@
from django.contrib import admin
from .models import Tag, Petition

# Register your models here.

class TagAdmin(admin.ModelAdmin):
pass


class PetitionAdmin(admin.ModelAdmin):
pass


admin.site.register(Tag, TagAdmin)
admin.site.register(Petition, PetitionAdmin)
4 changes: 4 additions & 0 deletions index/apps.py
Expand Up @@ -3,3 +3,7 @@

class IndexConfig(AppConfig):
name = "index"


class ViewAllConfig(AppConfig):
name = "view_all"
13 changes: 13 additions & 0 deletions index/forms.py
@@ -0,0 +1,13 @@
# from django.forms import ModelForm
from django import forms
from .models import Petition, Tag


class CreatePetitionForm(forms.ModelForm):
tags = forms.ModelMultipleChoiceField(
widget=forms.CheckboxSelectMultiple, queryset=Tag.objects.all(), required=True
)

class Meta:
model = Petition
fields = ["title", "description", "tags"]
149 changes: 149 additions & 0 deletions index/migrations/0001_initial.py
@@ -0,0 +1,149 @@
# Generated by Django 2.1.1 on 2019-02-15 01:22

import datetime
from django.db import migrations, models
import django.db.models.deletion
from django.utils.timezone import utc


class Migration(migrations.Migration):

initial = True

dependencies = []

operations = [
migrations.CreateModel(
name="Petition",
fields=[
("title", models.CharField(max_length=200)),
("description", models.CharField(max_length=4000)),
(
"ID",
models.IntegerField(
primary_key=True, serialize=False, verbose_name=999999
),
),
("archived", models.BooleanField(default=False)),
("hidden", models.BooleanField(default=False)),
(
"created_date",
models.DateTimeField(
db_index=True,
default=datetime.datetime(
2019, 2, 15, 1, 22, 11, 359671, tzinfo=utc
),
),
),
("expected_sig", models.IntegerField(verbose_name=300)),
],
),
migrations.CreateModel(
name="Response",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("senator_investigation", models.BooleanField(default=False)),
("committee_formed", models.BooleanField(default=False)),
("vote_resolution", models.BooleanField(default=False)),
("vote_referendum", models.BooleanField(default=False)),
("refer_to_other", models.BooleanField(default=False)),
("investigation_info", models.CharField(max_length=1000)),
("committee_info", models.CharField(max_length=1000)),
("resolution_info", models.CharField(max_length=1000)),
("referendum_info", models.CharField(max_length=1000)),
("refer_other_info", models.CharField(max_length=1000)),
],
),
migrations.CreateModel(
name="Signature",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"signed_date",
models.DateTimeField(
default=datetime.datetime(
2019, 2, 15, 1, 22, 11, 358683, tzinfo=utc
)
),
),
],
),
migrations.CreateModel(
name="Tag",
fields=[
(
"label",
models.CharField(max_length=15, primary_key=True, serialize=False),
)
],
),
migrations.CreateModel(
name="User",
fields=[
(
"rcs_id",
models.CharField(max_length=10, primary_key=True, serialize=False),
),
("name", models.CharField(max_length=50)),
("admin", models.BooleanField(default=False)),
("banned", models.BooleanField(default=False)),
("initials", models.CharField(max_length=2)),
("union_member", models.BooleanField(default=False)),
],
),
migrations.AddField(
model_name="signature",
name="signer",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="signatures",
to="index.User",
),
),
migrations.AddField(
model_name="petition",
name="author",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="petitions",
to="index.User",
),
),
migrations.AddField(
model_name="petition",
name="senate_response",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="petitions",
to="index.Response",
),
),
migrations.AddField(
model_name="petition",
name="signatures",
field=models.ManyToManyField(
related_name="petitions", to="index.Signature"
),
),
migrations.AddField(
model_name="petition",
name="tags",
field=models.ManyToManyField(related_name="petitions", to="index.Tag"),
),
]
28 changes: 28 additions & 0 deletions index/migrations/0002_auto_20190215_0130.py
@@ -0,0 +1,28 @@
# Generated by Django 2.1.1 on 2019-02-15 01:30

import datetime
from django.db import migrations, models
from django.utils.timezone import utc


class Migration(migrations.Migration):

dependencies = [("index", "0001_initial")]

operations = [
migrations.AlterField(
model_name="petition",
name="created_date",
field=models.DateTimeField(
db_index=True,
default=datetime.datetime(2019, 2, 15, 1, 30, 44, 768987, tzinfo=utc),
),
),
migrations.AlterField(
model_name="signature",
name="signed_date",
field=models.DateTimeField(
default=datetime.datetime(2019, 2, 15, 1, 30, 44, 767805, tzinfo=utc)
),
),
]

0 comments on commit a577ed9

Please sign in to comment.