summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandre Leray <alexandre@alexandreleray.com>2010-11-04 10:31:42 (GMT)
committer Alexandre Leray <alexandre@alexandreleray.com>2010-11-04 10:31:42 (GMT)
commitfc4e0ca08505483f72cb962343d9969e34f9ae34 (patch)
treea99e1046529188b4f789d1499aa238069bc4d634
parent677590ce0f0926374d8741f125bb346098314f48 (diff)
pull/request functions again
-rwxr-xr-xbrainch/models/actions.py14
-rw-r--r--brainch/templates/brainch/pull-request.html6
-rwxr-xr-xbrainch/views/repositories/edit.py2
-rwxr-xr-xbrainch/views/repositories/pull_request.py46
-rwxr-xr-xbrainch/views/utils.py8
5 files changed, 46 insertions, 30 deletions
diff --git a/brainch/models/actions.py b/brainch/models/actions.py
index e370e34..1ad4d8b 100755
--- a/brainch/models/actions.py
+++ b/brainch/models/actions.py
@@ -26,6 +26,7 @@ ACTION_CHOICES = (
(02, "EDITED"),
(03, "CLONED"),
(04, "PULLED"),
+ (05, "INVITED"),
)
@@ -50,6 +51,7 @@ class UserAction(models.Model):
ordering = ['-when']
def _get_message(self):
+ # TODO: Clone invitation action message
profile = self.who.get_profile()
data = json.loads(self.data)
@@ -57,18 +59,24 @@ class UserAction(models.Model):
% (profile.get_absolute_url(), self.who.username)
if self.get_what_display() == "CREATED":
message += "<span class=\"created\">created</span> "
- message += "a text entitled <em>%s</em>" \
+ message += "the text <em>%s</em>" \
% data.get("repo_name", "???")
elif self.get_what_display() == "EDITED":
message += "<span class=\"edited\">&#2710; edited</span> "
- message += "the text entitled <em>%s</em>" \
+ message += "the text <em>%s</em>" \
% data.get("repo_name", "???")
elif self.get_what_display() == "CLONED":
message += "<span class=\"cloned\">&#9903; cloned</span> "
- message += "the text entitled <em>%s</em> " \
+ message += "the text <em>%s</em> " \
% data.get("repo_name", "???")
message += "from %s" \
% data.get("origin_user", "???")
+ elif self.get_what_display() == "INVITED":
+ message += "<span class=\"invited\">invited</span> "
+ message += "%s " \
+ % data.get("repo_mates", "???")
+ message += "to synchronize his/her version of the text <em>%s</em> " \
+ % data.get("repo_name", "???")
else:
return None
diff --git a/brainch/templates/brainch/pull-request.html b/brainch/templates/brainch/pull-request.html
index d674bcf..ec7642e 100644
--- a/brainch/templates/brainch/pull-request.html
+++ b/brainch/templates/brainch/pull-request.html
@@ -4,12 +4,10 @@
{% block sidebar %}
- <h2>Tools</h2>
<ul class="tools">
- <li><a href='{% url brainch-view user.username page.name %}'>Read latest version</a></li>
- <li><a href='{% url brainch-history user.username page.name %}'>History of the text</a></li>
+ <li><a href='{% url brainch-view repo.user repo.name %}'>Read latest version</a></li>
+ <li><a href='{% url brainch-history repo.user repo.name %}'>History of the text</a></li>
</ul>
- {% include 'brainch/inclusion/author-list.html' %}
{% endblock sidebar %}
{% block main %}
diff --git a/brainch/views/repositories/edit.py b/brainch/views/repositories/edit.py
index 8c314ef..ed8ed21 100755
--- a/brainch/views/repositories/edit.py
+++ b/brainch/views/repositories/edit.py
@@ -97,7 +97,7 @@ def edit(request, username, name):
)
action.save()
- # Add a message
+ # Add a notification
messages.add_message(request, messages.INFO, dedent("""\
Your modifications have been saved.\
"""))
diff --git a/brainch/views/repositories/pull_request.py b/brainch/views/repositories/pull_request.py
index 76ca939..c58e73b 100755
--- a/brainch/views/repositories/pull_request.py
+++ b/brainch/views/repositories/pull_request.py
@@ -20,34 +20,47 @@ from django.contrib import messages
from django.template import RequestContext
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
-from brainch.views.utils import check_repo, get_mate_repos
+from brainch.views.utils import get_mate_repos
from brainch.forms import PullRequestForm
-from brainch.models import UserAction
+from brainch.models import UserAction, Repository
+from datetime import datetime
+import json
def pull_request(request, username, name):
"""
Send to one's mates a request for pull
"""
+ repo = Repository.objects.get(name=name, user__username=username)
if request.method == 'POST': # If the form has been submitted...
form = PullRequestForm(request.POST, mates=get_mate_repos(username, name), prospects=get_mate_repos(username, name, invert=True)) # A form bound to the POST data
if form.is_valid():
mates = form.cleaned_data['mates']
prospects = form.cleaned_data['prospects']
- message = form.cleaned_data['message']
- u = request.user
+
#from django.core.mail import send_mail
- #send_mail(subject, message, u.email, recipients)
- # TODO display the user firstname and lastname in the actions
- request.notifications.add('Your pull invitation has been sent to %s ' % u", ".join(mates))
- request.notifications.add('Your clone invitation has been sent to %s ' % u", ".join(prospects))
- user_action = UserAction(user=u, action="invited %sto pull his/her version of the text \"%s\"" % (", ".join(mates), name))
- user_action.save()
- user_action = UserAction(user=u, action="invited %sto clone his/her version of the text \"%s\"" % (", ".join(prospects), name))
- user_action.save()
- #return HttpResponse(message)
- #return HttpResponseRedirect('/contact/merci/') # Redirect after POST
- return HttpResponseRedirect('../') # Redirect after POST
+ #send_mail(subject, message, repo.user.email, recipients)
+
+ # Display a notification
+ messages.add_message(request, messages.INFO, dedent("""\
+ Your invitation has been sent.\
+ """))
+
+ # Creates an action for record
+ # TODO: Clone invitation action message
+ action = UserAction(
+ who=repo.user,
+ what=UserAction.get_action_index("INVITED"),
+ when=datetime.now(),
+ data=json.dumps({
+ "repo_name": repo.name,
+ "repo_mates": "%s" % (", ".join(mates)),
+ }),
+ )
+ action.save()
+ #user_action = UserAction(user=u, action="invited %sto clone his/her version of the text \"%s\"" % (", ".join(prospects), name))
+ #user_action.save()
+ return HttpResponseRedirect('/%s/%s' % (username, name)) # Redirect after POST
else:
email_body = """%s would like you to share his/her version of the text \"%s\" with you. \
Use the \"clone\" link if you don't have a copy of it yet, otherwise use the \"synchronize\" link to import %s's modifications. \
@@ -55,11 +68,8 @@ def pull_request(request, username, name):
data = { 'message': email_body }
form = PullRequestForm(data, mates=get_mate_repos(username, name), prospects=get_mate_repos(username, name, invert=True)) # An unbound form
- page, repo, content = check_repo(request, username, name)
ctx = {
- 'page': page,
'repo': repo,
- 'username': username,
'form': form,
}
return render_to_response('brainch/pull-request.html', ctx, context_instance=RequestContext(request))
diff --git a/brainch/views/utils.py b/brainch/views/utils.py
index b64f342..75a1b3f 100755
--- a/brainch/views/utils.py
+++ b/brainch/views/utils.py
@@ -24,7 +24,8 @@ from brainch.models import Repository
def check_repo(request, username, name):
- """Checks is a repository exist. If not, create one."""
+ #IS THIS STILL USED???
+ """Checks if a repository exist. If not, create one."""
# Does the repo exist?
try:
# Yes, and read its content
@@ -50,10 +51,9 @@ def get_mate_repos(username, name, invert=False):
mates = []
prospects= []
# List of users already sharing a copy
- clone_list = Repository.objects.filter(name=name)
+ clone_list = Repository.objects.filter(name=name).exclude(user__username=username)
for clone in clone_list:
- if clone.user.username != username:
- mates.append((clone.user.email, u"%s (%s)" % (clone.user.username, clone.user.email)))
+ mates.append((clone.user.email, u"%s (%s)" % (clone.user.username, clone.user.email)))
# List of the other users
users = User.objects.exclude(username=username)
for user in users: