]> git.parisson.com Git - teleforma.git/commitdiff
add period filtering for contents
authoryomguy <yomguy@parisson.com>
Fri, 2 Nov 2012 11:01:41 +0000 (12:01 +0100)
committeryomguy <yomguy@parisson.com>
Fri, 2 Nov 2012 11:01:41 +0000 (12:01 +0100)
example/settings.py
teleforma/templates/teleforma/inc/document_list.html
teleforma/templates/teleforma/inc/media_list.html
teleforma/templatetags/teleforma_tags.py
teleforma/views/core.py

index 4c6bda5f637850742344dc454a38320030709d16..8d8194f3880c272249fae773dd399f8c5eb76d15 100644 (file)
@@ -194,5 +194,5 @@ TELECASTER_MASTER_SERVER = 'angus.parisson.com'
 
 # CRFPA or AE or PRO
 TELEFORMA_E_LEARNING_TYPE = 'CRFPA'
-
+TELEFORMA_GLOBAL_TWEETER = False
 
index f774b7cbb50c3fec17f20fd09c9bd9e0102e943d..0982c352a0be5f5b75b0bda29bfb084e50197b02 100644 (file)
@@ -13,7 +13,7 @@
 <span class="doc_type_title">{{ doc_type }}</span>
 <table class="listing" width="100%">
     <tbody>
-        {% for doc in docs|from_course_type:type|from_doc_type:doc_type %}
+        {% for doc in docs|from_course_type:type|from_doc_type:doc_type|from_periods:periods %}
         {% if doc.course_type.all|length > 1 and type_counter > 1 %}
         {% else %}
         <tr>
index e204093caf73f6354f103d4fd6adc3b2a1a8e973..e0770566484312fc36bec913bce450f0e563d324 100644 (file)
@@ -9,7 +9,7 @@
 </div>
     <table class="listing" width="100%">
     <tbody>
-        {% for media in course.media.all|from_course_type:type %}
+        {% for media in course.media.all|from_course_type:type|from_periods:periods %}
          {% if media.is_published or user.is_staff %}
           {% if media.type == 'webm' %}
             <tr>
index c2ec5059678c73a4adc3ff6bd3f60e9eb6fa7151..d88e9a187744d58e80a3ed30c2bbe6265c64e3cd 100644 (file)
@@ -134,16 +134,20 @@ def yes_no(bool):
         return _('No')
 
 @register.filter
-def from_course_type(docs, type):
-    if docs:
-        return docs.filter(course_type=type)
-    else:
-        return False
-
+def from_course_type(contents, type):
+    if contents:
+        return contents.filter(course_type=type)
+    
 @register.filter
-def from_doc_type(docs, type):
-    return docs.filter(type=type)
-
+def from_doc_type(contents, type):
+    if contents:
+        return contents.filter(type=type)
+    
+@register.filter
+def from_periods(contents, periods):
+    if contents:
+        return contents.filter(period__in=periods)
+    
 @register.assignment_tag
 def get_all_professors():
     return Professor.objects.all().order_by('user__first_name')
index ddcb14cec9e99c71d14bb2e32829856b340f89a1..1b3290d26469a79a7e0ee4c58c9545a49ec046e4 100644 (file)
@@ -153,6 +153,26 @@ def get_random_hash():
     hash = random.getrandbits(128)
     return "%032x" % hash
 
+def get_periods(user):
+    professor = user.professor.all()
+    if professor:
+        professor = user.professor.get()
+        periods = Period.objects.all()
+
+    if settings.TELEFORMA_E_LEARNING_TYPE == 'CRFPA':
+        student = user.crfpa_student.all()
+        if student:
+            student = user.crfpa_student.get()
+            periods = student.period.all() 
+
+    elif settings.TELEFORMA_E_LEARNING_TYPE == 'AE':
+        student = user.ae_student.all()
+        if student:
+            student = user.ae_student.get()
+            periods = student.period.all()
+
+    return periods
+    
 
 class CourseView(DetailView):
 
@@ -176,6 +196,7 @@ class CourseView(DetailView):
             context['room'] = get_room(name=course.title, content_type=content_type,
                                    id=course.id)
         context['doc_types'] = DocumentType.objects.all()
+        context['periods'] = get_periods(self.request.user)
         return context
 
     @method_decorator(login_required)
@@ -198,6 +219,7 @@ class CoursesView(ListView):
         context['room'] = get_room(name='site')
         context['doc_types'] = DocumentType.objects.all()
         context['all_courses'] = sorted(self.all_courses, key=lambda k: k['number'])
+        context['periods'] = get_periods(self.request.user)
         return context
 
     @method_decorator(login_required)
@@ -232,6 +254,7 @@ class MediaView(DetailView):
         if not access:
             context['access_error'] = access_error
             context['message'] = contact_message
+        context['periods'] = get_periods(self.request.user)
         return context
 
     @method_decorator(login_required)
@@ -295,6 +318,7 @@ class DocumentView(DetailView):
         if not access:
             context['access_error'] = access_error
             context['message'] = contact_message
+        context['periods'] = get_periods(self.request.user)
         return context
 
     @method_decorator(login_required)
@@ -353,6 +377,7 @@ class ConferenceView(DetailView):
         if not access:
             context['access_error'] = access_error
             context['message'] = contact_message
+        context['periods'] = get_periods(self.request.user)
         return context
 
     @jsonrpc_method('teleforma.stop_conference')