Exemplo n.º 1
0
def milestone_add_typed(request, project_id=None, response_format='html'):
    """Milestone add to preselected project"""

    project = None
    if project_id:
        project = get_object_or_404(Project, pk=project_id)
        if not request.user.profile.has_permission(project, mode='x'):
            project = None

    if request.POST:
        if 'cancel' not in request.POST:
            milestone = Milestone()
            form = MilestoneForm(
                request.user.profile, project_id, request.POST, instance=milestone)
            if form.is_valid():
                milestone = form.save()
                milestone.set_user_from_request(request)
                return HttpResponseRedirect(reverse('projects_milestone_view', args=[milestone.id]))
        else:
            return HttpResponseRedirect(reverse('projects'))
    else:
        form = MilestoneForm(request.user.profile, project_id)

    context = _get_default_context(request)
    context.update({'form': form, 'project': project})

    return render_to_response('projects/milestone_add_typed', context,
                              context_instance=RequestContext(request), response_format=response_format)
Exemplo n.º 2
0
    def setUp(self):
        self.group, created = Group.objects.get_or_create(name='test')
        self.user, created = DjangoUser.objects.get_or_create(username=self.username)
        self.user.set_password(self.password)
        self.user.save()
        perspective, created = Perspective.objects.get_or_create(name='default')
        perspective.set_default_user()
        perspective.save()

        ModuleSetting.set('default_perspective', perspective.id)

        self.contact_type = ContactType(name='test')
        self.contact_type.set_default_user()
        self.contact_type.save()

        self.contact = Contact(name='test', contact_type=self.contact_type)
        self.contact.related_user = self.user.profile
        self.contact.set_default_user()
        self.contact.save()

        self.project = Project(name='test', manager=self.contact, client=self.contact)
        self.project.set_default_user()
        self.project.save()

        self.status = TaskStatus(name='test')
        self.status.set_default_user()
        self.status.save()

        self.milestone = Milestone(name='test', project=self.project, status=self.status)
        self.milestone.set_default_user()
        self.milestone.save()

        self.task = Task(name='test', project=self.project, status=self.status, caller=self.contact)
        self.task.set_default_user()
        self.task.save()

        self.task_assigned = Task(name='test', project=self.project, status=self.status)
        self.task_assigned.save()
        self.task_assigned.assigned.add(self.user.profile)

        self.time_slot = TaskTimeSlot(task=self.task, details='test', time_from=datetime.now(), user=self.user.profile)
        self.time_slot.set_default_user()
        self.time_slot.save()

        self.parent = Project(name='test')
        self.parent.set_default_user()
        self.parent.save()

        self.parent_task = Task(
            name='test', project=self.project, status=self.status, priority=3)
        self.parent_task.set_default_user()
        self.parent_task.save()

        self.client = Client()

        self.client.login(username=self.username, password=self.password)
Exemplo n.º 3
0
 def goal_copy(goal_id):
     from models import Goal, Milestone
     goal = Goal.objects.get_or_404(id=goal_id)
     if (goal.user.id == current_user.get_id()):
         abort(410)
     else:
         new_goal = Goal(title=goal.title, description=goal.description, user=current_user.self(), original=goal)
         new_goal.save()
         milestones = Milestone.objects(goal=goal.id)
         for milestone in milestones:
             new_milestone = Milestone(goal=new_goal, message=milestone.message)
             new_milestone.save()
         return redirect("/goal/%s" % new_goal.id)
Exemplo n.º 4
0
	def post(self):
		try:
			# get the data that they wish to add
			city = self.request.get('city')
			miles = self.request.get('miles')

			# if the user has input something for BOTH fields
			if city and miles:
				newMilestone = Milestone(id = city, city_name = city, goalMiles = float(miles))
				newMilestone.put()

			self.redirect('/milestones')
		except Exception, e:
			logging.error(e)
			self.response.out.write('Error adding milestone to datastore!')
			self.response.out.write(e)
Exemplo n.º 5
0
 def goal(goal_id):
     from models import Goal, Milestone
     goal = Goal.objects.get_or_404(id=goal_id)
     milestones = Milestone.objects(goal=goal)
     goal.views = goal.views + 1
     goal.save()
     return render_template("goal/goal.html", goal=goal, milestones=milestones)
