Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #111 from match4everyone/cleanup
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
Baschdl authored Jul 11, 2020
2 parents 7b1582f + 2109662 commit 345a92f
Show file tree
Hide file tree
Showing 29 changed files with 66 additions and 61 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# match4everyone
[![Documentation Status](https://readthedocs.org/projects/match4everything/badge/?version=latest)](https://match4everything.readthedocs.io/en/latest/?badge=latest)
[![Build Status](https://travis-ci.org/match4everyone/match4everything.svg?branch=staging)](https://travis-ci.org/match4everyone/match4everything)

Open source project for building a platform that can match anyone.

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
from math import radians, sin, cos, asin, sqrt
import csv
# plz is german for zipcode
plzs = {}
current_location = dirname(abspath(__file__))
from os.path import join
for countrycode in ["DE", "AT"]:
with open(join(current_location, f'files/{countrycode}.csv'), encoding='utf-8') as csvfile:
with open(join(current_location, f'data/{countrycode}.csv'), encoding='utf-8') as csvfile:
reader = csv.DictReader(csvfile)
plzs[countrycode] = {}
for row in reader:
Expand All @@ -28,6 +30,6 @@
with open(join(current_location, "files/plzs_merged.json"), "w") as f:
with open(join(current_location, "data/zipcodes_merged.json"), "w") as f:
f.write(json.dumps(plzs))
"""
7 changes: 7 additions & 0 deletions backend/apps/matching/data/map_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import json
from os.path import abspath, dirname, join

current_location = dirname(abspath(__file__))

with open(join(current_location, "../data/zipcodes_merged.json")) as f:
zipcodes = json.loads(f.read())
7 changes: 0 additions & 7 deletions backend/apps/matching/files/map_data.py

This file was deleted.

2 changes: 1 addition & 1 deletion backend/apps/matching/forms/participant_edit_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django import forms

from apps.matching.models import ParticipantInfo
from apps.matching.src.dual_factory import instanciate_for_participants
from apps.matching.utils.dual_factory import instanciate_for_participants


def make_participant_edit_info_form(participant_type):
Expand Down
2 changes: 1 addition & 1 deletion backend/apps/matching/forms/participant_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django import forms

from apps.matching.models import ParticipantInfoLocation
from apps.matching.src.dual_factory import instanciate_for_participants
from apps.matching.utils.dual_factory import instanciate_for_participants


def make_participant_location_form(participant_type):
Expand Down
2 changes: 1 addition & 1 deletion backend/apps/matching/forms/participant_signup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.utils.translation import gettext_lazy as _

from apps.matching.models import Participant, ParticipantInfo, User
from apps.matching.src.dual_factory import instanciate_for_participants
from apps.matching.utils.dual_factory import instanciate_for_participants


def make_participant_signup_form(participant_type):
Expand Down
2 changes: 1 addition & 1 deletion backend/apps/matching/forms/participant_view_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django import forms

from apps.matching.models import ParticipantInfo
from apps.matching.src.dual_factory import instanciate_for_participants
from apps.matching.utils.dual_factory import instanciate_for_participants


def make_participant_view_info_form(participant_type):
Expand Down
2 changes: 1 addition & 1 deletion backend/apps/matching/models/participant_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.db import models
from django.urls import reverse

from match4everyone.config.A import A
from match4everyone.configuration.A import A

from .participant import Participant

Expand Down
10 changes: 6 additions & 4 deletions backend/apps/matching/models/participant_info_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from django.utils.translation import gettext_lazy as _
import numpy as np

from apps.matching.files.map_data import plzs
from apps.matching.src.plzs import BIG_CITY_PLZS
from apps.matching.data.map_data import zipcodes
from apps.matching.utils.zipcodes import GERMAN_BIG_CITY_ZIPCODES

from .participant_info import ParticipantInfo

Expand Down Expand Up @@ -43,7 +43,7 @@ class AbstractParticipantInfoLocation(models.Model):
)

def clean(self):
if self.plz not in plzs[self.country_code]:
if self.plz not in zipcodes[self.country_code]:
raise ValidationError(
str(self.plz) + str(_(" is not a postcode in ")) + self.country_code
)
Expand All @@ -54,7 +54,9 @@ class Meta:
@classmethod
def generate_fake(cls, participant_info, rs=np.random):
pil = cls.objects.create(
participant_info=participant_info, country_code="DE", plz=rs.choice(BIG_CITY_PLZS)
participant_info=participant_info,
country_code="DE",
plz=rs.choice(GERMAN_BIG_CITY_ZIPCODES),
)
pil.save()
return pil
Expand Down
Empty file.
36 changes: 0 additions & 36 deletions backend/apps/matching/src/map.py

This file was deleted.

2 changes: 1 addition & 1 deletion backend/apps/matching/tables/approval.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django_tables2 import TemplateColumn

from apps.matching.models import Participant
from apps.matching.src.dual_factory import instanciate_for_participants
from apps.matching.utils.dual_factory import instanciate_for_participants

approval_button = '<form>{% csrf_token %}<input type="hidden" value="{{record.uuid}}" name="uuid"> <button type="submit" name="change_approval" formmethod="post" class="btn btn-sm {% if record.is_approved %} btn-warning {% else %} btn-success {%endif%}">{% if record.is_approved %}Disapprove{% else %} Approve {%endif%}</button></form>'
# TODO: We ned to link to the profile of that participant on the info https://github.com/match4everyone/match4everything/issues/55
Expand Down
2 changes: 1 addition & 1 deletion backend/apps/matching/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.views.generic.base import TemplateView

from . import views
from .src import converters
from .utils import converters

register_converter(converters.DecimalPointFloatConverter, "float")
register_converter(converters.ParticipantTypeConverter, "p")
Expand Down
37 changes: 37 additions & 0 deletions backend/apps/matching/utils/map.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
import time

from django.conf import settings

from apps.matching.data.map_data import zipcodes


def get_zipcode_data(countrycode, zipcode):
lat, lon, ort = zipcodes[countrycode][zipcode]
return {"latitude": lat, "longitude": lon, "city": ort}


def group_by_zip_code(entities):
countrycode_zipcode_details = {}

for entity in entities:
countrycode = entity.country_code
zipcode = entity.plz

if countrycode not in countrycode_zipcode_details:
countrycode_zipcode_details[countrycode] = {}

country = countrycode_zipcode_details[countrycode]
if zipcode not in country:
country[zipcode] = {
"countrycode": countrycode,
"plz": zipcode,
"count": 0,
**get_zipcode_data(countrycode, zipcode),
}

country[zipcode]["count"] += 1
return countrycode_zipcode_details


def get_ttl_hash(seconds=300):
"""Return the same value within `seconds` time period."""
return round(time.time() / seconds)


def get_tile_info():
"""Create a valid tile url from the settings and state the attribution."""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BIG_CITY_PLZS = [
GERMAN_BIG_CITY_ZIPCODES = [
"01067",
"01069",
"01097",
Expand Down
3 changes: 1 addition & 2 deletions backend/apps/matching/views/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from django.views.decorators.gzip import gzip_page

from apps.matching.models import ParticipantInfoLocation
from apps.matching.src.map import group_by_zip_code
from apps.matching.utils.map import get_tile_info
from apps.matching.utils.map import get_tile_info, group_by_zip_code


# Should be safe against BREACH attack because we don't have user input in reponse body
Expand Down
2 changes: 1 addition & 1 deletion backend/apps/matching/views/participant_signup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from apps.matching.admin import logged_in_not_permitted
from apps.matching.forms import ParticipantInfoSignupForm
from apps.matching.models import ParticipantInfoLocation
from apps.matching.src.notifications import send_password_set_email
from apps.matching.utils.notifications import send_password_set_email

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion backend/apps/matching/views/user_email_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.http import HttpResponseRedirect

from apps.matching.models import User
from apps.matching.src.notifications import send_password_set_email
from apps.matching.utils.notifications import send_password_set_email

logger = logging.getLogger(__name__)

Expand Down

0 comments on commit 345a92f

Please sign in to comment.