Skip to content

Commit

Permalink
Merge branch 'development' into pytype-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
cweitat committed May 23, 2023
2 parents 5b5b390 + 5ca3f9c commit 82cfccd
Show file tree
Hide file tree
Showing 144 changed files with 32,774 additions and 4,560 deletions.
34 changes: 18 additions & 16 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ version: 2
jobs:
dependencies:
docker:
- image: circleci/python:3.8.6-node
- image: quay.io/quan/circleci-python:py3.9
environment:
PIP_EXTRA_INDEX_URL: https://pypi.fury.io/fossasia/

working_directory: ~/code

Expand All @@ -12,16 +14,16 @@ jobs:
# Download and cache dependencies
- restore_cache:
keys:
- v1.5-dependencies-{{ checksum "poetry.lock" }}-{{ checksum "package.json" }}
- v1.5.1-dependencies-{{ checksum "poetry.lock" }}-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1.5-dependencies-
- v1.5.1-dependencies-

- run:
name: Install Python Dependencies
command: |
python3 -m venv venv
. venv/bin/activate
poetry install
poetry export -f requirements.txt --without-hashes --with dev | pip install -r /dev/stdin
- run:
name: Install Node Dependencies
Expand All @@ -33,11 +35,11 @@ jobs:
- ./node_modules
- ~/.cache/yarn
- ~/.yarn/bin
key: v1.5-dependencies-{{ checksum "poetry.lock" }}-{{ checksum "package.json" }}
key: v1.5.1-dependencies-{{ checksum "poetry.lock" }}-{{ checksum "package.json" }}

dredd:
docker:
- image: circleci/python:3.8.6-node
- image: quay.io/quan/circleci-python:py3.9
environment:
APP_CONFIG: config.TestingConfig
DATABASE_URL: postgresql://postgres@localhost/test
Expand All @@ -58,9 +60,9 @@ jobs:
# Download and cache dependencies
- restore_cache:
keys:
- v1.5-dependencies-{{ checksum "poetry.lock" }}-{{ checksum "package.json" }}
- v1.5.1-dependencies-{{ checksum "poetry.lock" }}-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1.5-dependencies-
- v1.5.1-dependencies-

- run:
name: Create API blueprint
Expand All @@ -80,7 +82,7 @@ jobs:

pytype:
docker:
- image: circleci/python:3.8.6-node
- image: quay.io/quan/circleci-python:py3.9

working_directory: ~/code

Expand All @@ -90,17 +92,17 @@ jobs:
# Download and cache dependencies
- restore_cache:
keys:
- v1.5-dependencies-{{ checksum "poetry.lock" }}-{{ checksum "package.json" }}
- v1.5.1-dependencies-{{ checksum "poetry.lock" }}-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1.5-dependencies-
- v1.5.1-dependencies-

- restore_cache:
keys:
- v1-pytype

- run:
name: Test pytype
command: . venv/bin/activate && pytype
command: ./venv/bin/pytype

- run:
command: ls -alR .pytype/ | md5sum > requirements/pytype.txt
Expand All @@ -112,7 +114,7 @@ jobs:

test:
docker:
- image: circleci/python:3.8.6-node
- image: quay.io/quan/circleci-python:py3.9
environment:
APP_CONFIG: config.TestingConfig
DATABASE_URL: postgresql://postgres@localhost/test
Expand All @@ -134,9 +136,9 @@ jobs:
# Download and cache dependencies
- restore_cache:
keys:
- v1.5-dependencies-{{ checksum "poetry.lock" }}-{{ checksum "package.json" }}
- v1.5.1-dependencies-{{ checksum "poetry.lock" }}-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1.5-dependencies-
- v1.5.1-dependencies-

- run:
name: Test
Expand All @@ -150,7 +152,7 @@ jobs:
path: test-results

- store_artifacts:
path: test-results
path: test-results

- run:
name: Upload Coverage
Expand Down
19 changes: 19 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 2
updates:
- package-ecosystem: pip
directory: "/"
schedule:
interval: daily
time: "21:00"
open-pull-requests-limit: 10
ignore:
- dependency-name: cryptography
versions:
- "> 3.3.2, < 4"
- dependency-name: sqlalchemy
versions:
- "> 1.3.23, < 2"
- dependency-name: flask-jwt-extended
versions:
- 4.0.2
- 4.1.0
40 changes: 24 additions & 16 deletions .github/workflows/docker-hub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,37 @@ jobs:
runs-on: ubuntu-latest
steps:
-
name: Login to DockerHub
# The job will terminate early if Docker Hub credentials is not set.
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
name: Checkout
uses: actions/checkout@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2
-
name: Docker meta
uses: docker/metadata-action@v3
uses: docker/metadata-action@v4
id: meta
with:
images: eventyay/open-event-server
images: |
eventyay/open-event-server
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
-
name: Build
id: docker_build
uses: docker/build-push-action@v2
name: Login to Docker Hub
uses: docker/login-action@v2
with:
push: true
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
-
name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/hadialqattan/pycln
rev: 0.0.1
rev: v1.1.0
hooks:
- id: pycln
args: [--config=pyproject.toml]
Expand Down
21 changes: 11 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,30 @@ FROM base as builder

