Ejemplo n.º 1
0
Archivo: views.py Proyecto: CSIOM/piPi
    def post(self, request):
        self.user = request.user
        reportform = AddReportForm(self.user, request.POST)
        reportitemform = ReportItemForm(request.POST)
        timer_status = '0'
        
        if reportform.is_valid() and reportitemform.is_valid():
            project = request.POST['project']
            report_id = DailyReport.objects.values_list('id',flat=True).filter(user=self.user.id).\
                filter(project=project).filter(date=datetime.date.today())
            if report_id:
                reportformdata = DailyReport.objects.get(pk=report_id[0])
            else:
                reportformdata = reportform.save()
            cd = reportitemform.cleaned_data
            self_rating = cd['self_rating']
            duration = cd['duration_in_hours']
            work_done = cd['work_done']
            struggle = cd['struggle']
            tags = cd['tags']
            reportitemformdata = DailyReportItem(daily_report=reportformdata,
                self_rating=self_rating, duration_in_hours=duration,
                work_done=work_done, struggle=struggle, tags=tags)
            reportitemformdata.save()
            message = "Report Added"
            self.reset_timer(request)
            try:
                time = TimeTrackingData.objects.get(user=self.user.id)
            except:
                time = ''
            dailyreportobject = DailyReport.objects.get(pk=reportformdata.id)
            dailyreportobj = DailyReport.objects.values('project__project__manager').\
            filter(id=reportformdata.id)[0]
            user_obj = User.objects.get(pk=dailyreportobj['project__project__manager'])
            if self.user != user_obj:
                notification_type = NotificationType.objects.get(name='Report')
                notifications = Notifications(notification_type=notification_type)
                notifications.save()
                notifications_obj = Notifications.objects.get(id=notifications.id)
                report_notifications = ReportNotifications(report=dailyreportobject,
                    notifier=user_obj, notifications=notifications_obj)
                report_notifications.save()
                try:
                    if time:
                        timer_status = '1'
                    else:
                        timer_status = '0'
                except:
                    pass

            return render(request,'users/report_success.html',{'message':message,
                'status':timer_status})
        else:
            reportform = AddReportForm(self.user, request.POST)
            reportitemform = ReportItemForm(request.POST)
            timer_stoped = 1
            timer_status = 0
            return render(request,'main/time_track.html',{'reportform':reportform,
            'reportitem':reportitemform,'timer_status':timer_status,
            'timer_stoped':timer_stoped})
Ejemplo n.º 2
0
Archivo: views.py Proyecto: CSIOM/piPi
 def post(self, request):
     pro = request.user
     reportform = AddReportForm(pro, request.POST)
     reportitemform = ReportItemForm(request.POST)
     if reportform.is_valid() and reportitemform.is_valid():
         user = request.user
         project = request.POST['project']
         report_id = DailyReport.objects.values_list('id',flat=True).filter(user=request.user.id).\
             filter(project=project).filter(date=datetime.date.today())
         if report_id:
             reportformdata = DailyReport.objects.get(pk=report_id[0])
         else:
             reportformdata = reportform.save()
         self_rating_list = request.POST.getlist('self_rating')
         duration_list = request.POST.getlist('duration_in_hours')
         work_done_list = request.POST.getlist('work_done')
         struggle_list = request.POST.getlist('struggle')
         tags_list = request.POST.getlist('tags')
         i = 0
         dailyreportobject = DailyReport.objects.get(pk=reportformdata.id)
         dailyreportobj = DailyReport.objects.values('project__project__manager').\
         filter(id=reportformdata.id)[0]
         user_obj = User.objects.get(pk=dailyreportobj['project__project__manager'])
         if user != user_obj:
             notification_type = NotificationType.objects.get(name='Report')
             notifications = Notifications(notification_type=notification_type)
             notifications.save()
             notifications_obj = Notifications.objects.get(id=notifications.id)
             report_notifications = ReportNotifications(report=dailyreportobject,
                 notifier=user_obj, notifications=notifications_obj)
             report_notifications.save()
         for self_rate in self_rating_list:
             reportitemobj = DailyReportItem(daily_report=dailyreportobject,
                 self_rating=self_rate, duration_in_hours=duration_list[i],
                 work_done=work_done_list[i], struggle=struggle_list[i],
                 tags=tags_list[i])
             reportitemobj.save()
             i = i + 1
         if i == len(work_done_list):
             message = "Report Added"
             error=0
         else:
             message = 'Error: Try again later'
             error=1
         return render(request,'users/report_success.html',{'message':message,'error':error})
     else:
         pro = request.user
         reportform = AddReportForm(pro, request.POST)
         reportitemform = ReportItemForm(request.POST)
         access_var = is_manager(request)
         notice_status = read_unread_notice(request)
         comment_form = CommentForm()
         return render(request,'users/report_add.html',{'reportform':reportform,
             'reportitemform':reportitemform, 'access_var':access_var,
             'form':comment_form, 'notice_status':notice_status})
