A lot of new features and improvements

This commit is contained in:
Élie Bouttier 2014-08-02 19:17:18 -07:00
parent 8aa77915ad
commit 7f91c790ec
15 changed files with 587 additions and 229 deletions

View file

@ -2,10 +2,9 @@
from __future__ import unicode_literals
from django.db import models, migrations
from django.conf import settings
import re
import colorful.fields
import django.core.validators
from django.conf import settings
class Migration(migrations.Migration):
@ -18,11 +17,11 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Event',
fields=[
('id', models.AutoField(serialize=False, auto_created=True, verbose_name='ID', primary_key=True)),
('date', models.DateTimeField(auto_now=True)),
('id', models.AutoField(primary_key=True, serialize=False, auto_created=True, verbose_name='ID')),
('date', models.DateTimeField(auto_now_add=True)),
('code', models.IntegerField(default=0)),
('_args', models.CharField(default='{}', blank=True, max_length=1024)),
('additionnal_section', models.TextField(default='', blank=True)),
('_args', models.CharField(blank=True, default='{}', max_length=1024)),
('additionnal_section', models.TextField(blank=True, default='')),
('author', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
],
options={
@ -32,12 +31,12 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Issue',
fields=[
('global_id', models.AutoField(serialize=False, primary_key=True)),
('global_id', models.AutoField(primary_key=True, serialize=False)),
('id', models.IntegerField(editable=False)),
('title', models.CharField(max_length=128)),
('opened_at', models.DateTimeField(auto_now=True)),
('opened_at', models.DateTimeField(auto_now_add=True)),
('closed', models.BooleanField(default=False)),
('assignee', models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, null=True)),
('assignee', models.ForeignKey(blank=True, null=True, to=settings.AUTH_USER_MODEL)),
('author', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
],
options={
@ -53,10 +52,11 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Label',
fields=[
('id', models.AutoField(serialize=False, auto_created=True, verbose_name='ID', primary_key=True)),
('id', models.AutoField(primary_key=True, serialize=False, auto_created=True, verbose_name='ID')),
('name', models.CharField(max_length=32)),
('color', colorful.fields.RGBColorField(default='#FFFFFF')),
('inverted', models.BooleanField(default=True)),
('deleted', models.BooleanField(default=False)),
('color', colorful.fields.RGBColorField(verbose_name='Background color', default='#000000')),
('inverted', models.BooleanField(default=True, verbose_name='Inverse text color')),
],
options={
},
@ -65,13 +65,13 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='issue',
name='labels',
field=models.ManyToManyField(blank=True, null=True, to='issue.Label'),
field=models.ManyToManyField(blank=True, to='issue.Label', null=True),
preserve_default=True,
),
migrations.CreateModel(
name='Milestone',
fields=[
('id', models.AutoField(serialize=False, auto_created=True, verbose_name='ID', primary_key=True)),
('id', models.AutoField(primary_key=True, serialize=False, auto_created=True, verbose_name='ID')),
('name', models.CharField(max_length=32)),
('progression', models.SmallIntegerField(default=0)),
('due_date', models.DateTimeField(null=True)),
@ -83,9 +83,9 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Project',
fields=[
('name', models.CharField(serialize=False, validators=[django.core.validators.RegexValidator(re.compile('^[-a-zA-Z0-9_]+$', 32), "Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens.", 'invalid')], primary_key=True, max_length=32, verbose_name='Short name (used in URL)')),
('display_name', models.CharField(max_length=32, verbose_name='Project name')),
('description', models.TextField(default='', blank=True, verbose_name='Description')),
('name', models.CharField(primary_key=True, verbose_name='Short name (used in URL, definitive)', validators=[django.core.validators.RegexValidator(message='Please enter only lowercase characters, number, underscores or hyphens.', regex='^[a-z0-9_-]+$')], serialize=False, max_length=32)),
('display_name', models.CharField(verbose_name='Project name', unique=True, max_length=32)),
('description', models.TextField(blank=True, default='', verbose_name='Description')),
],
options={
},
@ -107,10 +107,6 @@ class Migration(migrations.Migration):
field=models.ForeignKey(to='issue.Project'),
preserve_default=True,
),
migrations.AlterUniqueTogether(
name='label',
unique_together=set([('project', 'name')]),
),
migrations.AddField(
model_name='issue',
name='project',

View file

@ -1,6 +1,10 @@
from django.db import models
from django.contrib.auth.models import User
from django.core.validators import validate_slug
from django.core.validators import RegexValidator
from django.core.exceptions import ValidationError
from django.utils.safestring import mark_safe
from django.utils.html import escape
from django.core.urlresolvers import reverse
import json
@ -9,17 +13,28 @@ from colorful.fields import RGBColorField
class Project(models.Model):
name = models.CharField(primary_key=True, blank=False, max_length=32,
verbose_name="Short name (used in URL)",
validators=[validate_slug])
url_name_validator = RegexValidator(regex='^[a-z0-9_-]+$',
message="Please enter only lowercase characters, number, "
"underscores or hyphens.")
display_name = models.CharField(max_length=32,
name = models.CharField(primary_key=True, blank=False, max_length=32,
verbose_name="Short name (used in URL, definitive)",
validators=[url_name_validator])
display_name = models.CharField(max_length=32, unique=True,
verbose_name="Project name")
description = models.TextField(blank=True, default="",
verbose_name="Description")
def create_default_labels(self):
Label(project=self, name='bug', color='#FF0000').save()
Label(project=self, name='feature', color='#00A000').save()
Label(project=self, name='documentation', color='#1D3DBE').save()
def __str__(self):
return self.display_name
class Label(models.Model):
@ -28,12 +43,11 @@ class Label(models.Model):
name = models.CharField(max_length=32)
class Meta:
unique_together = [ 'project', 'name' ]
deleted = models.BooleanField(default=False)
color = RGBColorField(default='#FFFFFF')
color = RGBColorField(default='#000000', verbose_name="Background color")
inverted = models.BooleanField(default=True)
inverted = models.BooleanField(default=True, verbose_name="Inverse text color")
def style(self):
@ -79,11 +93,11 @@ class Issue(models.Model):
author = models.ForeignKey(User, related_name='+')
opened_at = models.DateTimeField(auto_now=True)
opened_at = models.DateTimeField(auto_now_add=True)
closed = models.BooleanField(default=False)
labels = models.ManyToManyField(Label, blank=True, null=True)
labels = models.ManyToManyField(Label, blank=True, null=True, related_name='issues')
assignee = models.ForeignKey(User, blank=True, null=True, related_name='+')
@ -98,9 +112,47 @@ class Issue(models.Model):
def comments(self):
comments = self.events.filter(code=Event.COMMENT)
comments = self.events.filter(issue=self,code=Event.COMMENT)
return comments[1:]
return comments
def getdesc(self):
desc = self.events.filter(issue=self,code=Event.DESCRIBE)
if desc.count():
return desc.first().additionnal_section
else:
return None
def setdesc(self, value):
desc = self.events.filter(issue=self,code=Event.DESCRIBE)
if desc.count():
desc = desc.first()
desc.additionnal_section = value
desc.save()
else:
desc = Event(issue=self, author=self.author, code=Event.DESCRIBE,
additionnal_section=value)
desc.save()
def deldesc(self):
desc = self.events.filter(issue=self,code=Event.DESCRIBE)
if desc.count():
desc.first().delete()
description = property(getdesc, setdesc, deldesc)
def add_label(self, author, label, commit=True):
self.labels.add(label)
if commit:
self.save()
event = Event(issue=self, author=author,
code=Event.ADD_LABEL, args={'label': label.id})
event.save()
def remove_label(self, author, label, commit=True):
self.labels.remove(label)
if commit:
self.save()
event = Event(issue=self, author=author,
code=Event.DEL_LABEL, args={'label': label.id})
event.save()
def __str__(self):
return self.title
@ -118,10 +170,11 @@ class Event(models.Model):
DEL_MILESTONE = 8
REFERENCE = 9
COMMENT = 10
DESCRIBE = 11
issue = models.ForeignKey(Issue, related_name="%(class)ss")
date = models.DateTimeField(auto_now=True)
date = models.DateTimeField(auto_now_add=True)
author = models.ForeignKey(User)
@ -139,34 +192,73 @@ class Event(models.Model):
additionnal_section = models.TextField(blank=True, default="")
def editable(self):
return self.code == Event.COMMENT or self.code == Event.DESCRIBE
def boxed(self):
return self.code == Event.COMMENT
return self.code == Event.COMMENT or self.code == Event.DESCRIBE
def glyphicon(self):
if self.code == Event.COMMENT or self.code == Event.DESCRIBE:
return "pencil"
elif self.code == Event.CLOSE:
return "ban-circle"
elif self.code == Event.REOPEN:
return "refresh"
elif self.code == Event.RENAME:
return "transfer"
elif self.code == Event.ADD_LABEL:
return "tag"
elif self.code == Event.DEL_LABEL:
return "tag"
elif self.code == Event.SET_MILESTONE:
return "road"
elif self.code == Event.CHANGE_MILESTONE:
return "road"
elif self.code == Event.DEL_MILESTONE:
return "road"
elif self.code == Event.REFERENCE:
return "transfer"
else:
return "cog"
def __str__(self):
args = self.args
if self.code == Event.COMMENT:
description = "{author} commented"
if self.code == Event.COMMENT or self.code == Event.DESCRIBE:
description = "commented"
elif self.code == Event.CLOSE:
description = "{author} closed this issue"
description = "closed this issue"
elif self.code == Event.REOPEN:
description = "{author} reopened this issue"
description = "reopened this issue"
elif self.code == Event.RENAME:
description = "{author} changed the title from {old_title} to {new_title}"
elif self.code == Event.ADD_LABEL:
description = "{author} added the {label} label"
elif self.code == Event.DEL_LABEL:
description = "{author} deleted the {label} label"
description = "changed the title from <mark>{old_title}</mark> to <mark>{new_title}</mark>"
elif self.code == Event.ADD_LABEL or self.code == Event.DEL_LABEL:
label = Label.objects.get(id=args['label'])
description = '{action} the <a href="{url}?q=is:open%20label:{label}"><span class="label" style="{style}">{label}</span></a> label'
args['label'] = label.name
args['url'] = reverse('list-issue', kwargs={'project': self.issue.project.name})
args['style'] = label.style()
if self.code == Event.ADD_LABEL:
args['action'] = 'added'
else:
args['action'] = 'removed'
elif self.code == Event.SET_MILESTONE:
description = "{author} added this to the {milestone} milestone"
description = "added this to the {milestone} milestone"
elif self.code == Event.CHANGE_MILESTONE:
description = "{author} moved this from the {old_milestone} milestone to the {new_mileston} milestone"
description = "moved this from the {old_milestone} milestone to the {new_mileston} milestone"
elif self.code == Event.DEL_MILESTONE:
description = "{author} deleted this from the {milestone} milestone"
description = "deleted this from the {milestone} milestone"
elif self.code == Event.REFERENCE:
description = "{author} referenced this issue"
description = "referenced this issue"
else:
return None
return description.format(author=self.author, **args)
# Escape args
safe_args = {k: escape(v) for k, v in args.items()}
return mark_safe(description.format(**safe_args))

View file

@ -6,3 +6,7 @@ body {
.navbar {
margin-bottom: 20px;
}
a .remove-label {
color: #CCC;
}

View file

@ -15,12 +15,16 @@
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<title>Issue Tracker</title>
<title>{% block title %}PonyTracker{% endblock %}</title>
<link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet">
<link href="{% static 'css/issue.css' %}" rel="stylesheet">
{% block css %}{% endblock %}
<script src="{% static 'js/jquery.min.js' %}"></script>
{% block js %}{% endblock %}
{% block media %}{% endblock %}
</head>
<body>
@ -37,7 +41,7 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{% url 'list-project' %}">{% block title %}Issue Tracker{% endblock %}</a>
<a class="navbar-brand" href="{% url 'list-project' %}">{% block page_title %}PonyTracker{% endblock %}</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
@ -74,7 +78,7 @@
<div class="row">
<div class="col-md-offset-2 col-md-8">
<div class="col-md-offset-1 col-md-10">
{% if messages %}
{% for message in messages %}
@ -93,7 +97,6 @@
</div> <!-- /container -->
<script src="{% static 'js/jquery.min.js' %}"></script>
<script src="{% static 'js/bootstrap.min.js' %}"></script>
{% block js_end %}{% endblock %}
</body>

View file

@ -1,60 +1,149 @@
{% extends 'issue/project.html' %}
{% load humanize %}
{% load django_markdown %}
{% block issuetab %} class="active"{% endblock %}
{% block content %}
<div class="panel panel-default">
<div class="panel-heading">
<div class="well">
<h1>{{ issue }} <small>#{{ issue.id }}</small></h1>
{% if issue.closed %}
<span class="label label-danger">Closed</span>
<span class="label label-danger" style="font-size: 120%;">Closed</span>
{% else %}
<span class="label label-success">Open</span>
<span class="label label-success" style="font-size: 120%;">Open</span>
{% endif %}
{{ issue.author.username }} opened this issue on {{ issue.opened_at }}
&#160;
<a href="{% url 'list-issue' project.name %}?q=is:open%20author:{{ issue.author.username }}"><strong>{{ issue.author.username }}</strong></a> opened this issue {{ issue.opened_at|naturaltime }}
- {{ issue.comments.count }} comments
</div>
<div class="row">
<div class="col-md-10">
{% for event in events %}
<div class="panel panel-default">
<div class="panel-heading">
<span class="badge"><span class="glyphicon glyphicon-{{ event.glyphicon }}"></span></span>
&#160;
<a href="{% url 'list-issue' project.name %}?q=is:open%20author:{{ event.author.username }}"><strong>{{ event.author}}</strong></a> {{ event }} {{ event.date|naturaltime }}
{% if event.code == event.DESCRIBE %}
<div class="pull-right">
<a href="{% url 'edit-issue' project.name issue.id %}">
<button class="btn btn-primary btn-xs">Edit</button>
</a>
</div>
{% elif event.code == event.COMMENT %}
<div class="pull-right">
<a href="{% url 'edit-comment' project.name issue.id event.id %}">
<button class="btn btn-primary btn-xs">Edit</button>
</a>
</div>
{% endif %}
</div>
<table class="table">
{% for event in events %}
<tr>
<td>
{{ event }} on {{ event.date }}
{% if event.additionnal_section %}
{% if event.boxed %}
<br />
<br />
<div class="well">
<div class="panel-body">
{{ event.additionnal_section|markdown }}
</div>
{% else %}
<hr>
{{ event.additionnal_section|markdown }}
{% elif event.code == event.DESCRIBE %}
<div class="panel-body">
<em>No description provided.</em>
</div>
{% endif %}
{% endif %}
</td>
</tr>
</div>
{% endfor %}
</table>
<div class="row">
<div class="col-md-3">
<a href="{% url 'comment-issue' project.name issue.id %}"><button class="btn btn-default btn-block">Add a comment</button></a>
</div>
<div class="col-md-3">
<a href="{% url 'edit-issue' project.name issue.id %}"><button class="btn btn-default btn-block">Edit this issue</button></a>
</div>
<div class="col-md-3">
{% if issue.closed %}
<a href="{% url 'reopen-issue' project.name issue.id %}"><button class="btn btn-default btn-block">Reopen this issue</button></a>
{% else %}
<a href="{% url 'close-issue' project.name issue.id %}"><button class="btn btn-default btn-block">Close this issue</button></a>
{% endif %}
</div>
<div class="col-md-3">
<a href="{% url 'delete-issue' project.name issue.id %}"><button class="btn btn-default btn-block">Delete this issue</button></a>
</div>
</div>
</div>
<div class="col-md-2">
<b>Labels</b>
<div class="pull-right">
<div class="dropdown">
<button class="btn btn-default btn-xs" type="button" id="labels-menu" data-toggle="dropdown"><span class="glyphicon glyphicon-plus"></span></button>
<ul class="dropdown-menu dropdown-menu-right" role="menu" aria-labelledby="labels-menu">
{% if labels.count %}
{% for label in labels %}
<li role="presentation">
<a href="{% url 'add-label-to-issue' project.name issue.id label.id %}">
<span class="label" style="{{ label.style }}">{{ label }}</span>
</a>
</li>
{% endfor %}
<li role="presentation" class="divider"></li>
{% endif %}
<li role="presentation">
<a href="{% url 'add-label' project.name %}?issue={{ issue.id }}">
<button class="btn btn-success btn-xs btn-block">New label...</button>
</a>
</li>
</ul>
</div>
</div>
<br /><br />
{% if issue.labels.count %}
{% for label in issue.labels.all %}
<div class="row">
<a href="{% url 'remove-label-from-issue' project.name issue.id label.id %}">
<span class="glyphicon glyphicon-remove remove-label"></span>
</a>
<a href="{% url 'list-issue' project.name %}?q=is:open%20label:{{ label.name }}">
<span class="label" style="{{ label.style }}">{{ label }}</span>
</a>
</div>
{% endfor %}
{% else %}
None yet
{% endif %}
<hr>
<h5>
<b>Milestons</b>
<div class="pull-right">
<a href="#">
<button class="btn btn-default btn-xs"><span class="glyphicon glyphicon-plus"></span></button>
</a>
</div>
</h5>
{% if issue.milestones.count %}
{% for milestone in issue.milestones.all %}
{{ milestone }}
{% endfor %}
{% else %}
No milestone
{% endif %}
</div>
</div>
<a href="{% url 'comment-issue' project.name issue.id %}"><button class="btn btn-default">Comment this issue</button></a>
<a href="{% url 'edit-issue' project.name issue.id %}"><button class="btn btn-default">Edit this issue</button></a>
{% if issue.closed %}
<a href="{% url 'reopen-issue' project.name issue.id %}"><button class="btn btn-default">Reopen this issue</button></a>
{% else %}
<a href="{% url 'close-issue' project.name issue.id %}"><button class="btn btn-default">Close this issue</button></a>
{% endif %}
<a href="{% url 'delete-issue' project.name issue.id %}"><button class="btn btn-default">Delete this issue</button></a>
{% endblock %}

View file

@ -2,6 +2,8 @@
{% load crispy_forms_tags %}
{% block media %}{{ form.media }}{% endblock %}
{% block issuetab %} class="active"{% endblock %}
{% block content %}

View file

@ -4,6 +4,10 @@
{% block issuetab %} class="active"{% endblock %}
{% block media %}
{{ form.media }}
{% endblock media %}
{% block content %}
<form action="" method="post" role="form">

View file

@ -1,5 +1,7 @@
{% extends 'issue/project.html' %}
{% load humanize %}
{% block issuetab %} class="active"{% endblock %}
{% block content %}
@ -14,14 +16,12 @@
<div class="form-group">
<div class="input-group">
<div class="dropdown">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" id="filters-menu">
Filters <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="filters-menu">
<li role="presentation"><a role="menu-item" href="{% url 'list-issue' project.name %}?q=open">Open</a></li>
<li role="presentation"><a role="menu-item" href="{% url 'list-issue' project.name %}?q=close">Close</a></li>
<li role="presentation"><a role="menu-item" href="{% url 'list-issue' project.name %}?q=all">All</a></li>
</ul>
{% if is_all_query %}
<a href="{% url 'list-issue' project.name %}"><button type="button" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-remove"> Reset filter</span></button></a>
{% endif %}
<a href="{% url 'list-issue' project.name %}?q=is:open{% if is_all_query %} {{ is_all_query }}{% endif %}"><button type="button" class="btn btn-default btn-sm{{ is_open }}">Open</button></a>
<a href="{% url 'list-issue' project.name %}?q=is:close{% if is_all_query %} {{ is_all_query }}{% endif %}"><button type="button" class="btn btn-default btn-sm{{ is_close }}">Close</button></a>
<a href="{% url 'list-issue' project.name %}?q={% if is_all_query %}{{ is_all_query }}{% else %}*{% endif %}"><button type="button" class="btn btn-default btn-sm{{ is_all }}">Both</button></a>
</div>
</div>
</div>
@ -29,17 +29,13 @@
<div class="input-group">
<input class="form-control" name="q" type="text" placeholder="filter" value="{{ query }}"/>
<div class="input-group-addon">
<a href="#" onclick="$('#filter-form').submit();">
<span class="glyphicon glyphicon-search"></span>
</a>
<a href="#" onclick="$('#filter-form').submit();"><span class="glyphicon glyphicon-search"></span></a>
</div>
</div>
</div>
<div class="form-group">
<div class="input-group">
<a href="{% url 'add-issue' project.name %}">
<button class="btn btn-success" type="button">New issue</button>
</a>
<a href="{% url 'add-issue' project.name %}"><button class="btn btn-success" type="button">New issue</button></a>
</div>
</div>
</form>
@ -52,16 +48,17 @@
{% for issue in issues %}
<tr>
<td>
<span class="text-headline">
<a href="{% url 'show-issue' project.name issue.id %}">{{ issue }}</a>
</span>
{% if issue.closed %}
<span class="text-danger"><span class="glyphicon glyphicon-ok-circle"></span></span>
{% else %}
<span class="text-success"><span class="glyphicon glyphicon-hand-right"></span></span>
{% endif %}
<b><a href="{% url 'show-issue' project.name issue.id %}">{{ issue }}</a></b>
{% for label in issue.labels.all %}
<a href="{% url 'list-issue' project.name %}?q=open%20label:{{ label.name }}">
<span class="label" style="{{ label.style }}">{{ label }}</span>
</a>
<a href="{% url 'list-issue' project.name %}?q=is:open%20label:{{ label.name }}"><span class="label" style="{{ label.style }}">{{ label }}</span></a>
{% endfor %}
<br />
<small>#{{ issue.id }} opened by {{ issue.author.username }} on {{ issue.opened_at }}</small>
<small>#{{ issue.id }} opened by <a href="{% url 'list-issue' project.name %}?q=is:open%20author:{{ issue.author.username }}"><strong>{{ issue.author.username }}</strong></a> {{ issue.opened_at|naturaltime }}</small>
<span class="badge">{{ issue.comments.count }}</span>
</td>
</tr>

View file

@ -6,10 +6,16 @@
{% block content %}
<form action="" method="post" role="form">
<div class="row">
<div class="col-md-offset-3 col-md-6">
<form action="" method="post" role="form">
{{ form|crispy }}
{% csrf_token %}
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</form>
</div>
</div>
{% endblock %}

View file

@ -20,16 +20,16 @@
{% for label in labels %}
<tr>
<td>
<a href="{% url 'list-issue' project.name %}?q=open%20label:{{ label.name }}">
<a href="{% url 'list-issue' project.name %}?q=is:open%20label:{{ label.name }}">
<button class="btn" style="{{ label.style }}">
<span class="glyphicon glyphicon-tag" style="font-size: 100%;"></span> {{ label }}
</button>
</a>
<div class="pull-right">
<a href="">
<a href="{% url 'edit-label' project.name label.id %}">
<button class="btn btn-primary"><span class="glyphicon glyphicon-edit"></span> Edit</button>
</a>
<a href="">
<a href="{% url 'delete-label' project.name label.id %}">
<button class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Delete</button>
</a>
</div>

View file

@ -1,11 +1,11 @@
{% extends 'base.html' %}
{% block title %}{{ project }}{% endblock %}
{% block title %}{{ project }} - PonyTracker{% endblock %}
{% block page_title %}{{ project }}{% endblock %}
{% block projectmenu %}
{% if request.user.is_authenticated and request.user.is_admin %}
<li role="presentation"><a role="menuitem" tabindex="-1" href="{% url 'edit-project' project.name %}">Modify this project</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="{% url 'delete-project' project.name %}">Delete this project</a></li>
{% endif %}
{% endblock %}
{% block navbar %}

View file

@ -1,22 +1,45 @@
{% extends 'base.html' %}
{% load django_markdown %}
{% block content %}
<h1>Projects</h1>
<table class="table table-hover">
<tr>
<th>Name</th>
<th>Description</th>
</tr>
<div class="panel panel-default">
<div class="panel-heading">
<h1>
Projects
<div class="pull-right">
<a href="{% url 'add-project' %}"><button class="btn btn-success">Add project</button></a>
</div>
</h1>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-3">
<strong>Name</strong>
</div>
<div class="col-md-8">
<strong>Description</strong>
</div>
</div>
{% for project in projects %}
<tr>
<td><a href="{% url 'list-issue' project.name %}">{{ project }}</a></td>
<td>{{ project.description }}</td>
</tr>
<hr>
<div class="row">
<div class="col-md-3">
<a href="{% url 'list-issue' project.name %}">{{ project }}</a>
</div>
<div class="col-md-9">
{% if project.description %}
{{ project.description|linebreaksbr }}
{% else %}
<em>No description provided.</em>
{% endif %}
</div>
</div>
{% endfor %}
</table>
<a href="{% url 'add-project' %}"><button class="btn btn-success">Add project</button></a>
</div>
{% endblock %}

View file

@ -2,23 +2,27 @@ from django.conf.urls import url
urlpatterns = [
url(r'^$', 'issue.views.project_list', name='list-project'),
url(r'^add$', 'issue.views.project_edit', name='add-project'),
url(r'^(?P<project>[a-z0-9]+)/edit$', 'issue.views.project_edit', name='edit-project'),
url(r'^(?P<project>[a-z0-9]+)/delete$', 'issue.views.project_delete', name='delete-project'),
url(r'^(?P<project>[a-z0-9]+)/issues$', 'issue.views.issue_list', name='list-issue'),
url(r'^(?P<project>[a-z0-9]+)/issues/add$', 'issue.views.issue_edit', name='add-issue'),
url(r'^(?P<project>[a-z0-9]+)/issues/(?P<id>[0-9]+)$', 'issue.views.issue', name='show-issue'),
url(r'^(?P<project>[a-z0-9]+)/issues/(?P<id>[0-9]+)/edit$', 'issue.views.issue_edit', name='edit-issue'),
url(r'^(?P<project>[a-z0-9]+)/issues/(?P<id>[0-9]+)/close$', 'issue.views.issue_close', name='close-issue'),
url(r'^(?P<project>[a-z0-9]+)/issues/(?P<id>[0-9]+)/reopen$', 'issue.views.issue_reopen', name='reopen-issue'),
url(r'^(?P<project>[a-z0-9]+)/issues/(?P<id>[0-9]+)/comment$', 'issue.views.issue_comment', name='comment-issue'),
url(r'^(?P<project>[a-z0-9]+)/issues/(?P<id>[0-9]+)/delete$', 'issue.views.issue_delete', name='delete-issue'),
url(r'^(?P<project>[a-z0-9]+)/labels$', 'issue.views.label_list', name='list-label'),
url(r'^(?P<project>[a-z0-9]+)/labels/add$', 'issue.views.label_edit', name='add-label'),
url(r'^(?P<project>[a-z0-9]+)/labels/edit/(?P<id>[0-9]+)$', 'issue.views.label_edit', name='edit-label'),
url(r'^(?P<project>[a-z0-9]+)/milestones$', 'issue.views.milestone_list', name='list-milestone'),
url(r'^(?P<project>[a-z0-9]+)/milestones/add$', 'issue.views.milestone_edit', name='add-milestone'),
url(r'^(?P<project>[a-z0-9]+)/milestones/edit/(?P<id>[0-9]+)$', 'issue.views.milestone_edit', name='edit-milestone'),
url(r'^add$', 'issue.views.project_add', name='add-project'),
url(r'^(?P<project>[a-z0-9_-]+)/edit$', 'issue.views.project_edit', name='edit-project'),
url(r'^(?P<project>[a-z0-9_-]+)/delete$', 'issue.views.project_delete', name='delete-project'),
url(r'^(?P<project>[a-z0-9_-]+)/issues$', 'issue.views.issue_list', name='list-issue'),
url(r'^(?P<project>[a-z0-9_-]+)/issues/add$', 'issue.views.issue_edit', name='add-issue'),
url(r'^(?P<project>[a-z0-9_-]+)/issues/(?P<id>[0-9]+)$', 'issue.views.issue', name='show-issue'),
url(r'^(?P<project>[a-z0-9_-]+)/issues/(?P<id>[0-9]+)/edit$', 'issue.views.issue_edit', name='edit-issue'),
url(r'^(?P<project>[a-z0-9_-]+)/issues/(?P<id>[0-9]+)/close$', 'issue.views.issue_close', name='close-issue'),
url(r'^(?P<project>[a-z0-9_-]+)/issues/(?P<id>[0-9]+)/reopen$', 'issue.views.issue_reopen', name='reopen-issue'),
url(r'^(?P<project>[a-z0-9_-]+)/issues/(?P<id>[0-9]+)/comment$', 'issue.views.issue_comment', name='comment-issue'),
url(r'^(?P<project>[a-z0-9_-]+)/issues/(?P<id>[0-9]+)/comments/(?P<comment>[0-9]+)/edit$', 'issue.views.issue_comment', name='edit-comment'),
url(r'^(?P<project>[a-z0-9_-]+)/issues/(?P<id>[0-9]+)/delete$', 'issue.views.issue_delete', name='delete-issue'),
url(r'^(?P<project>[a-z0-9_-]+)/issues/(?P<issue>[0-9]+)/add-label/(?P<label>[0-9]+)$', 'issue.views.issue_add_label', name='add-label-to-issue'),
url(r'^(?P<project>[a-z0-9_-]+)/issues/(?P<issue>[0-9]+)/remove-label/(?P<label>[0-9]+)$', 'issue.views.issue_remove_label', name='remove-label-from-issue'),
url(r'^(?P<project>[a-z0-9_-]+)/labels$', 'issue.views.label_list', name='list-label'),
url(r'^(?P<project>[a-z0-9_-]+)/labels/add$', 'issue.views.label_edit', name='add-label'),
url(r'^(?P<project>[a-z0-9_-]+)/labels/(?P<id>[0-9]+)/edit$', 'issue.views.label_edit', name='edit-label'),
url(r'^(?P<project>[a-z0-9_-]+)/labels/(?P<id>[0-9]+)/delete$', 'issue.views.label_delete', name='delete-label'),
url(r'^(?P<project>[a-z0-9_-]+)/milestones$', 'issue.views.milestone_list', name='list-milestone'),
url(r'^(?P<project>[a-z0-9_-]+)/milestones/add$', 'issue.views.milestone_edit', name='add-milestone'),
url(r'^(?P<project>[a-z0-9_-]+)/milestones/edit/(?P<id>[0-9]+)$', 'issue.views.milestone_edit', name='edit-milestone'),
url(r'^login$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}, name='login'),
url(r'^logout$', 'django.contrib.auth.views.logout', {'next_page': '/'}, name='logout'),
]

View file

@ -7,8 +7,10 @@ from django.core.exceptions import ObjectDoesNotExist
from issue.models import *
from django_markdown.widgets import MarkdownWidget
from stronghold.decorators import public
@public
def project_list(request):
projects = Project.objects.all()
@ -26,22 +28,25 @@ def project_list(request):
return render(request, 'issue/project_list.html', c)
def project_edit(request, project=None):
def project_add(request):
if project:
project = get_object_or_404(Project, name=project)
class ProjectForm(forms.ModelForm):
class Meta:
model=Project
fields=['display_name', 'name', 'description']
form = ProjectForm(request.POST or None, instance=project)
ProjectForm = modelform_factory(Project, fields=['display_name', 'name', 'description'])
form = ProjectForm(request.POST or None)
if request.method == 'POST' and form.is_valid():
if Project.objects \
.filter(display_name__iexact=form.cleaned_data['display_name']) \
.count():
form._errors['display_name'] = ['There is already a project with a similar name.']
else:
project = form.save()
project.create_default_labels()
messages.success(request, 'Project added successfully.')
return redirect('list-issue', project.name)
@ -51,7 +56,39 @@ def project_edit(request, project=None):
c = {
'request': request,
'projects': projects,
'project': project,
'form': form,
}
return render(request, 'issue/project_edit.html', c)
def project_edit(request, project):
project = get_object_or_404(Project, name=project)
ProjectForm = modelform_factory(Project, fields=['display_name', 'description'])
form = ProjectForm(request.POST or None, instance=project)
if request.method == 'POST' and form.is_valid():
if Project.objects \
.filter(display_name__iexact=form.cleaned_data['display_name']) \
.exclude(pk=project.pk).count():
form._errors['display_name'] = ['There is already a project with a similar name.']
else:
project = form.save()
messages.success(request, 'Project modified successfully.')
return redirect('list-issue', project.name)
projects = Project.objects.all()
c = {
'request': request,
'projects': projects,
'form': form,
}
@ -75,48 +112,92 @@ def issue_list(request, project):
issues = project.issues
query = request.GET.get('q', 'open')
is_open = ''
is_close = ''
is_all = ''
is_all_query = ""
constraints = query.split(' ')
query = request.GET.get('q', '')
error = False
for constraint in constraints:
if query == '':
query = 'is:open'
syntaxe_error = False
for constraint in query.split(' '):
if constraint == '':
continue
if constraint == '*':
continue
if constraint == 'open':
issues = issues.filter(closed=False)
elif constraint == 'close':
issues = issues.filter(closed=True)
elif constraint == 'all':
pass
else:
args = constraint.split(':')
if len(args) != 2:
error = True
messages.error(request, 'There is a syntaxe error in your filter.')
issues = None
break
if len(args) == 2 and args[0] == 'label':
key = args[0]
value = args[1]
if key == '':
continue
elif key == 'is':
if value == 'open':
issues = issues.filter(closed=False)
is_open = ' active'
elif value =='close':
issues = issues.filter(closed=True)
is_close = ' active'
else:
messages.error(request, "The keyword 'is' must be followed by 'open' or 'close'.")
issues = None
break
elif key == 'label':
try:
label = Label.objects.get(name=args[1])
label = Label.objects.get(project=project,name=value,deleted=False)
except ObjectDoesNotExist:
messages.info(request, "The label '%s' does not exist"
", ignoring the constraint." %args[1])
messages.error(request, "The label '%s' does not exist." %value)
issues = None
break
else:
issues = issues.filter(labels=label)
elif key == 'author' or key == 'user':
try:
author = User.objects.get(username=value)
except ObjectDoesNotExist:
messages.error(request, "The user '%s' does not exist." %value)
issues = None
break
else:
error = True
issues = issues.filter(author=author)
else:
messages.error(request, "Unknow '%s' filtering criterion." %keyword)
issues = None
break
if error:
messages.error(request, 'There is a syntaxe error in your filter.')
issues = project.issues.filter(closed=False)
if key != 'is':
is_all_query += ' ' + constraint
if issues:
issues = issues.extra(order_by=['-opened_at'])
if is_open == '' and is_close == '':
is_all = ' active'
c = {
'request': request,
'projects': projects,
'project': project,
'issues': issues,
'query': query,
'is_open': is_open,
'is_close': is_close,
'is_all': is_all,
'is_all_query': is_all_query[1:],
}
return render(request, 'issue/issue_list.html', c)
@ -128,7 +209,7 @@ def issue_edit(request, project, id=None):
if id:
issue = get_object_or_404(Issue, project__name=project.name, id=id)
init_data = {'title': issue.title,
'comment': issue.events.first().additionnal_section}
'description': issue.description}
else:
issue = None
init_data = None
@ -136,15 +217,14 @@ def issue_edit(request, project, id=None):
class IssueForm(forms.Form):
title = forms.CharField(max_length=128)
comment = forms.CharField(widget=MarkdownWidget)
description = forms.CharField(widget=MarkdownWidget, required=False)
form = IssueForm(request.POST or init_data)
if request.method == 'POST' and form.is_valid():
title = form.cleaned_data['title']
comment = form.cleaned_data['comment']
print(comment)
description = form.cleaned_data['description']
if issue:
@ -160,10 +240,8 @@ def issue_edit(request, project, id=None):
event.save()
modified = True
first_comment = issue.events.first()
if first_comment.additionnal_section != comment:
first_comment.additionnal_section = comment
first_comment.save()
if issue.description != description:
issue.description = description
modified = True
if modified:
@ -177,9 +255,7 @@ def issue_edit(request, project, id=None):
issue = Issue(title=title, author=author,
project=project, id=Issue.next_id(project))
issue.save()
event = Event(issue=issue, author=author, code=Event.COMMENT,
additionnal_section=comment)
event.save()
issue.description = description
messages.success(request, 'Issue created successfully.')
return redirect('show-issue', project.name, issue.id)
@ -200,12 +276,17 @@ def issue(request, project, id):
issue = get_object_or_404(Issue, project__name=project, id=id)
projects = Project.objects.all()
labels = Label.objects.filter(project=issue.project, deleted=False) \
.exclude(id__in=issue.labels.all().values_list('id'))
milestones = Milestone.objects.filter(project=issue.project)
events = issue.events.all()
c = {
'request': request,
'projects': projects,
'labels': labels,
'milestones': milestones,
'project': issue.project,
'issue': issue,
'events': events,
@ -219,7 +300,7 @@ def issue_comment(request, project, id, comment=None):
if comment:
event = get_object_or_404(Event, code=Event.COMMENT, issue=issue, id=comment)
init_data = {'comment': comment.additionnal_section}
init_data = { 'comment': event.additionnal_section }
else:
event = None
init_data = None
@ -301,11 +382,31 @@ def issue_delete(request, project, id):
return redirect('list-issue', project)
def issue_add_label(request, project, issue, label):
issue = get_object_or_404(Issue, project__name=project, id=issue)
label = get_object_or_404(Label, project__name=project, id=label)
author = User.objects.get(username=request.user.username)
issue.add_label(author, label)
return redirect('show-issue', project, issue.id)
def issue_remove_label(request, project, issue, label):
issue = get_object_or_404(Issue, project__name=project, id=issue)
label = get_object_or_404(Label, project__name=project, id=label)
author = User.objects.get(username=request.user.username)
issue.remove_label(author, label)
return redirect('show-issue', project, issue.id)
def label_list(request, project):
project = get_object_or_404(Project, name=project)
labels = project.labels.all()
labels = project.labels.filter(deleted=False)
projects = Project.objects.all()
@ -318,18 +419,37 @@ def label_list(request, project):
return render(request, 'issue/label_list.html', c)
def label_edit(request, project, label=None):
def label_edit(request, project, id=None):
project = get_object_or_404(Project, name=project)
if label:
label = get_object_or_404(Label, project=project, name=label)
if id:
label = get_object_or_404(Label, project=project, id=id)
else:
label = None
class LabelForm(forms.ModelForm):
class Meta:
model = Label
fields = ['name', 'color', 'inverted']
LabelForm = modelform_factory(Label, fields=['name', 'color'])
form = LabelForm(request.POST or None, instance=label)
if request.method == 'POST' and form.is_valid():
similar = Label.objects.filter(project=project,
name=form.cleaned_data['name'], deleted=False)
if label:
similar = similar.exclude(pk=label.pk)
if similar.count():
form._errors['name'] = ['There is already a label with this name.']
else:
if label:
form.save()
messages.success(request, 'Label modified successfully.')
@ -339,6 +459,10 @@ def label_edit(request, project, label=None):
label.save()
messages.success(request, 'Label added successfully.')
issue = request.GET.get('issue')
if issue:
return redirect('add-label-to-issue', project.name, issue, label.id)
return redirect('list-label', project.name)
projects = Project.objects.all()
@ -347,12 +471,25 @@ def label_edit(request, project, label=None):
'request': request,
'projects': projects,
'project': project,
'label': label,
'form': form,
}
return render(request, 'issue/label_edit.html', c)
def label_delete(request, project, id):
label = get_object_or_404(Label, project=project, id=id)
author = User.objects.get(username=request.user.username)
for issue in label.issues.all():
issue.remove_label(author, label)
label.deleted = True
label.save()
messages.success(request, "Label deleted successfully.")
return redirect('list-label', project)
def milestone_list(request, project):
project = get_object_or_404(Project, name=project)

View file

@ -3,5 +3,6 @@ Markdown==2.4.1
django-colorful==1.0.1
django-crispy-forms==1.4.0
django-markdown==0.6.1
django-stronghold==0.2.6
ipython==2.1.0
pyinotify==0.9.4