Italo Maia avatar Italo Maia committed 4d07294

Updated views and urls (improved code and stuff)

Comments (0)

Files changed (2)

     (r'^$',
         'index_view', {}, 'index'),
 
+    # your own profile
+    (r'^profile/$',
+        'profile_view', {}, 'profile'),
+
     # edit your own profile
     (r'^profile/edit/$',
         'edit_profile_view', {}, 'edit_profile'),
 
-    # your own profile
-    (r'^profile/$',
-        'profile_view', {}, 'profile'),
-
-    # someonelse's profile
+    # someone's profile
     (r'^profile/(?P<nickname>[\w\-\+\.@]+)/$',
         'public_profile_view', {}, 'profile'),
 
         'messages_view', {}, 'messages'),
 
     # see forum under this category
-    (r'^category/(?P<slug_category>[\w\-\+\.@]+)/$',
+    (r'^category/(?P<pk_category>[\w\-\+\.@]+)/$',
         'category_view', {}, 'category'),
 #
     # see forum
 from django.utils.translation import ugettext
 
 from django.contrib import messages
-from django.contrib.auth.models import User
 from django.contrib.auth.decorators import login_required
 
 from django.utils import simplejson as json
 
 @request_profile
 def public_profile_view(request, nickname):
-    return render(request, 'forum/public_profile.html', {
+    return render(request, 'forum/profile.html', {
+        'is_self': False,
         'profile': get_object(Profile, nickname=nickname)
     })
 
 @request_profile(ensure=True)
 def profile_view(request):
     return render(request, 'forum/profile.html', {
+        'is_self': True,
         'profile': request.profile
     })
 
     except Profile.DoesNotExist:
         profile = None
 
-    form = ProfileForm(request.POST or None, instance=profile)
+    form = ProfileForm(
+        request.POST or None,
+        request.FILES or None,
+        instance=profile)
 
     if form.is_bound and form.is_valid():
-        profile = form.save(commit=False)
-        profile.user = request.user
-        profile.save()
+        form.save(request.user)
+        messages.info(request, _('Profile updated successfully'))
+
         # just like login, forum:profile accepts a next redirect parameter
         next_page = request.GET.get('next') or 'forum:profile'
         return redirect(next_page)
 
-    return render(request, 'forum/edit_profile.html', {'form': form})
+    return render(request, 'forum/edit_profile.html', {
+        'form': form,
+        'profile': profile
+    })
 
 
 @login_required
 @request_profile(ensure=True)
 def send_message_view(request, nickname):
-    recipient_profile = get_object(Profile, nickname=nickname)
+    recipient = get_object(Profile, nickname=nickname)
     form = MessageForm(request.POST or None)
 
     if form.is_bound and form.is_valid():
-        form.save()
-        return redirect(recipient_profile)
+        form.save(request.profile, recipient)
+        return redirect(recipient)
 
-    return render(request, 'forum/send_message.html', {'form': form})
+    return render(request, 'forum/send_message.html', {
+        'profile': request.profile,
+        'recipient': recipient,
+        'form': form
+    })
 
 
 @login_required
 @request_profile(ensure=True)
 def messages_view(request, pk_message=None):
     message_box, created = MessageBox.objects.get_or_create(profile=request.profile)
-    messages = message_box.messages.all()
+    messages = request.profile.messages.active()
 
     if pk_message:
         message = get_object(messages, pk=pk_message)
         paginator = Paginator(messages, 12)
         object_list = paginator.page(page_number)
         return render(request, 'forum/messages.html', {
+            'profile': request.profile,
             'message_set': object_list,
             'number_of_messages': number_of_messages,
             'number_of_new_messages': number_of_new_messages
 
 
 def category_view(request, pk_category):
-    category = get_object(Category.objects.active(), pk=pk_category)
-    forum_set = category.forum_set.objects.active()
-    return render(request, 'forum/category.html', {'forum_set': forum_set})
+    category_set = Category.objects.active().filter(pk=pk_category)
+    return render(request, 'forum/index.html', {'category_set': category_set})
 
 
 def forum_view(request, pk_forum):
     forum = get_object(Forum.objects.active(), pk=pk_forum)
     category = forum.category
     threads = forum.threads.active()
-    page_number = int(request.GET.get('page', 1))
+    page_number = request.GET.get('page', 1)
     object_list = Paginator(threads, PAGINATE_THREADS_BY).page(page_number)
     return render(request, 'forum/forum.html', {
         'category': category,
     threads = forum.threads.active()
     thread = get_object(threads,  pk=pk_thread)
     replies = thread.replies.active()
-    page_number = int(request.GET.get('page', 1))
+    page_number = request.GET.get('page', 1)
     object_list = Paginator(replies, PAGINATE_REPLIES_BY).page(page_number)
 
     if ALLOW_INLINE_REPLY:
             new_reply = form.save()
             return redirect(new_reply)
 
+    thread.update_views(request)
     return render(request,  'forum/thread.html',  {
             'category': category,
+            'form': form,
             'forum': forum,
             'thread': thread,
             'object_list': object_list
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.