Exemplo n.º 6
0
	def get(self):
		# get all milestones
		milestones = Milestone.query().order(Milestone.goalMiles)

		# render milestones.html with all milestones
		self.render('html/milestones.html', {
			'milestones' : milestones
		})
Exemplo n.º 7
0
 def milestone_new(goal_id):
     from models import Goal, Milestone
     form = NewGoalForm(request.form)
     goal = Goal.objects.get_or_404(id=goal_id)
     form = NewMilestoneForm(request.form)
     new_status = "form"
     if request.method == "POST":
         if (current_user.get_id() == goal.user.id):
             try:
                 new_milestone = Milestone(message=form.message.data, goal=goal)
                 new_milestone.save()
                 new_status = "success"
             except OperationError:
                 new_status = "fail"
         else:
             new_status = "fail"
     return render_template("milestone/new.html", goal=goal, form=form, new_status=new_status)
Exemplo n.º 8
0
	def get(self):
		# get the chosen milestone
		modify_id = self.request.get('id')

		chosen_milestone = Milestone.query(Milestone.city_name == modify_id).get()

		self.render('html/modifyMilestone.html', {
			'milestone' : chosen_milestone
		})
Exemplo n.º 9
0
def milestone_add(request, response_format='html'):
    """New milestone form"""

    if request.POST:
        if 'cancel' not in request.POST:
            milestone = Milestone()
            form = MilestoneForm(
                request.user.profile, None, request.POST, instance=milestone)
            if form.is_valid():
                milestone = form.save()
                milestone.set_user_from_request(request)
                return HttpResponseRedirect(reverse('projects_milestone_view', args=[milestone.id]))
        else:
            return HttpResponseRedirect(reverse('projects'))
    else:
        form = MilestoneForm(request.user.profile, None)

    context = _get_default_context(request)
    context.update({'form': form})

    return render_to_response('projects/milestone_add', context,
                              context_instance=RequestContext(request), response_format=response_format)
Exemplo n.º 10
0
	def post(self):
		try:
			# get the city name of the milestone that they wish to delete
			deleteChoice = self.request.get('id')

			toDelete = Milestone.query(Milestone.city_name == deleteChoice).get()
			
			# delete from the datastore
			toDelete.key.delete()

			self.redirect('/milestones')
		except Exception as e:
			self.response.write('<html><body>Error deleting milestone!<br>')
			self.response.write(e)
			self.response.write(BACK_BUTTON)
			logging.error(e)
Exemplo n.º 11
0
def add_a_milestone():
    req_data = request.get_json()

    start = req_data['start']
    end = req_data['end']
    description = req_data['description']
    person_id = req_data['person_id']

    try:
        milestone = Milestone(start=start,
                              end=end,
                              description=description,
                              person_id=person_id)
        db.session.add(milestone)
        db.session.commit()
        return "Milestone added. Milestone id = {}".format(milestone.id)
    except Exception as e:
        return (str(e))
Exemplo n.º 12
0
	def post(self):
		modify_id = self.request.get('id')
		chosen_milestone = Milestone.query(Milestone.city_name == modify_id).get()

		try:
			# get the new values
			newCity = self.request.get('city')
			newMiles = self.request.get('miles')

			# update the milestone and add changes to datastore
			chosen_milestone.city_name = newCity
			chosen_milestone.goalMiles = float(newMiles)
			chosen_milestone.put()

			self.redirect('/milestones')
		except Exception, e:
			logging.error(e)
			self.response.write('<html><body>Error modifying milestone!<br>')
			self.response.write(e)
			self.response.write(BACK_BUTTON)
Exemplo n.º 13
0
    def get(self):
        # a list of teachers that have completed their milestone objective
        teacherList = []

        # get a list of all teachers
        allTeachers = Teacher.query()

        # iterate through all teachers
        for teacher in allTeachers:
            # get the current milestone for the teacher
            if not teacher.currentMilestone:
                currentMilestone = Milestone.query().order(Milestone.goalMiles).get()
                teacher.currentMilestone = currentMilestone.key
                teacher.put()
            else:
                currentMilestone = teacher.currentMilestone.get()
            
            # if the totalClassMiles of a teacher is >= its current milestone goal:
            if teacher.totalClassMiles >= currentMilestone.goalMiles:
                # add the teacher to the list
                teacherList.append((teacher.name, currentMilestone.city_name))

                # find the next milestone and assign it to the teacher
                nextMilestone = Milestone.query(Milestone.goalMiles > int(teacher.totalClassMiles)).order(Milestone.goalMiles).get()

                # check if there is a milestone
                if nextMilestone:
                    teacher.currentMilestone = nextMilestone.key
                    teacher.put()

        # if the teacherList is not empty
        if teacherList:
            # create an email to send to the teacher with the names of the teacher
            rowTemplate = Template("""
                <tr>
                    <td>$teacher</td>
                    <td>$milestone</td>
                </tr>
            """)


            body = """
            <html><body>
                <center><h2>Milestone Reached!</h2></center>
                The following teachers have reached their milestones:<br>
                <table width='30%' border='1'>
                    <tr>
                        <th>Teacher Name</th>
                        <th>Milestone</th>
                    </tr>
            """

            # for every teacher name that has passed their milestone
            for t, m in teacherList:
                body = body + rowTemplate.substitute(teacher=t, milestone=m)

            body = body + """
                </table>
            </body></html>
            """

            subject = 'A Milestone Has Been Reached! ' + str(date.today())
            app_id = app_identity.get_application_id()
            mail.send_mail_to_admins("support@"+app_id+".appspotmail.com", subject, body, html=body)
