def test_update_notes_is_working_properly_with_put(self): """testing if PUT: /api/entities/{id}/notes should raise 404 """ from stalker import db, Entity, Note test_entity = Entity(name='Test Entity') db.DBSession.add(test_entity) # Note 1 test_note1 = Note(content='Note 1') db.DBSession.add(test_note1) # Note 2 test_note2 = Note(content='Note 2') db.DBSession.add(test_note2) # Note 3 test_note3 = Note(content='Note 3') db.DBSession.add(test_note3) # Note 4 test_note4 = Note(content='Note 4') db.DBSession.add(test_note4) # Note 5 test_note5 = Note(content='Note 5') db.DBSession.add(test_note5) test_entity.notes = [test_note1, test_note2, test_note3] db.DBSession.commit() self.test_app.put('/api/entities/%s/notes' % test_entity.id, params={'note_id': [test_note4.id, test_note5.id]}, status=404)
def test_get_notes_view_is_working_properly(self): """testing if GET /api/entities/{id}/notes view is working properly """ from stalker import db, Entity, Note test_entity = Entity(name='Test Entity') db.DBSession.add(test_entity) test_note1 = Note(description='This is a Test note 1') db.DBSession.add(test_note1) test_note2 = Note(description='This is a Test note 2') db.DBSession.add(test_note2) test_entity.notes = [test_note1, test_note2] db.DBSession.commit() response = self.test_app.get('/api/entities/%s/notes' % test_entity.id, status=200) self.assertEqual( sorted(response.json_body), sorted([{ 'id': test_note1.id, '$ref': '/api/notes/%s' % test_note1.id, 'name': test_note1.name, 'entity_type': test_note1.entity_type }, { 'id': test_note2.id, '$ref': '/api/notes/%s' % test_note2.id, 'name': test_note2.name, 'entity_type': test_note2.entity_type }]))
def setUp(self): """setting up some proper values """ # create a user self.test_user = User(name="Test User", login="******", email="*****@*****.**", password="******") # create some test Tag objects, not necessarily needed but create them self.test_tag1 = Tag(name="Test Tag 1") self.test_tag2 = Tag(name="Test Tag 1") # make it equal to tag1 self.test_tag3 = Tag(name="Test Tag 3") self.tags = [self.test_tag1, self.test_tag2] # create a couple of test Note objects self.test_note1 = Note(name="test note1", content="test note1") self.test_note2 = Note(name="test note2", content="test note2") self.test_note3 = Note(name="test note3", content="test note3") self.notes = [self.test_note1, self.test_note2] self.kwargs = { "name": "Test Entity", "description": "This is a test entity, and this is a proper \ description for it", "created_by": self.test_user, "updated_by": self.test_user, "tags": self.tags, "notes": self.notes, } # create a proper SimpleEntity to use it later in the tests self.test_entity = Entity(**self.kwargs)
def test_entity_notes_is_working_properly(self): """testing if get_notes is working properly """ from stalker import db, Entity, Note test_entity = Entity(name='Test Entity') db.DBSession.add(test_entity) # Note 1 test_note1 = Note(content='Note 1') db.DBSession.add(test_note1) # Note 2 test_note2 = Note(content='Note 2') db.DBSession.add(test_note2) # Note 3 test_note3 = Note(content='Note 3') db.DBSession.add(test_note3) # dummy Note 4 test_note4 = Note(content='Note 4') db.DBSession.add(test_note4) test_entity.notes = [test_note1, test_note2, test_note3] db.DBSession.commit() from stalker_pyramid.testing import DummyRequest request = DummyRequest() request.matchdict['id'] = test_entity.id request.method = 'GET' entity_view = entity.EntityViews(request) response = entity_view.get_notes() self.assertEqual( sorted(response.json_body), sorted([ { 'id': test_note1.id, '$ref': '/api/notes/%s' % test_note1.id, 'name': test_note1.name, 'entity_type': 'Note' }, { 'id': test_note2.id, '$ref': '/api/notes/%s' % test_note2.id, 'name': test_note2.name, 'entity_type': 'Note' }, { 'id': test_note3.id, '$ref': '/api/notes/%s' % test_note3.id, 'name': test_note3.name, 'entity_type': 'Note' }, ]))
def test_inequality_operator(self): """testing inequality operator """ note1 = Note(**self.kwargs) note2 = Note(**self.kwargs) self.kwargs["content"] = "this is a different content" note3 = Note(**self.kwargs) assert not note1 != note2 assert note1 != note3
def test_equality_operator(self): """testing equality operator """ note1 = Note(**self.kwargs) note2 = Note(**self.kwargs) self.kwargs["content"] = "this is a different content" note3 = Note(**self.kwargs) self.assertTrue(note1 == note2) self.assertFalse(note1 == note3)
def test_update_notes_is_working_properly_with_patch(self): """testing if update_notes is working properly when the request method is PATCH """ from stalker import db, Entity, Note test_entity = Entity(name='Test Entity') db.DBSession.add(test_entity) # Note 1 test_note1 = Note(content='Note 1') db.DBSession.add(test_note1) # Note 2 test_note2 = Note(content='Note 2') db.DBSession.add(test_note2) # Note 3 test_note3 = Note(content='Note 3') db.DBSession.add(test_note3) # Note 4 test_note4 = Note(content='Note 4') db.DBSession.add(test_note4) # Note 5 test_note5 = Note(content='Note 5') db.DBSession.add(test_note5) test_entity.notes = [test_note1, test_note2, test_note3] db.DBSession.commit() from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.matchdict['id'] = test_entity.id request.method = 'PATCH' # add the 4th and 5th notes request.params = DummyMultiDict() request.params['note_id'] = [test_note4.id, test_note5.id] request.POST = request.params entity_view = entity.EntityViews(request) entity_view.update_notes() test_entity = Entity.query.filter(Entity.id == test_entity.id).first() self.assertEqual( sorted(test_entity.notes), sorted( [test_note1, test_note2, test_note3, test_note4, test_note5]))
def test_content_argument_is_missing(self): """testing if nothing is going to happen when no content argument is given """ self.kwargs.pop("content") new_note = Note(**self.kwargs) assert isinstance(new_note, Note)
def test_content_argument_is_set_to_None(self): """testing if nothing is going to happen when content argument is given as None """ self.kwargs["content"] = None new_note = Note(**self.kwargs) assert isinstance(new_note, Note)
def test_update_entity_is_working_properly(self): """testing if update_note is working properly """ from stalker import db, Note, User test_user = User(name='Test User', login='******', email='*****@*****.**', password='******') db.DBSession.add(test_user) note1 = Note(content='This is a test note') db.DBSession.add(note1) db.DBSession.commit() from stalker_pyramid.testing import DummyRequest, DummyMultiDict request = DummyRequest() request.matchdict['id'] = note1.id request.params = DummyMultiDict() request.params['content'] = 'this is the new content' request.params['updated_by_id'] = test_user.id note_view = note.NoteViews(request) note_view.update_entity() note1 = Note.query.first() self.assertEqual(note1.content, 'this is the new content') self.assertEqual(note1.updated_by, test_user)
def test_get_entity_is_working_properly(self): """testing if GET /api/notes/{id} view is working properly """ from stalker import db, Note test_note1 = Note(content='This is a test note', created_by=self.admin) db.DBSession.add(test_note1) db.DBSession.commit() response = self.test_app.get('/api/notes/%s' % test_note1.id, status=200) import stalker from stalker_pyramid.views import EntityViewBase self.assertEqual( response.json_body, { 'created_by': { 'id': self.admin.id, '$ref': '/api/users/%s' % self.admin.id, 'name': self.admin.name, 'entity_type': self.admin.entity_type }, 'content': 'This is a test note', 'date_created': EntityViewBase.milliseconds_since_epoch( test_note1.date_created), 'date_updated': EntityViewBase.milliseconds_since_epoch( test_note1.date_updated), 'description': 'This is a test note', 'entity_type': 'Note', 'generic_text': '', 'generic_data': { '$ref': '/api/simple_entities/%s/generic_data' % test_note1.id, 'length': 0 }, 'id': test_note1.id, 'name': test_note1.name, 'stalker_version': stalker.__version__, 'thumbnail': None, 'type': None, 'updated_by': { 'id': self.admin.id, '$ref': '/api/users/%s' % self.admin.id, 'name': self.admin.name, 'entity_type': self.admin.entity_type } })
def test_get_entities_is_working_properly(self): """testing if get_entities is working properly """ from stalker import db, Note note1 = Note(content='test content 1') note2 = Note(content='test content 2') note3 = Note(content='test content 3') note4 = Note(content='test content 4') db.DBSession.add_all([note1, note2, note3, note4]) db.DBSession.commit() from stalker_pyramid.testing import DummyRequest request = DummyRequest() note_views = note.NoteViews(request) response = note_views.get_entities() self.assertEqual( sorted(response.json_body), sorted([ { 'id': note1.id, '$ref': '/api/notes/%s' % note1.id, 'name': note1.name, 'entity_type': note1.entity_type }, { 'id': note2.id, '$ref': '/api/notes/%s' % note2.id, 'name': note2.name, 'entity_type': note2.entity_type }, { 'id': note3.id, '$ref': '/api/notes/%s' % note3.id, 'name': note3.name, 'entity_type': note3.entity_type }, { 'id': note4.id, '$ref': '/api/notes/%s' % note4.id, 'name': note4.name, 'entity_type': note4.entity_type }, ]))
def test_comments_attribute_is_synonym_for_notes_attribute(self): """testing if the comments attribute is the synonym for the notes attribute, so setting one will also set the other """ note1 = Note(name='Test Note 1', content='Test note 1') note2 = Note(name='Test Note 2', content='Test note 2') self.test_ticket.comments.append(note1) self.test_ticket.comments.append(note2) self.assertTrue(note1 in self.test_ticket.notes) self.assertTrue(note2 in self.test_ticket.notes) self.test_ticket.notes.remove(note1) self.assertFalse(note1 in self.test_ticket.comments) self.test_ticket.notes.remove(note2) self.assertFalse(note2 in self.test_ticket.comments)
def setUp(self): """setup the test """ self.kwargs = { "name": "Note to something", "description": "this is a simple note", "content": "this is a note content", } # create a Note object self.test_note = Note(**self.kwargs)
def test_get_entities_is_working_properly(self): """testing GET /api/notes is working properly """ from stalker import db, Note note1 = Note(content='test content 1') note2 = Note(content='test content 2') note3 = Note(content='test content 3') note4 = Note(content='test content 4') db.DBSession.add_all([note1, note2, note3, note4]) db.DBSession.commit() response = self.test_app.get('/api/notes', status=200) self.assertEqual( sorted(response.json_body), sorted([ { 'id': note1.id, '$ref': '/api/notes/%s' % note1.id, 'name': note1.name, 'entity_type': note1.entity_type }, { 'id': note2.id, '$ref': '/api/notes/%s' % note2.id, 'name': note2.name, 'entity_type': note2.entity_type }, { 'id': note3.id, '$ref': '/api/notes/%s' % note3.id, 'name': note3.name, 'entity_type': note3.entity_type }, { 'id': note4.id, '$ref': '/api/notes/%s' % note4.id, 'name': note4.name, 'entity_type': note4.entity_type }, ]))
def test_get_notes_is_working_properly(self): """testing get_notes() is working properly """ # create a test entity with notes from stalker import db, Entity, Note # test note 1 test_note1 = Note(content='Test note 1') db.DBSession.add(test_note1) # test note 2 test_note2 = Note(content='Test note 2') db.DBSession.add(test_note2) # test note 3 test_note3 = Note(content='Test note 3') db.DBSession.add(test_note3) # some other note test_note4 = Note(content='Test note 4') db.DBSession.add(test_note4) test_entity = Entity(name='Test Entity', notes=[test_note1, test_note2, test_note3]) db.DBSession.add(test_entity) db.DBSession.commit() from stalker_pyramid.testing import DummyRequest dummy_request = DummyRequest() dummy_request.matchdict['id'] = test_entity.id entity_view = entity.EntityViews(dummy_request) response = entity_view.get_notes() self.assertEqual( sorted(response.json_body), sorted([{ 'id': n.id, '$ref': '/api/notes/%s' % n.id, 'name': n.name, 'entity_type': n.entity_type } for n in [test_note1, test_note2, test_note3]]))
def test_content_argument_is_set_to_something_other_than_a_string(self): """testing if a TypeError will be raised when trying to set the content argument to something other than a string """ test_value = 1.24 self.kwargs["content"] = test_value with pytest.raises(TypeError) as cm: Note(**self.kwargs) assert str(cm.value) == \ 'Note.description should be a string, not float'
def test_delete_entity_is_working_properly(self): """testing if DELETE /api/notes/{id} view is working properly """ from stalker import db, Note test_note = Note(content='This is a test note') db.DBSession.add(test_note) db.DBSession.commit() self.test_app.delete('/api/notes/%s' % test_note.id, status=200) test_note_db = Note.query.filter(Note.name == test_note.name).first() self.assertIsNone(test_note_db)
def test_update_notes_is_working_properly_with_patch(self): """testing if PATCH /api/entities/{id}/notes view is working properly """ from stalker import db, Entity, Note test_entity = Entity(name='Test Entity') db.DBSession.add(test_entity) # Note 1 test_note1 = Note(content='Note 1') db.DBSession.add(test_note1) # Note 2 test_note2 = Note(content='Note 2') db.DBSession.add(test_note2) # Note 3 test_note3 = Note(content='Note 3') db.DBSession.add(test_note3) # Note 4 test_note4 = Note(content='Note 4') db.DBSession.add(test_note4) # Note 5 test_note5 = Note(content='Note 5') db.DBSession.add(test_note5) test_entity.notes = [test_note1, test_note2, test_note3] db.DBSession.commit() self.test_app.patch('/api/entities/%s/notes' % test_entity.id, params={'note_id': [test_note4.id, test_note5.id]}, status=200) test_entity = Entity.query.filter(Entity.id == test_entity.id).first() self.assertEqual( sorted(test_entity.notes), sorted( [test_note1, test_note2, test_note3, test_note4, test_note5]))
def test_update_entity_is_working_properly_with_post(self): """testing if POST /api/note/{id} is working properly """ from stalker import db, Note note1 = Note(content='This is a test note') db.DBSession.add(note1) db.DBSession.commit() self.admin_login() self.test_app.post('/api/notes/%s' % note1.id, params={'content': 'this is the new content'}, status=200) note1 = Note.query.first() self.assertEqual(note1.content, 'this is the new content')
def test_delete_entity_is_working_properly(self): """testing if the delete_entity method is working properly """ from stalker import db, Note test_note = Note(content='This is a test note') db.DBSession.add(test_note) db.DBSession.commit() from stalker_pyramid.testing import DummyRequest request = DummyRequest() request.matchdict['id'] = test_note.id note_view = note.NoteViews(request) note_view.delete_entity() test_note_db = Note.query.filter(Note.name == test_note.name).first() self.assertIsNone(test_note_db)
def accept(self): """overridden accept method """ # get the info task = self.tasks_combo_box.currentTask() resource = self.get_current_resource() # war the user if the resource is not the logged_in_user if resource != self.logged_in_user: msg_box = QtWidgets.QMessageBox(self) msg_box.setWindowTitle( 'Entering TimeLog On Behalf of Somebody Else' ) msg_box.setText( "You're entering a TimeLog on behalf of somebody else???" ) accept_button = msg_box.addButton( 'Accept the responsibility', QtWidgets.QMessageBox.AcceptRole ) cancel_button = msg_box.addButton( 'Cancel', QtWidgets.QMessageBox.RejectRole ) msg_box.setDefaultButton(cancel_button) msg_box.exec_() clicked_button = msg_box.clickedButton() msg_box.deleteLater() if clicked_button == cancel_button: return description = self.description_plain_text_edit.toPlainText() revision_cause_text = \ self.revision_type_combo_box.currentText().replace(' ', '_') is_complete = self.set_as_complete_radio_button.isChecked() submit_to_final_review = \ self.submit_for_final_review_radio_button.isChecked() # get the revision Types from stalker import Type revision_type = Type.query\ .filter(Type.target_entity_type == 'Note')\ .filter(Type.name == revision_cause_text)\ .first() date = self.calendar_widget.selectedDate() start = self.start_time_edit.time() end = self.end_time_edit.time() # construct proper datetime.DateTime instances import datetime start_date = datetime.datetime( date.year(), date.month(), date.day(), start.hour(), start.minute() ) end_date = datetime.datetime( date.year(), date.month(), date.day(), end.hour(), end.minute() ) today_midnight = datetime.datetime.now().replace( hour=23, minute=59, second=59, microsecond=999 ) # raise an error if the user is trying to enter a TimeLog to the future if start_date > today_midnight or end_date > today_midnight: QtWidgets.QMessageBox.critical( self, 'Error', 'Gelecege TimeLog giremezsiniz!!!', ) return # convert them to utc from anima.utils import local_to_utc utc_start_date = local_to_utc(start_date) utc_end_date = local_to_utc(end_date) # create a TimeLog # print('Task : %s' % task.name) # print('Resource : %s' % resource.name) # print('utc_start_date: %s' % utc_start_date) # print('utc_end_date : %s' % utc_end_date) # now if we are not using extra time just create the TimeLog from stalker import TimeLog from stalker.db.session import DBSession from stalker.exceptions import (OverBookedError, DependencyViolationError) utc_now = local_to_utc(datetime.datetime.now()) # TODO: Remove this in a later version import stalker from distutils.version import LooseVersion if LooseVersion(stalker.__version__) >= LooseVersion('0.2.18'): # inject timezone info import pytz utc_start_date = utc_start_date.replace(tzinfo=pytz.utc) utc_end_date = utc_end_date.replace(tzinfo=pytz.utc) utc_now = utc_now.replace(tzinfo=pytz.utc) from sqlalchemy.exc import IntegrityError if not self.timelog: try: new_time_log = TimeLog( task=task, resource=resource, start=utc_start_date, end=utc_end_date, description=description, date_created=utc_now ) except (OverBookedError, DependencyViolationError) as e: # inform the user that it can not do that QtWidgets.QMessageBox.critical( self, 'Error', '%s' % e ) DBSession.rollback() return try: DBSession.add(new_time_log) DBSession.commit() self.timelog_created = True except IntegrityError as e: DBSession.rollback() QtWidgets.QMessageBox.critical( self, 'Error', 'Database Error!!!' '<br>' '%s' % e ) return else: # just update the date values self.timelog.start = utc_start_date self.timelog.end = utc_end_date self.timelog.date_updated = utc_now DBSession.add(self.timelog) DBSession.commit() if self.no_time_left: # we have no time left so automatically extend the task from stalker import Task schedule_timing, schedule_unit = \ task.least_meaningful_time_unit( task.total_logged_seconds ) if schedule_timing != 0: task.schedule_timing = schedule_timing task.schedule_unit = schedule_unit # also create a Note from stalker import Note new_note = Note( content='Extending timing of the task <b>%s h %s min.</b>' % ( self.extended_hours, self.extended_minutes ), type=revision_type, created_by=self.logged_in_user, date_created=utc_now ) DBSession.add(new_note) task.notes.append(new_note) try: DBSession.commit() except IntegrityError as e: QtWidgets.QMessageBox.critical( self, 'Error', 'Database Error!!!' '<br>' '%s' % e ) DBSession.rollback() return if is_complete: # set the status to complete from stalker import Type, Status status_cmpl = Status.query.filter(Status.code == 'CMPL').first() forced_status_type = \ Type.query.filter(Type.name == 'Forced Status').first() # also create a Note from stalker import Note new_note = Note( content='%s has changed this task status to Completed' % resource.name, type=forced_status_type, created_by=self.logged_in_user, date_created=utc_now ) DBSession.add(new_note) task.notes.append(new_note) task.status = status_cmpl DBSession.commit() elif submit_to_final_review: # clip the Task timing to current time logs from stalker import Task schedule_timing, schedule_unit = \ task.least_meaningful_time_unit( task.total_logged_seconds ) task.schedule_timing = schedule_timing task.schedule_unit = schedule_unit DBSession.add(task) try: DBSession.commit() except IntegrityError as e: QtWidgets.QMessageBox.critical( self, 'Error', 'Database Error!!!' '<br>' '%s' % e ) DBSession.rollback() return # request a review reviews = task.request_review() for review in reviews: review.created_by = review.updated_by = self.logged_in_user review.date_created = utc_now review.date_updated = utc_now DBSession.add_all(reviews) # and create a Note for the Task request_review_note_type = \ Type.query\ .filter(Type.target_entity_type == 'Note')\ .filter(Type.name == 'Request Review')\ .first() from stalker import Note request_review_note = Note( type=request_review_note_type, created_by=self.logged_in_user, date_created=utc_now ) DBSession.add(request_review_note) DBSession.add(task) task.notes.append(request_review_note) try: DBSession.commit() except IntegrityError as e: DBSession.rollback() QtWidgets.QMessageBox.critical( self, 'Error', 'Database Error!!!' '<br>' '%s' % e ) return # Fix statuses from anima import utils utils.fix_task_statuses(task) try: DBSession.commit() except IntegrityError as e: DBSession.rollback() QtWidgets.QMessageBox.critical( self, 'Error', 'Database Error!!!' '<br>' '%s' % e ) return # if nothing bad happens close the dialog super(MainDialog, self).accept()
def test_content_argument_is_set_to_empty_string(self): """testing if nothing is going to happen when content argument is given as an empty string """ self.kwargs["content"] = "" Note(**self.kwargs)
def accept(self): """overridden accept method """ # get the info task = self.tasks_comboBox.currentTask() resource = self.get_current_resource() # war the user if the resource is not the logged_in_user if resource != self.logged_in_user: msg_box = QtWidgets.QMessageBox(self) msg_box.setWindowTitle('Baskasi Adina TimeLog Giriyorsun') msg_box.setText('Baskasi adina TimeLog giriyorsun???') accept_button = msg_box.addButton('Sorumlulugu Kabul Ediyorum', QtWidgets.QMessageBox.AcceptRole) cancel_button = msg_box.addButton('Cancel', QtWidgets.QMessageBox.RejectRole) msg_box.setDefaultButton(cancel_button) msg_box.exec_() clicked_button = msg_box.clickedButton() if clicked_button == cancel_button: return description = self.description_plainTextEdit.toPlainText() revision_cause_text = \ self.revision_type_comboBox.currentText().replace(' ', '_') is_complete = self.set_as_complete_radioButton.isChecked() submit_to_final_review = \ self.submit_for_final_review_radioButton.isChecked() # get the revision Types from stalker import Type revision_type = Type.query\ .filter(Type.target_entity_type == 'Note')\ .filter(Type.name == revision_cause_text)\ .first() date = self.calendarWidget.selectedDate() start = self.start_timeEdit.time() end = self.end_timeEdit.time() # construct proper datetime.DateTime instances import datetime start_date = datetime.datetime(date.year(), date.month(), date.day(), start.hour(), start.minute()) end_date = datetime.datetime(date.year(), date.month(), date.day(), end.hour(), end.minute()) today_midnight = datetime.datetime.now().replace(hour=23, minute=59, second=59, microsecond=999) # raise an error if the user is trying to enter a TimeLog to the future if start_date > today_midnight or end_date > today_midnight: QtWidgets.QMessageBox.critical( self, 'Error', 'Gelecege TimeLog giremezsiniz!!!', ) return # convert them to utc from anima.utils import local_to_utc utc_start_date = local_to_utc(start_date) utc_end_date = local_to_utc(end_date) # create a TimeLog # print('Task : %s' % task.name) # print('Resource : %s' % resource.name) # print('utc_start_date: %s' % utc_start_date) # print('utc_end_date : %s' % utc_end_date) # now if we are not using extra time just create the TimeLog from stalker import db, TimeLog from stalker.exceptions import OverBookedError utc_now = local_to_utc(datetime.datetime.now()) if not self.timelog: try: new_time_log = TimeLog(task=task, resource=resource, start=utc_start_date, end=utc_end_date, description=description, date_created=utc_now) except OverBookedError: # inform the user that it can not do that QtWidgets.QMessageBox.critical( self, 'Error', 'O saatte baska time log var!!!') return from sqlalchemy.exc import IntegrityError try: db.DBSession.add(new_time_log) db.DBSession.commit() self.timelog_created = True except IntegrityError as e: QtWidgets.QMessageBox.critical( self, 'Error', 'Database hatasi!!!' '<br>' '%s' % e) db.DBSession.rollback() return else: # just update the date values self.timelog.start = utc_start_date self.timelog.end = utc_end_date self.timelog.date_updated = utc_now db.DBSession.add(self.timelog) db.DBSession.commit() if self.no_time_left: # we have no time left so automatically extend the task from stalker import Task schedule_timing, schedule_unit = \ task.least_meaningful_time_unit( task.total_logged_seconds ) if schedule_timing != 0: task.schedule_timing = schedule_timing task.schedule_unit = schedule_unit # also create a Note from stalker import Note new_note = Note( content='Extending timing of the task <b>%s h %s min.</b>' % (self.extended_hours, self.extended_minutes), type=revision_type, created_by=self.logged_in_user, date_created=local_to_utc(datetime.datetime.now())) db.DBSession.add(new_note) task.notes.append(new_note) try: db.DBSession.commit() except IntegrityError as e: QtWidgets.QMessageBox.critical( self, 'Error', 'Database hatasi!!!' '<br>' '%s' % e) db.DBSession.rollback() return if is_complete: # set the status to complete from stalker import Type, Status status_cmpl = Status.query.filter(Status.code == 'CMPL').first() forced_status_type = \ Type.query.filter(Type.name == 'Forced Status').first() # also create a Note from stalker import Note new_note = Note( content='%s has changed this task status to Completed' % resource.name, type=forced_status_type, created_by=self.logged_in_user, date_created=local_to_utc(datetime.datetime.now())) db.DBSession.add(new_note) task.notes.append(new_note) task.status = status_cmpl db.DBSession.commit() task.update_parent_statuses() db.DBSession.commit() elif submit_to_final_review: # clip the Task timing to current time logs from stalker import Task schedule_timing, schedule_unit = \ task.least_meaningful_time_unit( task.total_logged_seconds ) task.schedule_timing = schedule_timing task.schedule_unit = schedule_unit db.DBSession.add(task) try: db.DBSession.commit() except IntegrityError as e: QtWidgets.QMessageBox.critical( self, 'Error', 'Database hatasi!!!' '<br>' '%s' % e) db.DBSession.rollback() return # request a review reviews = task.request_review() utc_now = local_to_utc(datetime.datetime.now()) for review in reviews: review.created_by = review.updated_by = self.logged_in_user review.date_created = utc_now review.date_updated = utc_now db.DBSession.add_all(reviews) # and create a Note for the Task request_review_note_type = \ Type.query\ .filter(Type.target_entity_type == 'Note')\ .filter(Type.name == 'Request Review')\ .first() from stalker import Note request_review_note = Note(type=request_review_note_type, created_by=self.logged_in_user, date_created=local_to_utc( datetime.datetime.now())) db.DBSession.add(request_review_note) db.DBSession.add(task) task.notes.append(request_review_note) try: db.DBSession.commit() except IntegrityError as e: QtWidgets.QMessageBox.critical( self, 'Error', 'Database hatasi!!!' '<br>' '%s' % e) db.DBSession.rollback() return # if nothing bad happens close the dialog super(MainDialog, self).accept()