-
Notifications
You must be signed in to change notification settings - Fork 2
Updates to portal #1
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
JakeNeyer
wants to merge
2
commits into
code-for-charlottesville:main
Choose a base branch
from
JakeNeyer:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| from django.core.management.base import BaseCommand | ||
| import random | ||
| from address.models import Address, Locality, State, Country | ||
|
|
||
| from logging import getLogger | ||
|
|
||
| from models.models import ( | ||
| Customer, | ||
| CustomerRecord, | ||
| Payment | ||
| ) | ||
|
|
||
|
|
||
| log = getLogger(__name__) | ||
|
|
||
| # python manage.py seed --mode=refresh | ||
|
|
||
| """ Clear all data and creates cusotmers """ | ||
| MODE_REFRESH = 'refresh' | ||
|
|
||
| """ Clear all data and do not create any object """ | ||
| MODE_CLEAR = 'clear' | ||
|
|
||
| class Command(BaseCommand): | ||
| help = "seed database for testing and development." | ||
|
|
||
| def add_arguments(self, parser): | ||
| parser.add_argument('--mode', type=str, help="Mode") | ||
|
|
||
| def handle(self, *args, **options): | ||
| self.stdout.write('seeding data...') | ||
| run_seed(self, options['mode']) | ||
| self.stdout.write('done.') | ||
|
|
||
|
|
||
| def clear_data(): | ||
| """Deletes all the table data""" | ||
| log.info("Deleting customers") | ||
| Customer.objects.all().delete() | ||
| CustomerRecord.objects.all().delete() | ||
|
|
||
|
|
||
| def create_customer(local, payment_types): | ||
| """Creates an customer object combining different elements from the list""" | ||
| log.info("Creating customer") | ||
|
|
||
| active_options = [True, False] | ||
| first_name_options = ["Bob", "Jane", "Joe", "Hank", "Jill", "Tom", "Alice"] | ||
| last_name_options = ["Smith", "Adams", "Thompson", "Berry", "Phillips"] | ||
|
|
||
|
|
||
| a = Address( | ||
| street_number="1", | ||
| route="Some Street", | ||
| locality=local, | ||
| raw="1 Some Street, Charlottesvile, VA" | ||
| ) | ||
| a.save() | ||
|
|
||
| c = Customer( | ||
| active=random.choice(active_options), | ||
| first_name=random.choice(first_name_options), | ||
| last_name=random.choice(last_name_options), | ||
| address=a | ||
| ) | ||
| c.save() | ||
|
|
||
|
|
||
| cr = CustomerRecord( | ||
| customer=c, | ||
| num_meals=1, | ||
| payment_type=random.choice(payment_types) | ||
| ) | ||
| cr.save() | ||
|
|
||
| log.info("{} customer created.".format(c)) | ||
| return c | ||
|
|
||
| def run_seed(self, mode): | ||
| """ Seed database based on mode | ||
|
|
||
| :param mode: refresh / clear | ||
| :return: | ||
| """ | ||
| # Clear data from tables | ||
| clear_data() | ||
| if mode == MODE_CLEAR: | ||
| return | ||
|
|
||
| payment_types = [] | ||
|
|
||
| try: | ||
| country = Country(name="US") | ||
| country.save() | ||
| state = State(name="VA", country=country) | ||
| state.save() | ||
| local = Locality(name="Charlottesville", postal_code="22911", state=state) | ||
| local.save() | ||
| except: | ||
| local = Locality.objects.first() | ||
|
|
||
| try: | ||
| p1 = Payment(name="debit") | ||
| p1.save() | ||
| p2 = Payment(name="credit") | ||
| p2.save() | ||
| p3 = Payment(name="cash") | ||
| p3.save() | ||
|
|
||
| payment_types = [p1,p2,p3] | ||
| except: | ||
| payment_types = Payment.objects.all() | ||
|
|
||
|
|
||
| # Creating 30 customers | ||
| for i in range(30): | ||
| try: | ||
| create_customer(local,payment_types) | ||
| except: | ||
| pass | ||
35 changes: 35 additions & 0 deletions
35
src/models/migrations/0034_volunteer_end_date_volunteer_end_reason.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Generated by Django 4.0.4 on 2024-08-11 00:44 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| def set_default_values(apps, schema_editor): | ||
| Volunteer = apps.get_model('models', 'volunteer') | ||
| db_alias = schema_editor.connection.alias | ||
|
|
||
| Volunteer.objects.update(active=True) | ||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('models', '0033_alter_route_bonusroute'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name='volunteer', | ||
| name='end_date', | ||
| field=models.DateField(blank=True, null=True), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='volunteer', | ||
| name='end_reason', | ||
| field=models.TextField(blank=True, default=''), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='volunteer', | ||
| name='active', | ||
| field=models.BooleanField(default=True), | ||
| ), | ||
| migrations.RunPython(set_default_values), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing wrong with this, but I think we do have some sample data, it just doesn't have a nice wrapper around if you were looking for something else!