Exemplo n.º 1
0
    def render(
        self,
        request,
        event,
        detail_template_name="timeline/fogbugz_event_detail.html",
        commands_template_name="timeline/fogbugz_event_commands.html",
    ):
        task = event.task
        if not task:
            return HttpResponse()

        cmds = []
        events = []

        tracker = BugTrackerFactory.get_bug_tracker_instance(task.bug_tracker)
        if tracker:
            cmds, events = tracker.get_events_for_bug(task.bug_tracker.base_url, task.remote_tracker_id)

        return HttpResponse(
            simplejson.dumps(
                {
                    "commands": render_to_string(commands_template_name, {"commands": cmds}),
                    "detail": render_to_string(
                        detail_template_name, {"events": events, "task": task, "snap": task.get_latest_snapshot()}
                    ),
                }
            )
        )
Exemplo n.º 2
0
    def clean(self):
        backend = self.cleaned_data['backend']
        base_url = self.cleaned_data['base_url']
        username = self.cleaned_data['username']
        password = self.cleaned_data['password']

        # Allow null backends
        if backend == '' or backend == None:
            return self.cleaned_data

        tracker = BugTrackerFactory.get_bug_tracker()
        if tracker.validate_backend(backend):
            client = tracker(base_url, backend)
            if not client.login(username, password):
                raise forms.ValidationError(
                    _('Authentication credentials could not be validated.  Either your username or password is incorrect, or the server could not be reached.'
                      ))
        else:
            self._errors['backend'] = ErrorList([
                _("Backend '%s' could not be found.  Make sure it can be found in berserk2.bugtrackers.bugzilla.backends."
                  ) % backend
            ])
            del self.cleaned_data['backend']

        return self.cleaned_data
Exemplo n.º 3
0
def sprint_current_bookmarklet(request):
    def redirect(error=None, notice=None):
        if error is not None:
            request.flash['error'] = error
        if notice is not None:
            request.flash['notice'] = notice
        return HttpResponseRedirect(reverse('sprint_edit',
                                            kwargs={'sprint_id': sprint.id}))

    sprint = Sprint.objects.current()
    if sprint == None or request.method != 'GET':
        return HttpResponseRedirect(reverse('sprint_index'))

    tracker = BugTrackerFactory.get_bug_tracker()
    if not tracker:
        return redirect(error=_('Your bug tracker has not been set up yet.'))

    base_url = sprint.default_bug_tracker.base_url
    remote_tracker_id = tracker.get_id_from_url(urllib.unquote(request.GET['url']),
                                                base_url)

    if not remote_tracker_id:
        return redirect(error=_('I don\'t recognize this type of URL.'))

    result = _add_task(request, sprint, sprint.default_bug_tracker,
                       remote_tracker_id)
    if 'error' in result:
        return redirect(error=result['error'])
    elif 'notice' in result:
        return redirect(notice=result['notice'])
    return redirect()
Exemplo n.º 4
0
    def snapshot_statistics(self):
        """
        Fetches the latest statistics about the milestone from the remote
        tracker.
        """
        tracker = BugTrackerFactory.get_bug_tracker()
        try:
            client = tracker(self.bug_tracker.base_url,
                             self.bug_tracker.backend)
        except AttributeError:
            logging.error('Backend %s not found' % self.bug_tracker.backend)
            return None

        if not client.login(self.bug_tracker.username,
                            self.bug_tracker.password):
            logging.error('Could not authenticate with bug tracker')
            return None

        stats = client.get_stats_for_milestone(self.bug_tracker.product,
                                               self.remote_tracker_name)

        stat, created = MilestoneStatisticsCache.objects.get_or_create(date=date.today(),
                                                                       milestone=self)
        stat.total_open_tasks = stats[0]
        stat.total_estimated_hours = stats[1]
        stat.total_remaining_hours = stats[2]
        stat.save()
        return stat
Exemplo n.º 5
0
    def snapshot(self):
        """
        Creates a new TaskSnapshot from the most recent bug tracke data. Returns
        the new snapshot if successful, None otherwise.
        """
        def lookup_user(email):
            users = User.objects.filter(email=email)
            return users[0] if users.count() > 0 else None

        tracker = BugTrackerFactory.get_bug_tracker()
        try:
            client = tracker(self.bug_tracker.base_url,
                             self.bug_tracker.backend)
        except AttributeError:
            logging.error('Backend %s not found' % self.bug_tracker.backend)
            return None

        if not client.login(self.bug_tracker.username,
                            self.bug_tracker.password):
            logging.error('Could not authenticate with bug tracker')
            return None

        bug = client.get_bug(self.remote_tracker_id)
        return TaskSnapshot.objects.create(task=self, title=bug.summary,
                                           component=bug.component, status=bug.status,
                                           submitted_by=lookup_user(bug.submitted_by),
                                           assigned_to=lookup_user(bug.assigned_to),
                                           estimated_hours=int(bug.estimated_time),
                                           actual_hours=int(bug.actual_time),
                                           remaining_hours=int(bug.remaining_time))