Exemplo n.º 14
0
class ProjectsViewsTest(TestCase):
    username = "******"
    password = "******"

    def setUp(self):
        self.group, created = Group.objects.get_or_create(name='test')
        self.user, created = DjangoUser.objects.get_or_create(username=self.username)
        self.user.set_password(self.password)
        self.user.save()
        perspective, created = Perspective.objects.get_or_create(name='default')
        perspective.set_default_user()
        perspective.save()

        ModuleSetting.set('default_perspective', perspective.id)

        self.contact_type = ContactType(name='test')
        self.contact_type.set_default_user()
        self.contact_type.save()

        self.contact = Contact(name='test', contact_type=self.contact_type)
        self.contact.related_user = self.user.profile
        self.contact.set_default_user()
        self.contact.save()

        self.project = Project(name='test', manager=self.contact, client=self.contact)
        self.project.set_default_user()
        self.project.save()

        self.status = TaskStatus(name='test')
        self.status.set_default_user()
        self.status.save()

        self.milestone = Milestone(name='test', project=self.project, status=self.status)
        self.milestone.set_default_user()
        self.milestone.save()

        self.task = Task(name='test', project=self.project, status=self.status, caller=self.contact)
        self.task.set_default_user()
        self.task.save()

        self.task_assigned = Task(name='test', project=self.project, status=self.status)
        self.task_assigned.save()
        self.task_assigned.assigned.add(self.user.profile)

        self.time_slot = TaskTimeSlot(task=self.task, details='test', time_from=datetime.now(), user=self.user.profile)
        self.time_slot.set_default_user()
        self.time_slot.save()

        self.parent = Project(name='test')
        self.parent.set_default_user()
        self.parent.save()

        self.parent_task = Task(
            name='test', project=self.project, status=self.status, priority=3)
        self.parent_task.set_default_user()
        self.parent_task.save()

        self.client = Client()

        self.client.login(username=self.username, password=self.password)

    def test_index(self):
        """Test project index page with login at /projects/"""
        response = self.client.get(reverse('projects'))
        self.assertEquals(response.status_code, 200)

    def assertQuerysetEqual(self, qs, values, transform=repr, ordered=True, msg=None):
        return super(ProjectsViewsTest, self).assertQuerysetEqual(qs, map(repr, values), transform, ordered, msg)

    def test_index_owned(self):
        """Test owned tasks page at /task/owned/"""
        response = self.client.get(reverse('projects_index_owned'))
        self.assertEquals(response.status_code, 200)
        self.assertQuerysetEqual(response.context['milestones'], [self.milestone])
        self.assertQuerysetEqual(response.context['tasks'], [self.task])
        self.assertEqual(type(response.context['filters']), FilterForm)
        # todo: actually test the form generated, if it has the right fields and querysets
        # self.assertEqual(str(response.context['filters']), str(filterform))

    def test_index_assigned(self):
        """Test assigned tasks page at /task/assigned/"""
        response = self.client.get(reverse('projects_index_assigned'))
        self.assertEquals(response.status_code, 200)
        self.assertQuerysetEqual(response.context['milestones'], [self.milestone])
        self.assertQuerysetEqual(response.context['tasks'], [self.task_assigned])
        self.assertEqual(type(response.context['filters']), FilterForm)

    # Projects
    def test_project_add(self):
        """Test index page with login at /projects/add/"""
        response = self.client.get(reverse('project_add'))
        self.assertEquals(response.status_code, 200)
        self.assertEqual(type(response.context['form']), ProjectForm)

        projects_qty = Project.objects.count()
        form_params = {'name': 'project_name', 'details': 'new project details'}
        response = self.client.post(reverse('project_add'), data=form_params)
        self.assertEquals(response.status_code, 302)
        project_id = response['Location'].split('/')[-1]
        self.assertRedirects(response, reverse('projects_project_view', args=[project_id]))
        self.assertEqual(Project.objects.count(), projects_qty+1)
        project = Project.objects.get(id=project_id)
        self.assertEqual(project.name, form_params['name'])
        self.assertEqual(project.details, form_params['details'])

    def test_project_add_typed(self):
        """Test index page with login at /projects/add/<project_id>/"""
        response = self.client.get(reverse('projects_project_add_typed', args=[self.parent.id]))
        self.assertEquals(response.status_code, 200)

    def test_project_view_login(self):
        """Test index page with login at /projects/view/<project_id>"""
        response = self.client.get(reverse('projects_project_view', args=[self.project.id]))
        self.assertEquals(response.status_code, 200)

    def test_project_edit_login(self):
        """Test index page with login at /projects/edit//<project_id>"""
        response = self.client.get(reverse('projects_project_edit', args=[self.project.id]))
        self.assertEquals(response.status_code, 200)

    def test_project_delete_login(self):
        """Test index page with login at /projects/delete//<project_id>"""
        response = self.client.get(reverse('projects_project_delete', args=[self.project.id]))
        self.assertEquals(response.status_code, 200)

    # Milestones
    def test_milestone_add(self):
        """Test index page with login at /projects/milestone/add"""
        response = self.client.get(reverse('projects_milestone_add'))
        self.assertEquals(response.status_code, 200)

    def test_milestone_add_typed(self):
        """Test index page with login at /projects/milestone/add/<project_id>"""
        response = self.client.get(reverse('projects_milestone_add_typed', args=[self.parent.id]))
        self.assertEquals(response.status_code, 200)

    def test_milestone_view_login(self):
        """Test index page with login at /projects/milestone/view/<milestone_id>"""
        response = self.client.get(reverse('projects_milestone_view', args=[self.milestone.id]))
        self.assertEquals(response.status_code, 200)

    def test_milestone_edit_login(self):
        """Test index page with login at /projects/milestone/edit/<milestone_id>"""
        response = self.client.get(reverse('projects_milestone_edit', args=[self.milestone.id]))
        self.assertEquals(response.status_code, 200)

    def test_milestone_delete_login(self):
        """Test index page with login at /projects/milestone/delete/<milestone_id>"""
        response = self.client.get(reverse('projects_milestone_delete', args=[self.milestone.id]))
        self.assertEquals(response.status_code, 200)

    # Tasks
    def test_task_add(self):
        """Test index page with login at /projects/task/add/"""
        response = self.client.get(reverse('projects_task_add'))
        self.assertEquals(response.status_code, 200)

    def test_task_add_typed(self):
        """Test index page with login at /projects/task/add/<project_id>"""
        response = self.client.get(reverse('projects_task_add_typed', args=[self.project.id]))
        self.assertEquals(response.status_code, 200)

    def test_task_add_to_milestone(self):
        """Test index page with login at /projects/task/add/<milestone_id>"""
        response = self.client.get(reverse('projects_task_add_to_milestone', args=[self.milestone.id]))
        self.assertEquals(response.status_code, 200)

    def test_task_add_subtask(self):
        """Test index page with login at /projects/task/add/<task_id>/"""
        response = self.client.get(reverse('projects_task_add_subtask', args=[self.parent_task.id]))
        self.assertEquals(response.status_code, 200)

    def test_task_set_status(self):
        """Test index page with login at /projects/task/add/<task_id>/status/<status_id>"""
        response = self.client.get(reverse('projects_task_set_status', args=[self.task.id, self.status.id]))
        self.assertEquals(response.status_code, 200)

    def test_task_view_login(self):
        """Test index page with login at /projects/task/view/<task_id>"""
        response = self.client.get(reverse('projects_task_view', args=[self.task.id]))
        self.assertEquals(response.status_code, 200)

    def test_task_edit_login(self):
        """Test index page with login at /projects/task/edit/<task_id>"""
        response = self.client.get(reverse('projects_task_edit', args=[self.task.id]))
        self.assertEquals(response.status_code, 200)

    def test_task_delete_login(self):
        """Test index page with login at /projects/task/delete/<task_id>"""
        response = self.client.get(reverse('projects_task_delete', args=[self.task.id]))
        self.assertEquals(response.status_code, 200)

    # Task Time Slots
    def test_time_slot_add(self):
        """Test index page with login at /projects/task/view/time/<task_id>add/"""
        response = self.client.get(reverse('projects_task_time_slot_add', args=[self.task.id]))
        self.assertEquals(response.status_code, 200)

    def test_time_slot_view_login(self):
        """Test index page with login at /projects/task/view/time/<time_slot_id>"""
        response = self.client.get(reverse('projects_task_view', args=[self.task.id]))
        self.assertEquals(response.status_code, 200)

    def test_time_slot_edit_login(self):
        """Test index page with login at /projects/task/edit/time/<time_slot_id>"""
        response = self.client.get(reverse('projects_task_edit', args=[self.task.id]))
        self.assertEquals(response.status_code, 200)

    def test_time_slot_delete_login(self):
        """Test index page with login at /projects/task/delete/time/<time_slot_id>"""
        response = self.client.get(reverse('projects_task_delete', args=[self.task.id]))
        self.assertEquals(response.status_code, 200)

    # Task Statuses
    def test_task_status_add(self):
        """Test index page with login at /projects/task/status/add/"""
        response = self.client.get(reverse('projects_task_status_add'))
        self.assertEquals(response.status_code, 200)

    def test_task_status_view_login(self):
        """Test index page with login at /projects/task/status/view/<status_id>/"""
        response = self.client.get(reverse('projects_index_by_status', args=[self.status.id]))
        self.assertEquals(response.status_code, 200)

    def test_task_status_edit_login(self):
        """Test index page with login at /projects/task/status/edit/<status_id>/"""
        response = self.client.get(reverse('projects_task_status_edit', args=[self.status.id]))
        self.assertEquals(response.status_code, 200)

    def test_task_status_delete_login(self):
        """Test index page with login at /projects/task/status/delete/<status_id>/"""
        response = self.client.get(reverse('projects_task_status_delete', args=[self.status.id]))
        self.assertEquals(response.status_code, 200)

    # Settings

    def test_project_settings_view(self):
        """Test index page with login at /projects/settings/view/"""
        response = self.client.get(reverse('projects_settings_view'))
        self.assertEquals(response.status_code, 200)

    def test_project_settings_edit(self):
        """Test index page with login at /projects/settings/edit/"""
        response = self.client.get(reverse('projects_settings_edit'))
        self.assertEquals(response.status_code, 200)
Exemplo n.º 15
0
 def test_model_milestone(self):
     tstatus = TaskStatus(name='test')
     tstatus.save()
     mstone = Milestone(project=self.project, status=tstatus)
     mstone.save()
     mstone.get_absolute_url()