RUN apk update && \
apk add --virtual build-deps make git g++ python3-dev musl-dev jpeg-dev zlib-dev libevent-dev file-dev libffi-dev openssl && \
apk add postgresql-dev
apk add postgresql-dev libxml2-dev libxslt-dev
# PDF Generation: weasyprint (libffi-dev jpeg-dev already included above)
RUN apk add --virtual gdk-pixbuf-dev

RUN apk --no-cache add postgresql-libs ca-certificates libxslt jpeg zlib file libxml2
# PDF Generation: weasyprint
RUN apk --no-cache add cairo-dev pango-dev ttf-opensans

# Note: The custom PyPI repo is for AlpineOS only, where Python packages are compiled with musl libc. Don't use it on glibc Linux.
ENV POETRY_HOME=/opt/poetry \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_NO_INTERACTION=1

POETRY_NO_INTERACTION=1 \
PIP_EXTRA_INDEX_URL=https://pypi.fury.io/fossasia/

ENV PATH="$POETRY_HOME/bin:$PATH"

RUN set -eo pipefail; wget -O - https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
RUN set -eo pipefail; wget -O - https://install.python-poetry.org | python -

WORKDIR /opt/pysetup

COPY pyproject.toml ./
COPY poetry.lock ./

RUN poetry install --no-root --no-dev
RUN poetry export -f requirements.txt --without-hashes --only main | poetry run pip install -r /dev/stdin

####

Expand All @@ -33,11 +39,6 @@ COPY --from=builder /opt/pysetup/.venv /opt/pysetup/.venv

ENV PATH="/opt/pysetup/.venv/bin:$PATH"

RUN apk --no-cache add postgresql-libs ca-certificates libxslt jpeg zlib file libxml2
# PDF Generation: weasyprint
RUN apk --no-cache add cairo-dev pango-dev ttf-opensans
RUN fc-cache -f

WORKDIR /data/app
ADD . .
RUN ["sh", "scripts/l10n.sh", "generate"]
Expand Down
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Open Event Server test
# Open Event Server

![Open Event Server](/docs/images/open-event-server.png)

