Skip to content
This repository has been archived by the owner on Oct 28, 2023. It is now read-only.

Hooked up postman_write url to a exchange_filter function which checks a... #8

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion mentorup/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
from django.conf.urls.static import static
from django.views.generic import TemplateView, RedirectView

# Import postman URL requirements for customization
from django.views.generic.base import RedirectView

from postman import OPTIONS
from postman.views import (InboxView, SentView, ArchivesView, TrashView,
WriteView, ReplyView, MessageView, ConversationView,
ArchiveView, DeleteView, UndeleteView)

from users.views import sender_profile_required

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
Expand All @@ -30,7 +40,22 @@
url(r'^avatar/', include('avatar.urls')),

# Your stuff: custom urls go here
url(r'^messages/', include('postman.urls')),
# url(r'^messages/', include('postman.urls')),

# URL pattern for select2's AJAX Support
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

urlpatterns += patterns('postman.views',
url(r'^messages/inbox/(?:(?P<option>'+OPTIONS+')/)?$', InboxView.as_view(), name='postman_inbox'),
url(r'^messages/sent/(?:(?P<option>'+OPTIONS+')/)?$', SentView.as_view(), name='postman_sent'),
url(r'^messages/archives/(?:(?P<option>'+OPTIONS+')/)?$', ArchivesView.as_view(), name='postman_archives'),
url(r'^messages/trash/(?:(?P<option>'+OPTIONS+')/)?$', TrashView.as_view(), name='postman_trash'),
url(r'^messages/write/(?:(?P<recipients>[\w.@+-:]+)/)?$', WriteView.as_view(exchange_filter=sender_profile_required), name='postman_write'),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Postman urls added for the purpose of the exchange_filter argument pass.

url(r'^messages/reply/(?P<message_id>[\d]+)/$', ReplyView.as_view(), name='postman_reply'),
url(r'^messages/view/(?P<message_id>[\d]+)/$', MessageView.as_view(), name='postman_view'),
url(r'^messages/view/t/(?P<thread_id>[\d]+)/$', ConversationView.as_view(), name='postman_view_conversation'),
url(r'^messages/archive/$', ArchiveView.as_view(), name='postman_archive'),
url(r'^messages/delete/$', DeleteView.as_view(), name='postman_delete'),
url(r'^messages/undelete/$', UndeleteView.as_view(), name='postman_undelete'),
(r'^$', RedirectView.as_view(url='inbox/')),
)
7 changes: 6 additions & 1 deletion mentorup/templates/users/user_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ <h4>What I want to learn</h4>
</div>

<div class="col-sm-1 col-md-offset-1">
<a href="{% url 'postman_write' user.username %}" class="btn btn-large btn-success pull-right contact-me"><i class="icon-envelope-alt"></i>&nbsp;Contact me</a>
<a href="{% url 'postman_write' user.username %}" class="btn btn-large btn-success pull-right contact-me"><i class="icon-envelope-alt">
{% if user.available_to_teach %}
</i>&nbsp;Contact me</a>
{% else %}
</i>&nbsp;Unavailable</a>
{% endif %}
</div>
</a>

Expand Down
2 changes: 1 addition & 1 deletion mentorup/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __unicode__(self):
skills_to_learn = models.ManyToManyField(Skill, related_name='skills_to_learn', blank=True)

available_to_teach = models.BooleanField(default=False)
availability_description = models.TextField()
availability_description = models.TextField(blank=True)

short_bio = models.TextField()
location = models.CharField(max_length=50, choices=sorted(LOCATIONS), default="boston")
Expand Down
5 changes: 0 additions & 5 deletions mentorup/users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,4 @@
name='search'
),

# url(
# regex=r'^~write_redirect/(?P<recipients>[\w\-_]+)/$',
# view=views.UserPostmanRedirect.as_view(),
# name='postman_write_redirect'
# ),
)
36 changes: 13 additions & 23 deletions mentorup/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django.db.models import Q

# Only authenticated users can access views using this.
from braces.views import LoginRequiredMixin, AccessMixin
from braces.views import LoginRequiredMixin

# Import the form from users/forms.py
from .forms import UserForm, MemberSearchForm
Expand All @@ -21,28 +21,18 @@
from .models import User, Skill


# class ProfileRequiredMixin(AccessMixin):
# """
# View mixin which verifies that the user has a profile created.
# """
# def dispatch(self, request, *args, **kwargs):
# if not request.user.is_authenticated() or not request.user.has_valid_profile():
# if self.raise_exception:
# raise PermissionDenied # return a forbidden response
# else:
# return HttpResponseRedirect(reverse(
# "users:update"))

# return super(ProfileRequiredMixin, self).dispatch(
# request, *args, **kwargs)


# class UserPostmanRedirect(ProfileRequiredMixin, RedirectView):

# def get_redirect_url(self, recipients):
# return reverse(
# "postman_write",
# kwargs={"recipients": recipients})
def sender_profile_required(sender, recipient, recipients_list):
'''
Method attached to postman_write url via exchange_filter.
Checks to see if a message sender has a valid profile, if not, returns a
message. Otherwise, the user can send a message.
'''
if not sender.has_valid_profile():
return "You must create a profile before contacting a user! Your profile must at least contain a short bio and the skills you wish to learn."
for recipient_user in recipients_list:
if not recipient_user.available_to_teach:
return "This user is not available to teach at this time."
return None


class UserDetailView(DetailView):
Expand Down