Skip to content

Add dummy data for development #5

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

Merged
merged 21 commits into from
Jan 26, 2025
Merged
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
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ This is a Django 4.2 application backed by PostgreSQL and running on Python 3.x.

### Ubuntu instructions

#### Install Dependencies / Configure Environment

First, prepare your development environment by installing pip, virtualenv, and postgresql-server-dev-X.Y.

```bash
Expand Down Expand Up @@ -45,12 +47,24 @@ be provided.
./manage.py migrate
```

You'll need either a database dump of the actual server's data or else to create a superuser:
#### Load data
For a quick start, you can load some dummy data into the database. Here's how you do that:

```
./manage.py loaddata auth_data.json
./manage.py loaddata commitfest_data.json
```

If you do this, the admin username and password are `admin` and `admin`.

On the other hand, if you'd like to start from scratch instead, you can run the following command to create
a super user:

```bash
./manage.py createsuperuser
```

#### Start application
Finally, you're ready to start the application:

```bash
Expand All @@ -69,3 +83,11 @@ codestyle.
ln -s ../../tools/githook/pre-commit .git/hooks/

```

If you'd like to regenerate the database dump files, you can run the following commands:
```
./manage.py dumpdata auth --format=json --indent=4 --exclude=auth.permission > pgcommitfest/commitfest/fixtures/auth_data.json
./manage.py dumpdata commitfest --format=json --indent=4 > pgcommitfest/commitfest/fixtures/commitfest_data.json
```

If you want to reload data from dump file, you can run `drop owned by postgres;` in the `pgcommitfest` database first.
20 changes: 20 additions & 0 deletions pgcommitfest/commitfest/ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import requests
import json
import textwrap
import re

from pgcommitfest.auth import user_search
from .models import CommitFest, Patch, MailThread, MailThreadAttachment
Expand All @@ -23,7 +24,26 @@ class Http503(Exception):
pass


def mockArchivesAPI(path):
with open(settings.MOCK_ARCHIVE_DATA, 'r', encoding='utf-8') as file:
data = json.load(file)
for message in data:
message['atts'] = []

message_pattern = re.compile(r"^/message-id\.json/(?P<message_id>[^/]+)$")

message_match = message_pattern.match(path)
if message_match:
message_id = message_match.group("message_id")
return [message for message in data if message['msgid'] == message_id]
else:
return data


def _archivesAPI(suburl, params=None):
if getattr(settings, 'MOCK_ARCHIVES', False) and getattr(settings, 'MOCK_ARCHIVE_DATA'):
return mockArchivesAPI(suburl)

try:
resp = requests.get(
"http{0}://{1}:{2}{3}".format(settings.ARCHIVES_PORT == 443 and 's' or '',
Expand Down
Loading