misc: add a profile view for authenticated users
This commit is contained in:
		
							
								
								
									
										15
									
								
								aircox/templates/accounts/profile.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								aircox/templates/accounts/profile.html
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					{% extends "aircox/base.html" %}
 | 
				
			||||||
 | 
					{% load i18n aircox %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					{% block head_title %}
 | 
				
			||||||
 | 
					    {% block title %}{{ user.username }}{% endblock %}
 | 
				
			||||||
 | 
					{% endblock %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					{% block main %}
 | 
				
			||||||
 | 
					  <h2 class="subtitle is-3">Mes émissions</h2>
 | 
				
			||||||
 | 
					  <ul>
 | 
				
			||||||
 | 
					  {% for p in programs %}
 | 
				
			||||||
 | 
					    <li>• <a href="{% url 'program-detail' slug=p.slug %}">{{ p.title }}</a></li>
 | 
				
			||||||
 | 
					  {% endfor %}
 | 
				
			||||||
 | 
					  </ul>
 | 
				
			||||||
 | 
					{% endblock %}
 | 
				
			||||||
@ -85,7 +85,7 @@ Usefull context:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                            {% if user.is_authenticated %}
 | 
					                            {% if user.is_authenticated %}
 | 
				
			||||||
                                <div class="navbar-item">
 | 
					                                <div class="navbar-item">
 | 
				
			||||||
                                <a>{{ user.username }}</a>   <a href="{% url 'logout' %}"> <i class="fa fa-power-off"></i></a>
 | 
					                                    <a href="{% url 'profile' %}">{{ user.username }}</a>   <a href="{% url 'logout' %}"> <i class="fa fa-power-off"></i></a>
 | 
				
			||||||
                                </div>
 | 
					                                </div>
 | 
				
			||||||
                            {% endif %}
 | 
					                            {% endif %}
 | 
				
			||||||
                        </div>
 | 
					                        </div>
 | 
				
			||||||
 | 
				
			|||||||
@ -10,3 +10,13 @@ def test_authenticate(user, client, program):
 | 
				
			|||||||
    r = client.post(reverse("login"), kwargs={"username": "foo", "password": "bar"})
 | 
					    r = client.post(reverse("login"), kwargs={"username": "foo", "password": "bar"})
 | 
				
			||||||
    assert b"errorlist" in r.content
 | 
					    assert b"errorlist" in r.content
 | 
				
			||||||
    assert client.login(username="user1", password="bar")
 | 
					    assert client.login(username="user1", password="bar")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@pytest.mark.django_db()
 | 
				
			||||||
 | 
					def test_profile_programs(user, client, program):
 | 
				
			||||||
 | 
					    client.force_login(user)
 | 
				
			||||||
 | 
					    r = client.get(reverse("profile"))
 | 
				
			||||||
 | 
					    assert program.title not in r.content.decode("utf-8")
 | 
				
			||||||
 | 
					    user.groups.add(program.editors)
 | 
				
			||||||
 | 
					    r = client.get(reverse("profile"))
 | 
				
			||||||
 | 
					    assert program.title in r.content.decode("utf-8")
 | 
				
			||||||
 | 
				
			|||||||
@ -117,4 +117,6 @@ urls = [
 | 
				
			|||||||
        views.errors.NoStationErrorView.as_view(),
 | 
					        views.errors.NoStationErrorView.as_view(),
 | 
				
			||||||
        name="errors-no-station",
 | 
					        name="errors-no-station",
 | 
				
			||||||
    ),
 | 
					    ),
 | 
				
			||||||
 | 
					    path("gestion/", views.profile, name="profile"),
 | 
				
			||||||
 | 
					    path("accounts/profile/", views.profile, name="profile"),
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
				
			|||||||
@ -11,6 +11,7 @@ from .page import (
 | 
				
			|||||||
    PageDetailView,
 | 
					    PageDetailView,
 | 
				
			||||||
    PageListView,
 | 
					    PageListView,
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					from .profile import profile
 | 
				
			||||||
from .program import (
 | 
					from .program import (
 | 
				
			||||||
    ProgramDetailView,
 | 
					    ProgramDetailView,
 | 
				
			||||||
    ProgramListView,
 | 
					    ProgramListView,
 | 
				
			||||||
@ -36,6 +37,7 @@ __all__ = (
 | 
				
			|||||||
    "BasePageListView",
 | 
					    "BasePageListView",
 | 
				
			||||||
    "PageDetailView",
 | 
					    "PageDetailView",
 | 
				
			||||||
    "PageListView",
 | 
					    "PageListView",
 | 
				
			||||||
 | 
					    "profile",
 | 
				
			||||||
    "ProgramDetailView",
 | 
					    "ProgramDetailView",
 | 
				
			||||||
    "ProgramListView",
 | 
					    "ProgramListView",
 | 
				
			||||||
    "ProgramPageDetailView",
 | 
					    "ProgramPageDetailView",
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										15
									
								
								aircox/views/profile.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								aircox/views/profile.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					from django.contrib.auth.decorators import login_required
 | 
				
			||||||
 | 
					from django.template.response import TemplateResponse
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from aircox.models import Program
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@login_required
 | 
				
			||||||
 | 
					def profile(request):
 | 
				
			||||||
 | 
					    programs = []
 | 
				
			||||||
 | 
					    ugroups = request.user.groups.all()
 | 
				
			||||||
 | 
					    for p in Program.objects.all():
 | 
				
			||||||
 | 
					        if p.editors in ugroups:
 | 
				
			||||||
 | 
					            programs.append(p)
 | 
				
			||||||
 | 
					    context = {"user": request.user, "programs": programs}
 | 
				
			||||||
 | 
					    return TemplateResponse(request, "accounts/profile.html", context)
 | 
				
			||||||
		Reference in New Issue
	
	Block a user