Skip to content

Commit 29aa534

Browse files
committed
Initial commit
0 parents  commit 29aa534

23 files changed

+1877
-0
lines changed

.gitignore

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
MANIFEST
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
*.cover
47+
.hypothesis/
48+
.pytest_cache/
49+
50+
# Translations
51+
*.mo
52+
*.pot
53+
54+
# Django stuff:
55+
*.log
56+
local_settings.py
57+
db.sqlite3
58+
59+
# Flask stuff:
60+
instance/
61+
.webassets-cache
62+
63+
# Scrapy stuff:
64+
.scrapy
65+
66+
# Sphinx documentation
67+
docs/_build/
68+
69+
# PyBuilder
70+
target/
71+
72+
# Jupyter Notebook
73+
.ipynb_checkpoints
74+
75+
# pyenv
76+
.python-version
77+
78+
# celery beat schedule file
79+
celerybeat-schedule
80+
81+
# SageMath parsed files
82+
*.sage.py
83+
84+
# Environments
85+
.env
86+
.venv
87+
env/
88+
venv/
89+
ENV/
90+
env.bak/
91+
venv.bak/
92+
93+
# Spyder project settings
94+
.spyderproject
95+
.spyproject
96+
97+
# Rope project settings
98+
.ropeproject
99+
100+
# mkdocs documentation
101+
/site
102+
103+
# mypy
104+
.mypy_cache/
105+
106+
template
107+
build
108+
.magicindex.json
109+
.noseids

