-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
shayan
committed
May 12, 2019
1 parent
7d0ac9e
commit 28b97c9
Showing
15 changed files
with
301 additions
and
413 deletions.
There are no files selected for viewing
This file contains 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,69 @@ | ||
from datetime import datetime | ||
|
||
from nanohttp import json, int_or_notfound, HTTPNotFound | ||
from restfulpy.authorization import authorize | ||
from restfulpy.controllers import ModelRestController | ||
from restfulpy.orm import DBSession, commit | ||
|
||
from ..exceptions import StatusEndDateMustBeGreaterThanStartDate | ||
from ..models import Dailyreport | ||
from ..validators import dailyreport_create_validator, \ | ||
dailyreport_update_validator | ||
|
||
|
||
class DailyreportController(ModelRestController): | ||
__model__ = Dailyreport | ||
|
||
@authorize | ||
@json( | ||
prevent_empty_form='708 Empty Form', | ||
form_whitelist=( | ||
['hours', 'note', 'itemId'], | ||
'707 Invalid field, only following fields are accepted: ' \ | ||
'hours, note and itemId' | ||
) | ||
) | ||
@dailyreport_create_validator | ||
@commit | ||
def create(self): | ||
dailyreport = Dailyreport() | ||
dailyreport.update_from_request() | ||
dailyreport.date = datetime.now().date() | ||
DBSession.add(dailyreport) | ||
return dailyreport | ||
|
||
@authorize | ||
@json(prevent_form='709 Form Not Allowed') | ||
def get(self, id): | ||
id = int_or_notfound(id) | ||
dailyreport = DBSession.query(Dailyreport).get(id) | ||
if dailyreport is None: | ||
raise HTTPNotFound() | ||
|
||
return dailyreport | ||
|
||
@authorize | ||
@json( | ||
prevent_empty_form='708 Empty Form', | ||
form_whitelist=( | ||
['hours', 'note'], | ||
'707 Invalid field, only following fields are accepted: hours, note' | ||
) | ||
) | ||
@dailyreport_update_validator | ||
@commit | ||
def update(self, id): | ||
id = int_or_notfound(id) | ||
dailyreport = DBSession.query(Dailyreport).get(id) | ||
if dailyreport is None: | ||
raise HTTPNotFound() | ||
|
||
dailyreport.update_from_request() | ||
return dailyreport | ||
|
||
@authorize | ||
@json(prevent_form='709 Form Not Allowed') | ||
@Dailyreport.expose | ||
def list(self): | ||
return DBSession.query(Dailyreport) | ||
|
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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 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 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,72 @@ | ||
from datetime import datetime | ||
|
||
from restfulpy.orm import Field, DeclarativeBase, OrderingMixin, \ | ||
FilteringMixin, PaginationMixin, relationship | ||
from sqlalchemy import Integer, Unicode, ForeignKey, Date | ||
|
||
|
||
class Dailyreport(OrderingMixin, FilteringMixin, PaginationMixin, \ | ||
DeclarativeBase): | ||
__tablename__ = 'dailyreport' | ||
|
||
item_id = Field( | ||
Integer, | ||
ForeignKey('item.id'), | ||
python_type=int, | ||
nullable=False, | ||
watermark='Choose a assginment', | ||
label='Assginment', | ||
not_none=True, | ||
required=True, | ||
example='Lorem Ipsum' | ||
) | ||
id = Field( | ||
Integer, | ||
primary_key=True, | ||
readonly=True, | ||
not_none=True, | ||
required=False, | ||
label='ID', | ||
minimum=1, | ||
) | ||
date = Field( | ||
Date, | ||
python_type=datetime.date, | ||
label='Date', | ||
pattern=r'^(\d{4})-(0[1-9]|1[012]|[1-9])-(0[1-9]|[12]\d{1}|3[01]|[1-9])', | ||
pattern_description='ISO format like "yyyy-mm-dd" is valid', | ||
example='2018-02-02', | ||
watermark='Date of daily report', | ||
nullable=False, | ||
not_none=True, | ||
required=False, | ||
readonly=True, | ||
) | ||
hours = Field( | ||
Integer, | ||
python_type=int, | ||
watermark='Hours spent on the assignment', | ||
label='Hours', | ||
example=2, | ||
nullable=True, | ||
not_none=False, | ||
required=False, | ||
) | ||
note = Field( | ||
Unicode, | ||
min_length=1, | ||
max_length=1024, | ||
label='Lorem Isum', | ||
watermark='Lorem Ipsum', | ||
not_none=False, | ||
nullable=True, | ||
required=False, | ||
python_type=str, | ||
example='Lorem Ipsum', | ||
) | ||
|
||
item = relationship( | ||
'Item', | ||
back_populates='dailyreports' | ||
) | ||
|
This file contains 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 was deleted.
Oops, something went wrong.
Oops, something went wrong.