Beispiel #1
0
def category(request, cat_id, class_id=None):
    r"""
    This is the view for category and base_category (``/class/<class_id>/category/<cat_id>`` and ``/category/<cat_id>``).  It generates the category page which has a table of all the content in all of its ``child_atoms`` and all of the ``child_atoms`` in all categories under it.
    """
    if class_id is not None:
        template = 'web/home/class/category.html'
        category_object = get_object_or_404(ClassCategory, id=cat_id)
        class_object = get_object_or_404(Class, id=class_id)
        # Check if user is allowed to see this page
        if has_class_access(class_object, request.user):
            return HttpResponseRedirect(reverse('class_index')) # Redirect
    else:
        template = 'web/home/base/category.html'
        category_object = get_object_or_404(BaseCategory, id=cat_id)
        class_object = None # We aren't in a class
    context = get_navbar_context(category_object, class_object)
    context.update( # Add the breadrumbs to the context
        get_breadcrumbs(request.path, web_breadcrumb_dict)
    )
    context.update( # Add the category specific content to the context
        get_context_for_category(category_object)
    )
    context.update({
        'class_object':class_object,
        'category_object':category_object,
    })

    return render(request, template, context)
Beispiel #2
0
def atom(request, cat_id, atom_id, class_id=None):
    r"""
    This is the view for both the ``atom`` view and the ``base_atom`` view (``/class/<class_id>/category/<cat_id>/atom/<atom_id>`` and ``/category/<cat_id>/atom/<atom_id>``).  It generates the content that is contained in the atom.
    """
    if class_id is not None:
        template = 'web/home/class/category.html'
        class_object = get_object_or_404(Class, id=class_id)
        category_object = get_object_or_404(ClassCategory, id=cat_id)
        # Check if user is allowed to see this page
        if has_class_access(class_object, request.user):
            return HttpResponseRedirect(reverse('class_index')) # Redirect
    else:
        template = 'web/home/base/category.html'
        class_object = None
        category_object = get_object_or_404(BaseCategory, id=cat_id)
    atom_object = get_object_or_404(Atom, id=atom_id) 
    context = get_navbar_context(category_object, class_object)
    context.update( # Add the breadcrumbs to the context
        get_breadcrumbs(request.path, web_breadcrumb_dict)
    )
    context.update( # Add the atom specific content to the context
        get_context_for_atom(atom_object)
    )
    context.update({
        'atom_object': atom_object,
        'class_object':class_object,
        'forum': Forum.objects.get(atom=atom_object),
    })
    return render(request, template, context)
 def get_context_data(self, **kwargs):
     context = super(CreateClassView, self).get_context_data(**kwargs)
     context.update(
         get_navbar_context()
     )
     context.update(
         get_breadcrumbs(self.request.path, web_breadcrumb_dict)
     )
     return context
Beispiel #4
0
def class_list(request):    
    r"""This is the view for the class list."""
    context = get_navbar_context()
    context.update(
        get_breadcrumbs(request.path, web_breadcrumb_dict) 
    )
    context.update({
        'class_list':    Class.objects.all()
    })
    return render(request, 'web/home/class_list.html', context)
Beispiel #5
0
def classes(request, class_id):
    r"""
    This is the view for the class home page.  It shows the class summary.
    """
    class_object = get_object_or_404(Class, id=class_id)
    # Check if user is allowed to see this page
    if has_class_access(class_object, request.user):
        return HttpResponseRedirect(reverse('class_index')) # If not redirect
    context = get_navbar_context(None, class_object)
    context.update( # Add breadcrumbs to context
        get_breadcrumbs(request.path, web_breadcrumb_dict)
    )
    context.update({ # Add the class_objet to the context
        'class_object': class_object
    })
    return render(request, 'web/home/class/index.html', context)
Beispiel #6
0
def index(request):
    """
        This is the home view for categories when you aren't in a class and haven't clicked on a category/atom yet.
    
        For now this displays the top ranked videos for all of the categories, we need to change it eventually.
    """
    context = get_navbar_context() # Add the initial navbar content.
    top_ranked_videos = cache.get('top_ranked_videos') # Load from cache
    if top_ranked_videos is None: # If there is no cached version
        print("top_ranked_videos has not been found in cache.")
        top_ranked_videos = Video.objects.all().annotate(votes=Count('vote')).order_by('-votes')[:8]
        cache.set('top_ranked_videos', top_ranked_videos, 60*10) # Set cache
        
    context.update({ # Add 'top_ranked_videos' to context
        'top_ranked_videos': top_ranked_videos,
    })
    return render(request, 'web/home/base/index.html', context)    