Ejemplo n.º 3
0
Archivo: views.py Proyecto: CSIOM/piPi
    def post(self, request):
        """
        saves posted comment and rating with user id and report id.
        """
        poster = request.user
        rate_form = RatingForm(request.POST)
        comment_form = CommentForm(request.POST)
        report = request.POST['report_id']
        report_obj = DailyReport.objects.get(pk=report)
        report_object = DailyReport.objects.values('user',
            'project__project__manager').get(pk=report)
        try:
            reviewer = Reviewed.objects.values('reviewer').filter(report=report)[0]
            reviewer_obj = User.objects.get(pk=reviewer['reviewer'])
        except:
            reviewer_obj = ''
        user_obj = User.objects.get(pk=report_object['user'])
        manager_obj = User.objects.get(pk=report_object['project__project__manager'])

        if comment_form.is_valid():
            formdata = comment_form.cleaned_data
            comment = formdata['comment']
            data_comment = ReportComment(comment=comment, commenter=poster, 
                report=report_obj)
            data_comment.save()
            report_comment = ReportComment.objects.get(pk=data_comment.id)
            notification_type = NotificationType.objects.get(name='Comment')
            notifications = Notifications(notification_type=notification_type)
            notifications.save()
            notifications_obj = Notifications.objects.get(id=notifications.id)
            if poster != user_obj:
                comment_notifications = CommentNotifications(report=report_obj,
                    notifier=user_obj, notifications=notifications_obj,
                    comment=report_comment)
                comment_notifications.save()
            if poster != manager_obj:
                comment_notifications = CommentNotifications(report=report_obj,
                    notifier=manager_obj, notifications=notifications_obj,
                    comment=report_comment)
                comment_notifications.save()
            if poster != reviewer_obj and reviewer_obj != '':
                comment_notifications = CommentNotifications(report=report_obj,
                    notifier=reviewer_obj, notifications=notifications_obj,
                    comment=report_comment)
                comment_notifications.save()

        if rate_form.is_valid():
            formdata = rate_form.cleaned_data
            rating = formdata['rating']
            data = Rating(rating=rating,report=report_obj,rater=poster,
                comment=data_comment)
            data.save()

        return HttpResponse('')
Ejemplo n.º 4
0
Archivo: views.py Proyecto: CSIOM/piPi
 def post(self, request):
     login_user = request.user
     manager=request.user.id
     project_form = ProjectSelectForm(manager, request.POST)
     if project_form.is_valid() or 'project_id' in request.POST:
         members = request.POST.getlist('select_members')
         try:
             project_id = request.POST['project_id']
             team = TeamMembers.objects.values_list('id',flat=True).\
                 filter(project=project_id).exclude(user = manager)
             current_team = list(TeamMembers.objects.values_list('user__id',flat=True).\
                 filter(project=project_id))
             for val in team:
                 TeamMembers.objects.filter(pk=val).update(is_active=False)
         except:
             project_id = request.POST['project']
             current_team = TeamMembers.objects.values_list('user_id',flat=True).\
                 filter(project=project_id)
         project = ProjectDetails.objects.get(pk=project_id)
         for user_id in members:
             team = TeamMembers.objects.values_list('user__id',flat=True).\
                 filter(project=project).filter(user=user_id)
             if team:
                 TeamMembers.objects.filter(project=project).filter(user=user_id).\
                 update(is_active=True)
             else:
                 user = User.objects.get(pk=user_id)
                 TeamMembers(user=user, project=project).save()
                 if user != login_user:
                     in_previous_team = False
                     for current_team_member in current_team:
                         if int(user_id) == int(current_team_member):
                             in_previous_team = True
                             break
                     if in_previous_team:
                         pass
                     else:
                         notification_type = NotificationType.objects.get(name='Team Added')
                         notifications = Notifications(notification_type=notification_type)
                         notifications.save()
                         notifications_obj = Notifications.objects.get(id=notifications.id)
                         TeamAddedNotifications(project_details=project,
                             notifier=user, notifications=notifications_obj).save()
                         temp = Context({'user':user.username,'title':project.title,
                             'manager':project.manager,'summary':project.project_summary,
                             'domain':domain,'project_id':project.id})
                         plaintext = get_template('managers/team_added_mail.txt')
                         content = get_template('managers/team_added_mail.html')
                         html_content = content.render(temp)
                         subject, from_email, to = 'You are in Team', _SENDER_EMAIL, user.email
                         text_content = plaintext.render(temp)
                         msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
                         msg.attach_alternative(html_content, "text/html")
                         msg.send()
         access_var = is_manager(request)
         notice_status = read_unread_notice(request)
         return render(request,'managers/team_added.html',{'access_var':access_var,
             'notice_status':notice_status})
     else:
         team_list = []
         team_id = User.objects.values_list('id', flat=True).order_by('username')
         for val in team_id:
             temp = {}
             temp['id'] = val
             username = User.objects.values_list('username',flat=True).filter(id=val)[0]
             temp['username'] = username
             active_projects = TeamMembers.objects.values_list('id',flat=True).\
                 filter(user=val).filter(project__is_inactive=False, is_active=True)
             project_count = len(active_projects)
             temp['project_count'] = project_count
             team_list.append(temp)
         project_form = ProjectSelectForm(manager, request.POST)
         access_var = is_manager(request)
         notice_status = read_unread_notice(request)
         return render(request,'managers/add_team.html',{'team_list':team_list,
             'project_form':project_form, 'access_var':access_var, 
             'notice_status':notice_status})