summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandre Leray <alexandre@alexandreleray.com>2010-11-03 23:49:02 (GMT)
committer Alexandre Leray <alexandre@alexandreleray.com>2010-11-03 23:49:02 (GMT)
commit677590ce0f0926374d8741f125bb346098314f48 (patch)
tree8bf6f82e18d8504f199280b3f32452d8ece340d3
parent2bb1be3a1e752a2ba06a4da6c104526a9f6e2684 (diff)
puttin back pull request. it works except csrf when sending
-rw-r--r--brainch/templates/brainch/pull-request.html1
-rwxr-xr-xbrainch/templates/brainch/view.html2
-rwxr-xr-xbrainch/views/repositories/pull_request.py14
-rwxr-xr-xbrainch/views/utils.py29
4 files changed, 22 insertions, 24 deletions
diff --git a/brainch/templates/brainch/pull-request.html b/brainch/templates/brainch/pull-request.html
index 1645cf5..d674bcf 100644
--- a/brainch/templates/brainch/pull-request.html
+++ b/brainch/templates/brainch/pull-request.html
@@ -16,6 +16,7 @@
<div class="column60">
<h2>Share your copy of {{ repo.name }}</h2>
<form method="post" action="." name="pull-request">
+ {% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Send request" />
</form>
diff --git a/brainch/templates/brainch/view.html b/brainch/templates/brainch/view.html
index 623ceb8..c44e398 100755
--- a/brainch/templates/brainch/view.html
+++ b/brainch/templates/brainch/view.html
@@ -15,7 +15,7 @@
{% if user.is_authenticated %}
{% ifequal repo.user user %}
<li><a href="{% url brainch-edit repo.user repo.slug %}">Edit the text</a></li>
- <li><a href="#{#{% url brainch-pull-request repo.user repo.slug %}#}" style='text-decoration: line-through'>Propose your changes</a></li>
+ <li><a href="{% url brainch-pull-request repo.user repo.slug %}" style='text-decoration: line-through'>Propose your changes</a></li>
{% else %}
{% if true %}
<li><a href="{% url brainch-pull repo.user repo.slug %}">Synchronize your text</a></li>
diff --git a/brainch/views/repositories/pull_request.py b/brainch/views/repositories/pull_request.py
index 0f83942..76ca939 100755
--- a/brainch/views/repositories/pull_request.py
+++ b/brainch/views/repositories/pull_request.py
@@ -39,19 +39,19 @@ def pull_request(request, username, name):
#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 have been sent to %s ' % u", ".join(mates))
- request.notifications.add('Your clone invitation have been sent to %s ' % u", ".join(prospects))
- user_action = UserAction(user=u, action="invited %sto pull his/her version of the text entitled \"%s\"" % (", ".join(mates), name))
+ 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 entitled \"%s\"" % (", ".join(prospects), name))
+ 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
else:
- email_body = """%s would like you to share his/her version of the text entitled \"%s\" with you. \
- Use the \"clone\" if you don't have a copy of that yet, otherwise use the \"pull\" link to import %s's modifications. \
- Both links are located in the side menu.""" % (username, name, username)
+ 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. \
+ Both links are located on the left sidebar.""" % (username, name, username)
data = { 'message': email_body }
form = PullRequestForm(data, mates=get_mate_repos(username, name), prospects=get_mate_repos(username, name, invert=True)) # An unbound form
diff --git a/brainch/views/utils.py b/brainch/views/utils.py
index 57ed9b2..b64f342 100755
--- a/brainch/views/utils.py
+++ b/brainch/views/utils.py
@@ -20,6 +20,7 @@ from os import listdir
from os.path import join
from django.conf import settings
from django.contrib.auth.models import User
+from brainch.models import Repository
def check_repo(request, username, name):
@@ -48,24 +49,20 @@ def get_mate_repos(username, name, invert=False):
"""Returns a tuple of mate repos (ie repo with the same name)"""
mates = []
prospects= []
- dirs = listdir(settings.BRAINCH_REPO_PATH)
- for dir in dirs:
- if name in listdir(join(settings.BRAINCH_REPO_PATH, dir)):
- try:
- mate = User.objects.get(username=dir)
- if mate.username != username:
- mates.append((mate.email, u"%s (%s)" % (mate.username, mate.email)))
- except:
- pass
- else:
- try:
- prospect = User.objects.get(username=dir)
- prospects.append((prospect.email, u"%s (%s)" % (prospect.username, prospect.email)))
- except:
- pass
+ # List of users already sharing a copy
+ clone_list = Repository.objects.filter(name=name)
+ for clone in clone_list:
+ if clone.user.username != username:
+ 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:
+ prospects.append((user.email, u"%s (%s)" % (user.username, user.email)))
+ # Substracting users already in mates
+ prospects = [item for item in prospects if item not in mates]
+
if invert:
return prospects
else:
return mates
-