Commits

joberschweiber  committed 671f3a2

More robust handling of missing values

  • Participants
  • Parent commits e66c5dc

Comments (0)

Files changed (2)

File rhodecode/controllers/issue.py

 log = logging.getLogger(__name__)
 
 class IssueController(BaseRepoController):
-	@LoginRequired()
-	@HasRepoPermissionAnyDecorator('repository.read', 'repository.write', 'repository.admin')
+    @LoginRequired()
+    @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', 'repository.admin')
 
 
-	def __before__(self):
-		super(IssueController, self).__before__()
-	
-	def __update_labels(self, comment):
-		label_strings = ['Summary-%s' % request.POST['summary'], 'Owner-%s' % request.POST['owner'],
-			'Status-%s' % request.POST['status']]
-		i = 0
-		while ('label_%d' % i) in request.POST:
-			if len(request.POST['label_%d' % i]) == 0:
-				i += 1
-				continue
-			label_strings.append(request.POST['label_%d' % i])
-			i += 1
-		
-		cc = [x.strip() for x in request.POST['cc'].split(',')]
-		for a in cc:
-			if len(a) > 0:
-				label_strings.append('Cc-%s' % a)
-		
-		label_strings = list(Set(label_strings))
-		rhodecode.model.issue.update_issue_labels(self.sa, c.dbrepo.repo_id, c.issue.issue_no, 
-			comment.comment_no, label_strings)
-		self.sa.commit()
+    def __before__(self):
+        super(IssueController, self).__before__()
+    
+    def __update_labels(self, comment):
+        label_strings = ['Summary-%s' % request.POST['summary'], 'Owner-%s' % request.POST['owner'],
+            'Status-%s' % request.POST['status']]
+        i = 0
+        while ('label_%d' % i) in request.POST:
+            if len(request.POST['label_%d' % i]) == 0:
+                i += 1
+                continue
+            label_strings.append(request.POST['label_%d' % i])
+            i += 1
+        
+        cc = [x.strip() for x in request.POST['cc'].split(',')]
+        for a in cc:
+            if len(a) > 0:
+                label_strings.append('Cc-%s' % a)
+        
+        label_strings = list(Set(label_strings))
+        rhodecode.model.issue.update_issue_labels(self.sa, c.dbrepo.repo_id, c.issue.issue_no, 
+            comment.comment_no, label_strings)
+        self.sa.commit()
 
 
-	def view(self, repo_name, issue_no):
-		e = request.environ
-		c.dbrepo = dbrepo = c.rhodecode_db_repo
+    def view(self, repo_name, issue_no):
+        e = request.environ
+        c.dbrepo = dbrepo = c.rhodecode_db_repo
 
-		c.cursor = ''
-		if 'cursor' in request.params:
-			c.cursor = request.params['cursor']
-		c.page = ''
-		if 'page' in request.params:
-			c.page = request.params['page']
+        c.cursor = ''
+        if 'cursor' in request.params:
+            c.cursor = request.params['cursor']
+        c.page = ''
+        if 'page' in request.params:
+            c.page = request.params['page']
 
-		c.issue = self.sa.query(Issue).get((dbrepo.repo_id, issue_no))
-		c.active_labels = list(c.issue.active_labels)
-		c.stati = json_formatted_status_presets(self.sa, dbrepo.repo_id)
-		c.common_labels = json_formatted_common_labels(self.sa, dbrepo.repo_id)
-		c.starred = c.issue.starred_by(c.rhodecode_user.user_id)
-		c.cc = []
-		rem = []
-		for l in c.active_labels:
-			if l.key == 'Summary':
-				c.summary = l.value
-				rem.append(l)
-			if l.key == 'Owner':
-				c.owner = l.value
-				rem.append(l)
-			if l.key == 'Cc':
-				c.cc.append(l.value)
-				rem.append(l)
-			if l.key == 'Status':
-				c.status = l.value
-				rem.append(l)
-		for l in rem:
-			c.active_labels.remove(l)
-		c.cc_list = c.cc
-		c.cc = ','.join(c.cc)
+        c.issue = self.sa.query(Issue).get((dbrepo.repo_id, issue_no))
+        c.active_labels = list(c.issue.active_labels)
+        c.stati = json_formatted_status_presets(self.sa, dbrepo.repo_id)
+        c.common_labels = json_formatted_common_labels(self.sa, dbrepo.repo_id)
+        c.starred = c.issue.starred_by(c.rhodecode_user.user_id)
+        c.cc = []
+        rem = []
+        c.summary = '----'
+        c.owner = '----'
+        c.status = '----'
+        for l in c.active_labels:
+            if l.key == 'Summary':
+                c.summary = l.value
+                rem.append(l)
+            if l.key == 'Owner':
+                c.owner = l.value
+                rem.append(l)
+            if l.key == 'Cc':
+                c.cc.append(l.value)
+                rem.append(l)
+            if l.key == 'Status':
+                c.status = l.value
+                rem.append(l)
+        for l in rem:
+            c.active_labels.remove(l)
+        c.cc_list = c.cc
+        c.cc = ','.join(c.cc)
 
