Django and React project to manage receipts and reimbursements at Datasektionen
Python JavaScript CSS HTML
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.idea
cashflow
documents
expenses
public
src
.gitignore
README.md
manage.py
package.json
requirements.txt

README.md

Cashflow 2.0

Django and React project to manage receipts and reimbursements at Datasektionen.

Setup

pip install -r requirements.txt
npm install

Run

The following environment variables are required to run the project:

Variable Description Default
DB_HOST PostgreSQL server hostname localhost
DB_NAME PostgreSQL database cashflow
DB_USER PostgreSQL username postgres
DB_PASS PostgreSQL password postgres
DB_PORT PostgreSQL port 5432
DEBUG Django debug mode False
SECRET_KEY Django encryption key ---
LOGIN2_KEY Login2 API key for KTH authentication ---
S3_BUCKET_NAME Amazon AWS s3 bucket name ---
S3_ACCESS_KEY_ID Amazon AWS IAM access key id ---
S3_SECRET_ACCESS_KEY Amazon AWS IAM secret access key ---
S3_USE_SIGV4 If Frankfurt, set to False True
S3_HOST Login2 API key for KTH authentication s3.eu-central-1.amazonaws.com
REDIS_URL Url to a redis-server redis://localhost:6379

When running the project, you have two options for the frontend. Django is configured to look for index.html and the static files in the build directory, which is generated by npm run build.

However, for the best React development experience, you can use React's dev server by running npm start. Just make sure you've hit /on the Django server to start a session first (the frontend assumes you're logged in since this the behavior in production.)

After running npm run build, start Django with the required environment variables through manage.py runserver 8000.

API documentation

Creating a new expense

Method: PUT
URL: /api/expense/new/

Request: json:

{

}

Updating expense

Method: PUT
URL: /api/expense/<id>/

Getting expense by id

Method: GET
URL: /api/expense/<id>/

Get a expense by its id, also retrieves expense_parts and budget_lines associated with the expense.


Response:

{
   "expense":{
      "owner_first_name":"John",
      "reimbursement":null,
      "description":"Foo",
      "owner_last_name":"Doe",
      "expense_date":"2017-03-05",
      "verification":"E231",
      "expense_parts":[
         {
            "budget_line":{
               "budget_line_name":"mat",
               "cost_centre":{
                  "cost_centre_name":"dwrek",
                  "committee":{
                     "committee_name":"Drek",
                     "committee_id":1
                  },
                  "cost_centre_id":2
               },
               "budget_line_id":3
            },
            "attest_date":"2017-03-06",
            "amount":12,
            "attested_by":"foba",
            "id":5
         }
      ],
      "owner":2,
      "id":1,
      "owner_username":"johdo"
   }
}

Getting all expenses

Method: GET
URL: /api/expense/

Retrieves all expenses current user is elegible to view

Responese:

{
    "expenses": [<List of expenses>]
}

Getting all expenses belonging to user

Method: GET
URL: /api/user/<username>/expenses/

Retrieves all expenses belonging to the user with the specified kthid/username.

Responese:

{
    "expenses": [<List of expenses>]
}

Get all unattested expenses

Method: GET
URL: /api/attest/

Retrieves all the expenses that the current user can attest that haven't been attested yet.

Responese:

{"expenses": [<List of expenses>]

Attest expenses

Method: POST
URL: /api/attest/

Attest all the specified reciepts

Request: list:

[1,22,23,12]

Response:

{
  'success': true
}

Get current user

Method: GET
URL: /api/user/

Get the currently logged in

Response:

{
   "user":{
      "username":"foba",
      "bank_name":"Swedbank",
      "first_name":"Foo",
      "last_name":"Bar",
      "sorting_number":"2322-1",
      "default_account":{
         "id":1,
         "name":"DKM"
      },
      "bank_account":"2131231231"
   }
}

Get user

Method: GET
URL: /api/user/<username>/

Get a user by its kthid/username

Response:

{
   "user":{
      "username":"foba",
      "bank_name":"Swedbank",
      "first_name":"Foo",
      "last_name":"Bar",
      "sorting_number":"2322-1",
      "default_account":{
         "id":1,
         "name":"DKM"
      },
      "bank_account":"2131231231"
   }
}

Get budget

Method: GET
URL: /api/budget/

Response:

{
   "committees":[
      {
         "committee_name":"D-rektoratet",
         "committee_id":1,
         "cost_centres":[
            {
               "cost_centre_name":"Allmänt",
               "cost_centre_id":1,
               "budget_lines":[
                  {
                     "budget_line_name":"MUTA",
                     "budget_line_id":1
                  },
                  {
                     "budget_line_name":"Representation",
                     "budget_line_id":2
                  }
               ]
            }
         ]
      }
   ]
}