Skip to content

Commit

Permalink
Revise time card to daily report, closes #805 closes #806 closes #807 c…
Browse files Browse the repository at this point in the history
…loses #808 closes #809
  • Loading branch information
shayan committed May 12, 2019
1 parent 7d0ac9e commit 28b97c9
Show file tree
Hide file tree
Showing 15 changed files with 301 additions and 413 deletions.
69 changes: 69 additions & 0 deletions dolphin/controllers/dailyreport.py
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)

4 changes: 2 additions & 2 deletions dolphin/controllers/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from .activity import ActivityController
from .eventtype import EventTypeController
from .event import EventController
from .timecard import TimecardController
from .dailyreport import DailyreportController


here = abspath(dirname(__file__))
Expand Down Expand Up @@ -54,7 +54,7 @@ class Apiv1(RestController, JsonPatchControllerMixin):
activities = ActivityController()
eventtypes = EventTypeController()
events = EventController()
timecards = TimecardController()
dailyreports = DailyreportController()

@json
def version(self):
Expand Down
58 changes: 0 additions & 58 deletions dolphin/controllers/timecard.py

This file was deleted.

16 changes: 10 additions & 6 deletions dolphin/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ class StatusInvalidEndDateFormat(HTTPKnownStatus):
status = '790 Invalid End Date Format'


class StatusLimitedCharecterForSummary(HTTPKnownStatus):
status = '902 At Most 1024 Characters Are Valid For Summary'
class StatusLimitedCharecterForNote(HTTPKnownStatus):
status = '902 At Most 1024 Characters Are Valid For Note'


class StatusInvalidEstimatedTimeType(HTTPKnownStatus):
status = '900 Invalid Estimated Time Type'
class StatusInvalidHoursType(HTTPKnownStatus):
status = '900 Invalid Hours Type'


class StatusSummaryNotInForm(HTTPKnownStatus):
Expand All @@ -180,8 +180,8 @@ class StatusEstimatedTimeNotInForm(HTTPKnownStatus):
status = '901 Estimated Time Not In Form'


class StatusSummaryIsNull(HTTPKnownStatus):
status = '903 Summary Is Null'
class StatusNoteIsNull(HTTPKnownStatus):
status = '903 Note Is Null'


class StatusEstimatedTimeIsNull(HTTPKnownStatus):
Expand All @@ -203,3 +203,7 @@ class StatusRepeatNotInForm(HTTPKnownStatus):
class StatusQueryParameterNotInFormOrQueryString(HTTPKnownStatus):
status = '912 Query Parameter Not In Form Or Query String'


class StatusHoursMustBeGreaterThanZero(HTTPKnownStatus):
status = '914 Hours Must Be Greater Than 0'

2 changes: 1 addition & 1 deletion dolphin/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
from .skill import Skill, SkillMember
from .activity import Activity
from .eventtype import EventType
from .timecard import Timecard
from .dailyreport import Dailyreport
from .event import Event, event_repeats

72 changes: 72 additions & 0 deletions dolphin/models/dailyreport.py
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'
)

10 changes: 5 additions & 5 deletions dolphin/models/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
String, select, func
from sqlalchemy.orm import column_property

from .timecard import Timecard
from .dailyreport import Dailyreport


item_statuses = [
Expand Down Expand Up @@ -133,14 +133,14 @@ class Item(TimestampMixin, OrderingMixin, FilteringMixin, PaginationMixin,
foreign_keys=issue_id,
back_populates='items'
)
timecards = relationship(
'Timecard',
dailyreports = relationship(
'Dailyreport',
back_populates='item'
)

hours_worked = column_property(
select([func.sum(Timecard.estimated_time)])
.where(Timecard.item_id == id)
select([func.sum(Dailyreport.hours)])
.where(Dailyreport.item_id == id)
)

UniqueConstraint(phase_id, issue_id, member_id)
Expand Down
87 changes: 0 additions & 87 deletions dolphin/models/timecard.py

This file was deleted.

Loading

0 comments on commit 28b97c9

Please sign in to comment.