Exemplo n.º 6
0
    def render(self,
               request,
               event,
               detail_template_name='timeline/fogbugz_event_detail.html',
               commands_template_name='timeline/fogbugz_event_commands.html'):
        task = event.task
        if not task:
            return HttpResponse()

        cmds = []
        events = []

        tracker = BugTrackerFactory.get_bug_tracker_instance(task.bug_tracker)
        if tracker:
            cmds, events = tracker.get_events_for_bug(
                task.bug_tracker.base_url, task.remote_tracker_id)

        return HttpResponse(
            simplejson.dumps({
                'commands':
                render_to_string(commands_template_name, {'commands': cmds}),
                'detail':
                render_to_string(
                    detail_template_name, {
                        'events': events,
                        'task': task,
                        'snap': task.get_latest_snapshot()
                    })
            }))
Exemplo n.º 7
0
    def snapshot_statistics(self):
        """
        Fetches the latest statistics about the milestone from the remote
        tracker.
        """
        client = BugTrackerFactory.get_bug_tracker_instance(self.bug_tracker)
        if not client:
            return None

        stats = client.get_stats_for_milestone(self.bug_tracker.product,
                                               self.remote_tracker_name)

        stat, created = MilestoneStatisticsCache.objects.get_or_create(
            date=date.today(), milestone=self)
        stat.total_open_tasks = stats[0]
        stat.total_estimated_hours = stats[1]
        stat.total_remaining_hours = stats[2]
        stat.save()
        return stat
Exemplo n.º 8
0
    def snapshot_statistics(self):
        """
        Fetches the latest statistics about the milestone from the remote
        tracker.
        """
        client = BugTrackerFactory.get_bug_tracker_instance(self.bug_tracker)
        if not client:
            return None

        stats = client.get_stats_for_milestone(self.bug_tracker.product,
                                               self.remote_tracker_name)

        stat, created = MilestoneStatisticsCache.objects.get_or_create(date=date.today(),
                                                                       milestone=self)
        stat.total_open_tasks = stats[0]
        stat.total_estimated_hours = stats[1]
        stat.total_remaining_hours = stats[2]
        stat.save()
        return stat
Exemplo n.º 9
0
    def snapshot(self):
        """
        Creates a new TaskSnapshot from the most recent bug tracke data. Returns
        the new snapshot if successful, None otherwise.
        """
        def lookup_user(email):
            users = User.objects.filter(email=email)
            return users[0] if users.count() > 0 else None

        client = BugTrackerFactory.get_bug_tracker_instance(self.bug_tracker)
        if not client:
            return None

        bug = client.get_bug(self.remote_tracker_id)
        return TaskSnapshot.objects.create(task=self, title=bug.summary,
                                           component=bug.component, status=bug.status,
                                           submitted_by=lookup_user(bug.submitted_by),
                                           assigned_to=lookup_user(bug.assigned_to),
                                           estimated_hours=int(bug.estimated_time),
                                           actual_hours=int(bug.actual_time),
                                           remaining_hours=int(bug.remaining_time))
Exemplo n.º 10
0
    def clean(self):
        backend = self.cleaned_data['backend']
        base_url = self.cleaned_data['base_url']
        username = self.cleaned_data['username']
        password = self.cleaned_data['password']

        # Allow null backends
        if backend == '' or backend == None:
            return self.cleaned_data

        tracker = BugTrackerFactory.get_bug_tracker()
        if tracker.validate_backend(backend):
            client = tracker(base_url, backend)
            if not client.login(username, password):
                raise forms.ValidationError(_('Authentication credentials could not be validated.  Either your username or password is incorrect, or the server could not be reached.'))
        else:
            self._errors['backend'] = ErrorList([
                _("Backend '%s' could not be found.  Make sure it can be found in berserk2.bugtrackers.bugzilla.backends.") % backend
            ])
            del self.cleaned_data['backend']

        return self.cleaned_data
Exemplo n.º 11
0
    def snapshot(self):
        """
        Creates a new TaskSnapshot from the most recent bug tracke data. Returns
        the new snapshot if successful, None otherwise.
        """
        def lookup_user(email):
            users = User.objects.filter(email=email)
            return users[0] if users.count() > 0 else None

        client = BugTrackerFactory.get_bug_tracker_instance(self.bug_tracker)
        if not client:
            return None

        bug = client.get_bug(self.remote_tracker_id)
        return TaskSnapshot.objects.create(
            task=self,
            title=bug.summary,
            component=bug.component,
            status=bug.status,
            submitted_by=lookup_user(bug.submitted_by),
            assigned_to=lookup_user(bug.assigned_to),
            estimated_hours=int(bug.estimated_time),
            actual_hours=int(bug.actual_time),
            remaining_hours=int(bug.remaining_time))
Exemplo n.º 12
0
 def get_remote_task_url(self, task):
     tracker = BugTrackerFactory.get_bug_tracker()
     return tracker.get_url_from_id(task.remote_tracker_id, self.base_url)