.travis.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
language: python
2+
python:
3+
- '2.7'
4+
cache: pip
5+
addons:
6+
- mariadb: '10.0'
7+
8+
env:
9+
- >-
10+
TEST_DATABASE_URL=mysql+mysqldb://root@localhost/geokrety_unittest?charset=utf8mb4
11+
12+
install:
13+
- pip install -r requirements.dev.txt
14+
15+
before_script:
16+
- mysql -e 'FLUSH TABLES; DROP DATABASE IF EXISTS geokrety_unittest; CREATE DATABASE geokrety_unittest CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;'
17+
script:
18+
- nosetests tests/ -v --with-coverage --with-id --nologcapture --stop
19+
after_success:
20+
- 'bash <(curl -s https://codecov.io/bash)'
21+
- python setup.py sdist
22+
23+
deploy:
24+
- provider: releases
25+
api_key:
26+
secure: sXLUmqqrcEKel/mHk0g8k0XB7D8PE1Q/8oQkf79jSvoKBfX3+MsUqV6/YlxeO/sCk6SOstn5pNWjr/JsuNv752PaOJs5IAoxsUj2xzWDkoWKoW93NUlzhDfLWi2ITqmmzWwA92fxUkfaok4PPmk1deB0ywmxc8JEXN1PT12kT+ccyVN1R/meqP7auhrqWKVRU5zGpuhIQ8XPp+VRKKJh/odFiTtCFIA0uXRvjHlJLP7OAajMmjEycKGBiJCgIqoe5Ut2rEBAIcmaWy2T23y5o3DBhP4eKIvKXLKAVqLhcsVFgGURTESEMDmdJk3K6EMxY3sdCZBtP3qNHXCsqnfNrJTqf5SiZYr+JwscuoHrAFMZbc4LlC8J3NnbjJane9Co+6pFTK2aWGtxXEKfA8fsgAVDoA3f4J6SH8/HyrZGILeg+MZvUQ613QHViwhjypbvMnHYv6hAWa6ntxDoufZXG3smmwmVtZ5QHZmUXSmZbnNQsBhBHFTtyuvgudzA63LLPCmTu0JvhE/CLTjl2g6ItgKDBVDuCtfDFB9yz2JLAOqPf+t8znfZeh/ft3piWbX4ehJaaKVXnMnVzzs7wJKS+9wZRIbw5NwE8PErkplKqvXJQH6kH1YGUdtb4M7TT/zzXJqFPLXMLwGRfE1qmhhAWHtaftYCJpY2KXL89J+sGHA=
27+
file_glob: true
28+
file: dist/geokrety_api_models-*.tar.gz
29+
skip_cleanup: true
30+
on:
31+
tags: true
32+
repo: geokrety/geokrety-api-models
33+
34+
- provider: pypi
35+
user: geokrety-bot
36+
password:
37+
secure: D6qjz9fdAbsPAxTU9Q7PBZzSO+821fj1dEQf1yzh8Qk1Ffob82a/JO+gLAgbRJAGZrI4Yo2ii7xMcdW4PU+/si7L0Z6GWTC5qBuRX5YPBj8BrPCngHl300nqhoA9/Cj8/t5NdXmBhN83seK1mM9fytgfQLYeO4YX1p4uE/VgfTehtEcIWpg90nuq3wpMCbQcN5H8fogykyRGHQxBOdcEfiM9jcwdhjH/+rutT4O4oj/In+/rm0DlMkXv7KmzveQwMrKsaZviYfG7qHkEeDeEK4JKQwvixYbnhhdKSfFOcJwtB0mRecgvPD2oth2ZIckPI31tA89T9JHbSK4YGEVAArlvREi4afCJjjt6QoVJnf8zQdaTVy1B3LytEJnTL9ZlVbUTzL/D1maovV9oNHfgJSRufO3Ouk3C0e31fizFmrNYkZ266hseXTbnem1l4Lvg8sGKQbzAPeyx0jPjaPzLFrrugGjzWAdxObTEd0dvnNrhQYX6bUdp646cHMYuqc/n6AZd8Ou49hk+PlIINoxDPHbF4sTcM11HJau8El3rfxbaAucotOruihjvhFl/oqhtM7E0YA94ujhuMCu/niLu892i7B3naWrbUPjcS5+awe6bY951JoOxoc8s/vV8xlz7QWl0FRVjUvbvfT34qEFIu9IVUDYTZc8vxdUAdkh3ZjM=
38+
on:
39+
tags: true
40+
repo: geokrety/geokrety-api-models

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 GeoKrety
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[![Python 3](https://pyup.io/repos/github/geokrety/geokrety-api-models/python-3-shield.svg)](https://pyup.io/repos/github/geokrety/geokrety-api-models/)
2+
[![Updates](https://pyup.io/repos/github/geokrety/geokrety-api-models/shield.svg)](https://pyup.io/repos/github/geokrety/geokrety-api-models/)
3+
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/f9a7080046074fa6b084f14f9bb0a91c)](https://www.codacy.com/app/GeoKrety/geokrety-api-models?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=geokrety/geokrety-api-models&amp;utm_campaign=Badge_Grade)
4+
5+
6+
# GeoKrety API Models
7+
8+
This contains ORM files for the [GeoKrety API project](https://github.com/geokrety/geokrety-api)
9+
or other dependent subprojects such as FAAS functions.

geokrety_api_models/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from .badge import Badge
4+
from .geokret import Geokret
5+
from .move import Move
6+
from .move_comment import MoveComment
7+
from .news import News
8+
from .news_comment import NewsComment
9+
from .news_subscription import NewsSubscription
10+
from .user import User
11+
12+
__all__ = [
13+
"Badge",
14+
"Geokret",
15+
"Move",
16+
"MoveComment",
17+
"News",
18+
"NewsComment",
19+
"NewsSubscription",
20+
"User",
21+
]

geokrety_api_models/badge.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import datetime
4+
import uuid
5+
6+
from sqlalchemy import Column, DateTime, ForeignKey, Integer, String, event
7+
from sqlalchemy.ext.hybrid import hybrid_property
8+
from sqlalchemy.orm import relationship
9+
10+
import bleach
11+
import characterentities
12+
13+
from .base import Base
14+
15+
16+
class Badge(Base):
17+
__tablename__ = 'gk-badges-collection'
18+
19+
id = Column(
20+
'id',
21+
Integer,
22+
primary_key=True,
23+
key='id',
24+
)
25+
26+
_name = Column(
27+
'name',
28+
String(80),
29+
key='name',
30+
nullable=False,
31+
unique=True,
32+
)
33+
34+
_description = Column(
35+
'description',
36+
String(128),
37+
key='description',
38+
nullable=True,
39+
)
40+
41+
filename = Column(
42+
'filename',
43+
String(32),
44+
key='filename',
45+
nullable=False,
46+
)
47+
48+
created_on_datetime = Column(
49+
'date',
50+
DateTime,
51+
key='created_on_datetime',
52+
nullable=False,
53+
default=datetime.datetime.utcnow,
54+
)
55+
56+
author_id = Column(
57+
'author_id',
58+
Integer,
59+
ForeignKey('gk-users.id'),
60+
key='author_id',
61+
nullable=False,
62+
)
63+
64+
author = relationship(
65+
"User",
66+
foreign_keys=[author_id],
67+
backref="created_badges"
68+
)
69+
70+
@hybrid_property
71+
def name(self):
72+
return characterentities.decode(self._name)
73+
74+
@name.setter
75+
def name(self, name):
76+
name_clean = bleach.clean(name, strip=True)
77+
self._name = characterentities.decode(name_clean).strip()
78+
79+
@name.expression
80+
def name(cls):
81+
return cls._name
82+
83+
@hybrid_property
84+
def description(self):
85+
if self._description is None:
86+
return u''
87+
return characterentities.decode(self._description)
88+
89+
@description.setter
90+
def description(self, description):
91+
if description is None:
92+
return u''
93+
description_clean = bleach.clean(description, strip=True)
94+
self._description = characterentities.decode(description_clean).replace('\x00', '').strip()
95+
96+
@description.expression
97+
def description(cls):
98+
return cls._description
99+
100+
@hybrid_property
101+
def upload_url(self):
102+
# Todo send info to other daemon -> redis?
103+
from app.views.minio import storage
104+
res = storage.connection.presigned_put_object(
105+
'badges-incoming', self.filename) # , expires=timedelta(minutes=5))
106+
return res
107+
# return uuid.uuid4().hex
108+
109+
110+
@event.listens_for(Badge, 'init')
111+
def receive_init(target, args, kwargs):
112+
target.filename = uuid.uuid4().hex
113+
114+
115+
if __name__ == '__main__':
116+
# Check
117+
badge = Badge()

geokrety_api_models/base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from sqlalchemy.ext.declarative import declarative_base
4+
5+
Base = declarative_base()

0 commit comments

Comments
 (0)