-		return render('issue/view.html')
-	
-	def comment(self, repo_name, issue_no):
-		e = request.environ
-		c.dbrepo = dbrepo = c.rhodecode_db_repo
+        return render('issue/view.html')
+    
+    def comment(self, repo_name, issue_no):
+        e = request.environ
+        c.dbrepo = dbrepo = c.rhodecode_db_repo
 
-		c.issue = self.sa.query(Issue).get((dbrepo.repo_id, issue_no))
-		c.issue.touch(self.sa)
+        c.issue = self.sa.query(Issue).get((dbrepo.repo_id, issue_no))
+        c.issue.touch(self.sa)
 
-		if not 'summary' in request.POST or len(request.POST['summary']) == 0:
-			h.flash('No issues without summaries!', category='error')
-			return redirect(url('issue_home', repo_name=repo_name, issue_no=issue_no))
-		
-		comment = IssueComment()
-		comment.repo_id = dbrepo.repo_id
-		comment.issue_no = c.issue.issue_no
-		comment.user_id = self.rhodecode_user.user_id
-		comment.text = request.POST['comment']
-		comment.insert_transacted(self.sa)
-		self.sa.commit()
+        if not 'summary' in request.POST or len(request.POST['summary']) == 0:
+            h.flash('No issues without summaries!', category='error')
+            return redirect(url('issue_home', repo_name=repo_name, issue_no=issue_no))
+        
+        comment = IssueComment()
+        comment.repo_id = dbrepo.repo_id
+        comment.issue_no = c.issue.issue_no
+        comment.user_id = self.rhodecode_user.user_id
+        comment.text = request.POST['comment']
+        comment.insert_transacted(self.sa)
+        self.sa.commit()
 
-		c.cursor = ''
-		c.page = ''
-		if 'cursor' in request.params:
-			c.cursor = request.params['cursor']
-		if 'page' in request.params:
-			c.page = request.params['page']
+        c.cursor = ''
+        c.page = ''
+        if 'cursor' in request.params:
+            c.cursor = request.params['cursor']
+        if 'page' in request.params:
+            c.page = request.params['page']
 
-		self.__update_labels(comment)		
-		
-		action_logger(c.rhodecode_user, 'issue_updated:' + str(comment.issue_no) + ',' + str(comment.comment_no), c.rhodecode_db_repo, sa=self.sa)
+        self.__update_labels(comment)       
+        
+        action_logger(c.rhodecode_user, 'issue_updated:' + str(comment.issue_no) + ',' + str(comment.comment_no), c.rhodecode_db_repo, sa=self.sa)
 
-		from rhodecode.lib.celerylib import tasks, run_task
-		run_task(tasks.send_issue_notifications, dbrepo.repo_id, issue_no, comment.comment_no)
+        from rhodecode.lib.celerylib import tasks, run_task
+        run_task(tasks.send_issue_notifications, dbrepo.repo_id, issue_no, comment.comment_no)
 
-		return redirect(url('issue_home', repo_name=repo_name, issue_no=issue_no, cursor=c.cursor, page=c.page))
-	
-	def new(self, repo_name):
-		e = request.environ
-		c.dbrepo = dbrepo = c.rhodecode_db_repo
+        return redirect(url('issue_home', repo_name=repo_name, issue_no=issue_no, cursor=c.cursor, page=c.page))
+    
+    def new(self, repo_name):
+        e = request.environ
+        c.dbrepo = dbrepo = c.rhodecode_db_repo
 