def exposition_submit(request, pk):
    r"""
    This is the view for the exposition submit feature.
    """
    success_url = request.GET.get('next', None)
    if 'add-another' in request.POST:
        success_url = reverse('expo_submit')
    context = get_navbar_context()
    context.update(
        get_breadcrumbs(request.path, web_breadcrumb_dict)
    )

    form_kwargs = {'user':request.user}
    if pk:
        exposition = get_object_or_404(Exposition, pk=pk)
        form_kwargs.update({'instance':exposition})
    else:
        exposition = None
    
    if request.method == 'POST': # If the form has been submitted...
        form = ExpositionForm(request.POST, request.FILES, **form_kwargs)
        if form.is_valid():    # All validation rules pass
            obj = form.save()
            messages.success(
                request,
                _('The exposition has been submitted correctly.')
            )
            if success_url is not None:
                return HttpResponseRedirect(success_url)
            else:
                return HttpResponseRedirect(obj.get_absolute_url())
            
        else:
            messages.warning(request, _('Error submitting the exposition.'))
    else:
        form = ExpositionForm(**form_kwargs)
        
    context.update({
        'object':exposition,
        'form':form,
        'success_url':success_url
    })
    
    return render(request, 'web/home/expo_submit.html', context)
def video_submit(request, pk):
    """
    This is the view for video submission.
        
    """
    success_url = request.GET.get('next', None) # Redirection URL
    if 'add-another' in request.POST:
        success_url = reverse('video_submit')
    context = get_navbar_context()
    context.update(
        get_breadcrumbs(request.path, web_breadcrumb_dict)
    )
    form_kwargs = {'user': request.user}
    if pk:
        video =  get_object_or_404(Video, pk=pk)
        form_kwargs.update({'instance':video})
    else:
        video = None
    
    if request.method == 'POST':
        form = VideoForm(request.POST, **form_kwargs)
        
        if form.is_valid():
            obj = form.save()
            messages.success(
                request,
                _('The video has been submitted correctly.')
            )
            if success_url is not None:
                return HttpResponseRedirect(success_url)
            else:
                return HttpResponseRedirect(obj.get_absolute_url())
        else:
            messages.warning(request, _('Error submitting the video.'))
    else:
        form = VideoForm(**form_kwargs)
    
    context.update({
        'object':video,
        'form':form,
        'success_url':success_url
    })

    return render(request, 'web/home/video_submit.html', context)
def EditClassView(request, class_id, cat_id):
    r"""View for editing classes."""
    context = {} # The context data
    class_object = get_object_or_404(Class, id=class_id) # The class instance
    class_form_kwargs = {'user':request.user, 'instance':class_object}
    category_form_kwargs = {'parent_class':class_object}
    
    if cat_id: # If we are editing a category
        category_object = get_object_or_404(ClassCategory, pk=cat_id)
        category_form_kwargs.update({'instance':category_object})
        
    if request.method == 'POST':
        if u'class-form' in request.POST: # class submit
            class_form = ClassForm(request.POST, **class_form_kwargs)
            context.update(
                process_forms(
                    request=request,
                    class_object=class_object,
                    class_form=class_form
                )
            )
        elif u'category-form' in request.POST: # category submit
            category_form = CategoryForm(request.POST, **category_form_kwargs)
            context.update(
                process_forms(
                    request=request,
                    class_object=class_object,
                    category_form=category_form
                )
            )
        else: # submit all
            class_form = ClassForm(request.POST, **class_form_kwargs)
            category_form = CategoryForm(request.POST, **category_form_kwargs)
            context.update(
                process_forms(
                    request=request,
                    class_object=class_object,
                    class_form=class_form,
                    category_form=category_form
                )
            )
        if request.is_ajax():
            return render_to_json_response(context) # Only need part of context
        elif cat_id is not None: # Non AJAX requests aren't allowed if cat_id
            return HttpResponseRedirect(reverse('edit_class', args=[class_id]))
    else: # GET
        if request.is_ajax():
            category_form = CategoryForm(**category_form_kwargs) # Get form
            template = loader.get_template('web/category_form_template.html')
            c = RequestContext(request, {'form':category_form})
            form_html = template.render(c) # HTML for the form
            context.update({
            'category_form':form_html # New form html will replace the old form
            })
            return render_to_json_response(context) # html for ne wform
        elif cat_id is not None: # We don't allow non ajax requests if cat_id
            return HttpResponseRedirect(reverse('edit_class', args=[class_id]))
            
        context.update({ # Add forms to context if not post
            'class_form':ClassForm(**class_form_kwargs),
            'category_form':CategoryForm(**category_form_kwargs)
        })
    context.update(
        get_navbar_context()
    )
    context.update(
        get_breadcrumbs(request.path, web_breadcrumb_dict)
    )
    context.update({
        'pk':class_object.id,
    })
    return render(request, 'web/class_edit_form.html', context)