[![GitHub release](https://img.shields.io/github/release/fossasia/open-event-server.svg)](https://github.com/fossasia/open-event-server/releases/latest)
[![Build Status](https://travis-ci.org/fossasia/open-event-server.svg?branch=development)](https://travis-ci.org/fossasia/open-event-server)
[![CircleCI Build Staus Badge](https://img.shields.io/circleci/build/github/fossasia/open-event-server?label=CircleCI%20Build)](https://www.circleci.com/gh/fossasia/open-event-server)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/1ac554483fac462797ffa5a8b9adf2fa?style=flat-square)](https://www.codacy.com/app/fossasia/open-event-server)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/f5036c0e23b44270ad24397e338b8412)](https://www.codacy.com/gh/fossasia/open-event-server/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=fossasia/open-event-server&amp;utm_campaign=Badge_Grade)
[![Codecov branch](https://codecov.io/gh/fossasia/open-event-server/branch/development/graph/badge.svg?style=flat-square)](https://codecov.io/gh/fossasia/open-event-server)
[![Gitter](https://img.shields.io/badge/chat-on%20gitter-ff006f.svg?style=flat-square)](https://gitter.im/fossasia/open-event-server)
[![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)
Expand Down Expand Up @@ -41,14 +41,7 @@ A demo version is automatically deployed from our repositories:
The Open Event Server can be easily deployed on a variety of platforms. Detailed platform-specific installation instructions have been provided below.


**NOTE:** If you are heading towards `Local Installation`, be sure to use one of the following operating systems:


* Debian based Linux Distros (like Ubuntu)
* MacOS

1. [Generic Installation Instructions](/docs/installation/basic.md)
1. [Local Installation](/docs/installation/local.md)
1. [Installation Instructions](/docs/installation/basic.md)
1. [Vagrant Installation](/docs/installation/vagrant.md)
1. [Deployment on Google Compute Engine](/docs/installation/google.md)
1. [Deployment on Google Container Engine (Kubernetes)](/docs/installation/gce-kubernetes.md)
Expand Down Expand Up @@ -206,7 +199,7 @@ Clone the repo and set up the server according to the steps listed. Make sure yo

```
# Install Poetry
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
curl -sSL https://install.python-poetry.org | python -
source ~/.profile
# Install Python dependencies
Expand Down Expand Up @@ -250,6 +243,20 @@ robot -v SERVER:localhost:5000 -v SUPERUSER_USERNAME:test@opev.net -v SUPERUSER_
```
* Once the tests are completed, a report and a log would be generated at `report.html` and `log.html` respectively in your root directory.

### Pre-commits guide

Git hook scripts are useful for identifying simple issues before submission to code review.

#### Install the git hook scripts:
* run pre-commit install to set up the git hook scripts
```sh
$ pre-commit install
pre-commit installed at .git/hooks/pre-commit
```
* now pre-commit will run automatically on git commit!

#### For configuration, [Click Here](https://pre-commit.com/)

## Logging

Certain information is being logged and stored in the database for future reference, resolving conflicts in case of hacks and for maintaining an overview of the system. Read more about [logging here](/docs/general/logs.md).
Expand All @@ -264,7 +271,6 @@ If you would like to contribute to the translation of Open Event, you need to [r

Once you have activated your account just proceed to the [translation section](https://hosted.weblate.org/projects/open-event/).


## Contributions, Bug Reports, Feature Requests

This is an Open Source project and we would be happy to see contributors who report bugs and file feature requests submitting pull requests as well. Please report issues here https://github.com/fossasia/open-event-server/issues. It is also recommended to go through the [developer handbook](https://github.com/fossasia/open-event/tree/master/docs/dev-handbook) in order to get a basic understanding of the ecosystem.
Expand Down
45 changes: 29 additions & 16 deletions app/api/admin_sales/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from app.api.admin_sales.utils import summary
from app.api.bootstrap import api
from app.api.helpers.db import save_to_db
from app.api.helpers.utilities import dasherize
from app.models import db
from app.models.event import Event
Expand Down Expand Up @@ -33,34 +34,30 @@ class Meta:
ends_at = fields.DateTime()
payment_currency = fields.String()
payment_country = fields.String()
completed_order_sales = fields.Integer(dump_only=True)
placed_order_sales = fields.Integer(dump_only=True)
pending_order_sales = fields.Integer(dump_only=True)
completed_order_tickets = fields.Integer(dump_only=True)
placed_order_tickets = fields.Integer(dump_only=True)
pending_order_tickets = fields.Integer(dump_only=True)
type = fields.Method('event_type')
owner = fields.Method('event_owner')
owner_id = fields.Method('event_owner_id')
sales = fields.Method('calc_sales')

@staticmethod
def calc_sales(obj):
"""
Returns sales (dictionary with total sales and ticket count) for
placed, completed and pending orders
"""
return summary(obj)

def event_owner(self, obj):
return str(obj.owner.email)

def event_owner_id(self, obj):
return obj.owner.id


def event_type(self, obj):
t = 'To be announced'
if(obj.online):
if(obj.location_name):
t='Hybrid'
if obj.online:
if obj.location_name:
t = 'Hybrid'
else:
t='Online'
elif(obj.location_name):
t = 'Online'
elif obj.location_name:
t = 'Venue'
return str(t)

Expand All @@ -74,7 +71,23 @@ class AdminSalesByEventsList(ResourceList):
def query(self, _):
return Event.query

def before_get(self, args, kwargs):
events = Event.query.all()
for event in events:
sales = summary(event)
event.completed_order_sales = sales['completed']['sales_total']
event.placed_order_sales = sales['placed']['sales_total']
event.pending_order_sales = sales['pending']['sales_total']
event.completed_order_tickets = sales['completed']['ticket_count']
event.placed_order_tickets = sales['placed']['ticket_count']
event.pending_order_tickets = sales['pending']['ticket_count']
save_to_db(event)

methods = ['GET']
decorators = (api.has_permission('is_admin'),)
schema = AdminSalesByEventsSchema
data_layer = {'model': Event, 'session': db.session, 'methods': {'query': query}}
data_layer = {
'model': Event,
'session': db.session,
'methods': {'query': query, 'before_get': before_get},
}
Loading

0 comments on commit 82cfccd

Please sign in to comment.