-		c.summary = ''
-		c.description = ''
-		c.status = ''
-		c.cc = ''
-		c.owner = dbrepo.user.username
-		c.stati = json_formatted_status_presets(self.sa, dbrepo.repo_id)
-		c.common_labels = json_formatted_common_labels(self.sa, dbrepo.repo_id)
+        c.summary = ''
+        c.description = ''
+        c.status = ''
+        c.cc = ''
+        c.owner = dbrepo.user.username
+        c.stati = json_formatted_status_presets(self.sa, dbrepo.repo_id)
+        c.common_labels = json_formatted_common_labels(self.sa, dbrepo.repo_id)
 
 
-		return render('issue/new.html')
-	
-	def __insert_label(self, repo_id, issue_no, key, value):
-		lbl = IssueLabel()
-		lbl.repo_id = repo_id
-		lbl.issue_no = issue_no
-		lbl.key = key
-		lbl.value = value
-		self.sa.add(lbl)
-	
-	def create(self, repo_name):
-		e = request.environ
-		c.dbrepo = dbrepo = c.rhodecode_db_repo
+        return render('issue/new.html')
+    
+    def __insert_label(self, repo_id, issue_no, key, value):
+        lbl = IssueLabel()
+        lbl.repo_id = repo_id
+        lbl.issue_no = issue_no
+        lbl.key = key
+        lbl.value = value
+        self.sa.add(lbl)
+    
+    def create(self, repo_name):
+        e = request.environ
+        c.dbrepo = dbrepo = c.rhodecode_db_repo
 
-		if not request.POST.has_key('summary') or len(request.POST['summary']) < 1:
-			h.flash('No issues without summaries!', category='error')
-			return redirect(url('issue_new', repo_name=repo_name))
+        if not request.POST.has_key('summary') or len(request.POST['summary']) < 1:
+            h.flash('No issues without summaries!', category='error')
+            return redirect(url('issue_new', repo_name=repo_name))
 
-		issue = Issue()
-		issue.repo_id = dbrepo.repo_id
-		issue.reporter_id = self.rhodecode_user.user_id
-		issue.description = request.POST['description']
-		issue.insert_transacted(self.sa)
-		self.sa.commit()
+        issue = Issue()
+        issue.repo_id = dbrepo.repo_id
+        issue.reporter_id = self.rhodecode_user.user_id
+        issue.description = request.POST['description']
+        issue.insert_transacted(self.sa)
+        self.sa.commit()
 
-		self.__insert_label(dbrepo.repo_id, issue.issue_no, 'Summary', request.POST['summary'])
-		if len(request.POST['owner']) > 0:
-			self.__insert_label(dbrepo.repo_id, issue.issue_no, 'Owner', request.POST['owner'])
-		if len(request.POST['status']) > 0:
-			self.__insert_label(dbrepo.repo_id, issue.issue_no, 'Status', request.POST['status'])
-		if len(request.POST['cc']) > 0:
-			addrs = list(Set([x.strip() for x in request.POST['cc'].split(',')]))
-			for a in addrs:
-				self.__insert_label(dbrepo.repo_id, issue.issue_no, 'Cc', a)
-		
-		i = 0
-		while ('label_%d' % i) in request.POST:
-			if len(request.POST['label_%d' % i]) == 0:
-				i += 1
-				continue
-			s = request.POST['label_%d' % i]
-			k, v = '', None
-			if '-' in s:
-				k, v = s.split('-', 1)
-			else:
-				k = s
-			self.__insert_label(dbrepo.repo_id, issue.issue_no, k, v)
-			i += 1
+        self.__insert_label(dbrepo.repo_id, issue.issue_no, 'Summary', request.POST['summary'])
+        if len(request.POST['owner']) > 0:
+            self.__insert_label(dbrepo.repo_id, issue.issue_no, 'Owner', request.POST['owner'])
+        if len(request.POST['status']) > 0:
+            self.__insert_label(dbrepo.repo_id, issue.issue_no, 'Status', request.POST['status'])
+        if len(request.POST['cc']) > 0:
+            addrs = list(Set([x.strip() for x in request.POST['cc'].split(',')]))
+            for a in addrs:
+                self.__insert_label(dbrepo.repo_id, issue.issue_no, 'Cc', a)
+        
+        i = 0
+        while ('label_%d' % i) in request.POST:
+            if len(request.POST['label_%d' % i]) == 0:
+                i += 1
+                continue
+            s = request.POST['label_%d' % i]
+            k, v = '', None
+            if '-' in s:
+                k, v = s.split('-', 1)
+            else:
+                k = s
+            self.__insert_label(dbrepo.repo_id, issue.issue_no, k, v)
+            i += 1
 
-		self.sa.commit()
-		action_logger(c.rhodecode_user, 'issue_created:' + str(issue.issue_no), c.rhodecode_db_repo, sa=self.sa)
-		self.sa.commit()
-		
-		return redirect(url('issue_home', repo_name=repo_name, issue_no=issue.issue_no))
+        self.sa.commit()
+        action_logger(c.rhodecode_user, 'issue_created:' + str(issue.issue_no), c.rhodecode_db_repo, sa=self.sa)
+        self.sa.commit()
+        
+        return redirect(url('issue_home', repo_name=repo_name, issue_no=issue.issue_no))
 
-	def list(self, repo_name):
-		e = request.environ
-		c.dbrepo = dbrepo = c.rhodecode_db_repo
+    def list(self, repo_name):
+        e = request.environ
+        c.dbrepo = dbrepo = c.rhodecode_db_repo
 
-		pg = 1
-		if 'page' in request.params and request.params['page'].isdigit():
-			pg = int(request.params['page'])
-		
-		sort = 'Modified'
-		sort_dir = 'desc'
-		if 'sort' in request.params:
-			sort = request.params['sort']
-		if 'sort-dir' in request.params:
-			sort_dir = request.params['sort-dir']
-		c.sort = sort
-		c.sort_dir = sort_dir
+        pg = 1
+        if 'page' in request.params and request.params['page'].isdigit():
+            pg = int(request.params['page'])
+        
+        sort = 'Modified'
+        sort_dir = 'desc'
+        if 'sort' in request.params:
+            sort = request.params['sort']
+        if 'sort-dir' in request.params:
+            sort_dir = request.params['sort-dir']
+        c.sort = sort
+        c.sort_dir = sort_dir
 
-		c.cursor = 0
-		if 'cursor' in request.params:
-			c.cursor = request.params['cursor']
-		
-		c.cursor_idx = None
-		if 'cursorIdx' in request.params:
-			c.cursor_idx = request.params['cursorIdx']
+        c.cursor = 0
+        if 'cursor' in request.params:
+            c.cursor = request.params['cursor']
+        
+        c.cursor_idx = None
+        if 'cursorIdx' in request.params:
+            c.cursor_idx = request.params['cursorIdx']
 
-		q = None
-		if 'q' in request.params:
-			q = request.params['q']
-			if q.isdigit():
-				return redirect(url('issue_home', repo_name=repo_name, issue_no=int(q)))
-		c.q = q or ''
-		all_issues = query_issues(self.sa, dbrepo.repo_id, order_by=sort, order_dir=sort_dir, q=q)
-		c.issues = Page(all_issues, page=pg, items_per_page=10)
+        q = None
+        if 'q' in request.params:
+            q = request.params['q']
+            if q.isdigit():
+                return redirect(url('issue_home', repo_name=repo_name, issue_no=int(q)))
+        c.q = q or ''
+        all_issues = query_issues(self.sa, dbrepo.repo_id, order_by=sort, order_dir=sort_dir, q=q)
+        c.issues = Page(all_issues, page=pg, items_per_page=10)
 
-		return render('issue/list.html')
-	
-	@jsonify
-	def toggle_star(self, repo_name, issue_no):
-		e = request.environ
-		c.dbrepo = dbrepo = c.rhodecode_db_repo
+        return render('issue/list.html')
+    
+    @jsonify
+    def toggle_star(self, repo_name, issue_no):
+        e = request.environ
+        c.dbrepo = dbrepo = c.rhodecode_db_repo
 
-		issue = self.sa.query(Issue).get((dbrepo.repo_id, issue_no))
-		current_user = self.sa.query(User).get((self.rhodecode_user.user_id,))
-		exists = current_user in issue.starring_users
-		if not exists:
-			issue.starring_users.append(current_user)
-		else:
-			issue.starring_users.remove(current_user)
-		self.sa.add(issue)
-		self.sa.commit()
-		return not exists
+        issue = self.sa.query(Issue).get((dbrepo.repo_id, issue_no))
+        current_user = self.sa.query(User).get((self.rhodecode_user.user_id,))
+        exists = current_user in issue.starring_users
+        if not exists:
+            issue.starring_users.append(current_user)
+        else:
+            issue.starring_users.remove(current_user)
+        self.sa.add(issue)
+        self.sa.commit()
+        return not exists

File rhodecode/model/db.py

 
     @property
     def status(self):
-        return self.status_label[0].value
+        if len(self.status_label) > 0:
+            return self.status_label[0].value
+        else:
+            return '----'
 
     @property
     def summary(self):
 
     @property
     def owner(self):
-        return self.owner_label[0].value
+        if len(self.owner_label) > 0:
+            return self.owner_label[0].value
+        else:
+            return '----'
 
     @property
     def last_change(self):