Add display profile info

This commit is contained in:
chrizuuu 2021-01-27 20:09:55 +01:00
parent 2c8bc4e5dc
commit 64cf510627
68 changed files with 372 additions and 47 deletions

Binary file not shown.

View File

@ -3,10 +3,7 @@ from .models import Offer, Offer_Category, Image_offer
from reservation.models import Reservation from reservation.models import Reservation
# Register your models here. # Register your models here.
class ReservationOfferDetail(admin.TabularInline):
model = Reservation
can_delete = False
verbose_name = 'Rezerwację'
class OfferALlDetail(admin.TabularInline): class OfferALlDetail(admin.TabularInline):
model = Image_offer model = Image_offer
can_delete = True can_delete = True
@ -14,7 +11,7 @@ class OfferALlDetail(admin.TabularInline):
class OfferAdmin(admin.ModelAdmin): class OfferAdmin(admin.ModelAdmin):
model = Offer model = Offer
inlines = [OfferALlDetail,ReservationOfferDetail] inlines = [OfferALlDetail]
list_display = ('id','title','category','date_added','status','slug') list_display = ('id','title','category','date_added','status','slug')
order = 'date_added' order = 'date_added'

View File

@ -0,0 +1,18 @@
# Generated by Django 3.1.3 on 2021-01-24 16:53
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('camper', '0002_auto_20210112_1748'),
]
operations = [
migrations.AddField(
model_name='offer',
name='description',
field=models.TextField(default='', max_length=1000),
),
]

View File

@ -53,6 +53,7 @@ class Offer(models.Model):
title = models.CharField(_("Title"), max_length=50,default='Tytuł oferty') title = models.CharField(_("Title"), max_length=50,default='Tytuł oferty')
slug = models.SlugField(max_length=70, editable = False,default='' , unique=True,) slug = models.SlugField(max_length=70, editable = False,default='' , unique=True,)
description = models.TextField(max_length = 1000,default = '')
category = models.ForeignKey(Offer_Category ,default= None,on_delete= models.CASCADE) category = models.ForeignKey(Offer_Category ,default= None,on_delete= models.CASCADE)
price = models.DecimalField(max_digits=10, decimal_places=2) price = models.DecimalField(max_digits=10, decimal_places=2)

View File

@ -6,7 +6,7 @@ from django.views.generic import (
) )
from camper.models import Offer, Image_offer from camper.models import Offer, Image_offer
from django.http import Http404, HttpResponseRedirect from django.http import Http404, HttpResponseRedirect
from django.core.paginator import Paginator ,EmptyPage, PageNotAnInteger
class Home(View): class Home(View):
@ -22,6 +22,9 @@ class OfferListView(ListView):
model = Offer model = Offer
template_name = 'offer/offers.html' template_name = 'offer/offers.html'
context_object_name = 'active_offers_list' context_object_name = 'active_offers_list'
paginate_by = 4
ordering = ['-date_added']
def get_queryset(self): def get_queryset(self):
return Offer.objects.filter(status = 'Active') return Offer.objects.filter(status = 'Active')

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 KiB

Binary file not shown.

View File

@ -0,0 +1,19 @@
# Generated by Django 3.1.3 on 2021-01-24 14:57
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('reservation', '0002_auto_20210115_0037'),
]
operations = [
migrations.AlterField(
model_name='reservation',
name='reservation_start_date',
field=models.DateField(default=django.utils.timezone.now),
),
]

View File

@ -3,6 +3,21 @@ body {
color: black; color: black;
font-family: 'Poppins'; font-family: 'Poppins';
} }
body a {
color:black;
text-decoration: none;
}
body a:hover {
color:black;
text-decoration: none;
}
.link {
color:black;
text-decoration: none;
}
.link:hover {
color:black;
text-decoration: none;}
.container { .container {
width: 1380px; width: 1380px;
@ -50,11 +65,9 @@ body {
max-width: 85px; max-width: 85px;
} }
.header-logo a { .header-logo a {
color: black;
font-family: 'Dosis'; font-family: 'Dosis';
font-size: 32px; font-size: 32px;
font-weight: 600; font-weight: 600;
text-decoration: none;
} }
/* HEADER NAV */ /* HEADER NAV */
@ -65,10 +78,8 @@ body {
max-width: 90%; max-width: 90%;
} }
.header-nav a { .header-nav a {
color: black;
font-family: 'Poppins'; font-family: 'Poppins';
font-size: 14px; font-size: 14px;
text-decoration: none;
font-weight: 500; font-weight: 500;
padding-left: 15px; padding-left: 15px;
padding-right: 15px; padding-right: 15px;
@ -100,8 +111,14 @@ body {
.header-nav-bar-text { .header-nav-bar-text {
margin: auto; margin: auto;
text-align: center; text-align: center;
font-weight: 600;
} }
.header-nav-bar-text a {
font-size: 1em;
font-weight: 600!important;
}
.header-nav-bar-avatar { .header-nav-bar-avatar {
min-width: 36px; min-width: 36px;
max-height: 36px; max-height: 36px;
@ -142,4 +159,128 @@ body {
.main-content { .main-content {
padding-left: 20px; padding-left: 20px;
padding-right: 20px; padding-right: 20px;
} }
/* OFFERS BOX */
.offer-box-wrapper{
margin-top: 50px;
margin-bottom: 50px;
}
.offer-box-row{
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content:flex-start;
}
.offer-box-row div {
margin-left:6px;
}
.offer-box-wrapper-photo{
flex:10%;
}
.offer-box-wrapper-photo img {
width:400px;
border-radius: 5%;
display: block;
height: auto; /* maintain aspect ratio*/
margin: auto;
}
.offer-box-wrapper-content{
margin-top: 10px;
flex:50%;
}
.offer-box-wrapper-content h2 {
font-size:19px;
font-weight: 500;
}
.offer-box-wrapper-content p {
font-size: 12px;
}
.offer-box-wrapper-content a {
color:black;
font-size: 15px;
font-family: 'Poppins';
text-decoration: none;
}
.offer-box-wrapper-content ul {
white-space:wrap;
margin-left: 0; padding-left: 0;
}
.offer-box-wrapper-content li {
display: inline;
font-size:11px;
}
/* OFFERS PAGINATION */
.page-item.active .page-link {
z-index: 1;
color: #fff;
background-color: #070707 !important;
border-color: #000000 !important;
}
/* PROFILE */
.profile-wrapper {
margin-top: 50px;
width: 100%;
}
.profile-wrapper-row{
display: flex;
flex-flow:row wrap;
justify-content:flex-start;
min-height: 600px;
}
.profile-wrapper-row-information {
flex:20%;
background-color: crimson;
}
.profile-wrapper-row-content {
flex:70%;
}
.profile-information-row {
display: flex;
flex-flow:row wrap;
}
.profile-information-avatar{
display: flex;
justify-content: center;
align-items: center;
flex:1 100%;
}
.profile-information-avatar img {
width: 200px;
height: 200px;
margin:5px;
border-radius: 50%;
border: 0.5px solid black;
}
.profile-information-content {
margin-top:10px;
flex:1 100%;
}
.profile-email, .profile-date-joined {
color:#48484898;
text-align: center;
}
.profile-date-joined{
font-size: 0.9em;
}
.profile-logout {
color:black;
text-align: center;
font-weight: 600;
}

View File

@ -6,7 +6,10 @@
<link rel="stylesheet" href="{% static 'css/style.css' %}"> <link rel="stylesheet" href="{% static 'css/style.css' %}">
<link href = "https://fonts.googleapis.com/css?family=Dosis" rel='stylesheet'> <link href = "https://fonts.googleapis.com/css?family=Dosis" rel='stylesheet'>
<link href = "https://fonts.googleapis.com/css?family=Poppins" rel='stylesheet'> <link href = "https://fonts.googleapis.com/css?family=Poppins" rel='stylesheet'>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</head> </head>
<body> <body>
<div class='header-smart-baner'> <!-- TOP HEADER SMART BANER--> <div class='header-smart-baner'> <!-- TOP HEADER SMART BANER-->
@ -28,15 +31,21 @@
{% if user.is_authenticated %} {% if user.is_authenticated %}
{% if user.status != 'Moderator' %} {% if user.status != 'Moderator' %}
Witaj, {{ user.first_name }} <a class='link' href='{{ request.scheme }}://{{ request.META.HTTP_HOST }}/profile'> Witaj, {{ user.first_name }} </a>
{% else %} {% else %}
Witaj, Adminie <a href='{{ request.scheme }}://{{ request.META.HTTP_HOST }}/profile'>Witaj, Adminie </a>
{% endif %} {% endif %}
{% else %} {% else %}
Witaj, nieznajomy <a href='{{ request.scheme }}://{{ request.META.HTTP_HOST }}/signup'>Witaj, nieznajomy </a>
{% endif %} {% endif %}
</div> </div>
<div class='header-nav-bar-avatar'> <img src='photo.jpg'> </div> <div class='header-nav-bar-avatar'>
{% if user.avatar %}
<img src={{ user.avatar.url }}>
{% else %}
<img src='/media/avatars/default.png'>
{%endif%}
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -3,18 +3,60 @@
<link rel="stylesheet" href="{% static 'css/styles.css' %}"> <link rel="stylesheet" href="{% static 'css/styles.css' %}">
{% block content %} {% block content %}
{% if active_offers_list %}
{% for Offer in active_offers_list %} {% if active_offers_list %}
{% for Offer in active_offers_list %}
<a href ="{{ Offer.get_absolute_url}}"> <h1> {{ Offer.title}} </h1> </a>
{{ Offer.category }} {{ Offer.price }} {{ Offer.created_by }} <div class='offer-box-wrapper'>
<div class='offer-box-row'>
{% for photo in Offer.images.all %} <div class='offer-box-wrapper-photo'>
{% if photo.main_image == True%} {% for photo in Offer.images.all %}
<img src="{{ photo.image.url }}" width = 300px> {% if photo.main_image == True%}
{% endif %} <img src="{{ photo.image.url }}">
{% endfor %} {% endif %}
{% endfor %}
{% endfor %} </div>
<div class='offer-box-wrapper-content'>
<a href ="{{ Offer.get_absolute_url}}"> <h2> {{ Offer.title}} </h2></a>
<p> {{ Offer.description|truncatewords:50 }} </p>
<ul>
<li> Ilośc miejsc do spania: {{Offer.Places_to_sleep}} </li>
<li> Skrzynia biegów: {{Offer.get_gearbox_display}}</li>
</ul>
<div class='offer-box-price'>Cena: {{ Offer.price }} PLN / dzień </div>
</div>
</div>
</div>
{% endfor %}
{% endif %}
<nav aria-label="...">
{% if is_paginated %}
<ul class="pagination">
{% if page_obj.has_previous %}
<li class="page-item"><a class="page-link" href="?page={{ page_obj.previous_page_number }}" tabindex="-1">Previous</a></li>
{% else %}
<li class="page-item disabled"></li>
{% endif %}
{% for i in paginator.page_range %}
{% if page_obj.number == i %}
<li class="page-item active"><a class="page-link" href="#">{{ i }} <span class="sr-only">(current)</span></a></li>
{% else %}
<li class="page-item"><a class="page-link" href="?page={{ i }}">{{ i }}</a></li>
{% endif %}
{% endfor %}
{% if page_obj.has_next %}
<li class="page-item"><a class="page-link" href="?page={{ page_obj.next_page_number }}#">Next</a></li>
{% else %}
<li class="page-item disabled"></li>
{% endif %}
</ul>
{% endif %} {% endif %}
{% endblock %} </nav>
{% endblock %}

View File

@ -0,0 +1,30 @@
{% extends 'index.html' %}
{% load static %}
{% block content %}
<div class='profile-wrapper'>
<div class='profile-wrapper-row'>
<div class='profile-wrapper-row-information'>
<div class='profile-information-row'>
<div class='profile-information-avatar'>
{% if user.avatar %}
<img src={{ user.avatar.url }}>
{% else %}
<img src='media/avatars/default.png'>
{%endif%}
</div>
<div class='profile-information-content'>
<div class='profile-email'> @{{user.email}} </div>
<div class='profile-date-joined'>Data dołączenia: {{user.date_joined|date}} </div>
<div class='profile-logout'> <p><a href="{% url 'logout_user' %}">Log Out</a></p> </div>
</div>
</div>
</div>
<div class='profile-wrapper-row-content'>
{% for offer in offers%}
{{offer.id}}
{% endfor %}
</div>
</div>
</div>
{% endblock %}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -24,13 +24,13 @@ class CustomUserAdmin(UserAdmin):
list_display = ('id','email', "is_staff", "is_active","is_superuser",'status') list_display = ('id','email', "is_staff", "is_active","is_superuser",'status')
fieldsets = ( fieldsets = (
(None, {'fields': ('email','first_name','last_name', 'password','status')}), (None, {'fields': ('email','phone','first_name','last_name', 'password','status','avatar')}),
('Permissions', {'fields': ('is_staff', 'is_active',)}), ('Permissions', {'fields': ('is_staff', 'is_active',)}),
) )
add_fieldsets = ( add_fieldsets = (
(None, { (None, {
'classes': ('wide',), 'classes': ('wide',),
'fields': ('email','first_name','last_name', 'password1', 'password2', 'is_staff', 'is_active','status')} 'fields': ('email','phone','first_name','last_name', 'password1', 'password2', 'is_staff', 'is_active','status','avatar')}
), ),
) )
ordering = ('email',) ordering = ('email',)

View File

@ -1,20 +1,22 @@
from django import forms from django import forms
from django.contrib.auth.forms import UserCreationForm, UserChangeForm from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from phonenumber_field.formfields import PhoneNumberField
from .models import Base_User from .models import Base_User
class CustomUserCreationForm(UserCreationForm): class CustomUserCreationForm(UserCreationForm):
phone = PhoneNumberField()
class Meta(UserCreationForm): class Meta(UserCreationForm):
model = Base_User model = Base_User
fields = ('email','password',) fields =['email','password','phone']
class CustomUserChangeForm(UserChangeForm): class CustomUserChangeForm(UserChangeForm):
phone = PhoneNumberField()
class Meta: class Meta:
model = Base_User model = Base_User
fields = ('email','password',) fields = ['email','password','phone']

View File

@ -0,0 +1,19 @@
# Generated by Django 3.1.3 on 2021-01-26 19:13
from django.db import migrations
import phonenumber_field.modelfields
class Migration(migrations.Migration):
dependencies = [
('users', '0004_auto_20210114_2051'),
]
operations = [
migrations.AddField(
model_name='base_user',
name='phone',
field=phonenumber_field.modelfields.PhoneNumberField(blank=True, default='', max_length=128, null=True, region=None, unique=True),
),
]

View File

@ -42,7 +42,8 @@ class UserManager(BaseUserManager):
class Base_User(AbstractBaseUser,PermissionsMixin): class Base_User(AbstractBaseUser,PermissionsMixin):
id = models.AutoField(primary_key= True) id = models.AutoField(primary_key= True)
email = models.EmailField(_('Email'), unique= True) email = models.EmailField(_('Email'), unique= True)
#phone = PhoneNumberField(null = False, blank = False, unique = True) phone = PhoneNumberField(null = False, blank = False, unique = True, default = '')
avatar = models.ImageField(upload_to='media/avatars', null = True, blank = True,default='media/avatars/default.png')
first_name = models.CharField(_('First Name'), max_length=30, blank = False, default = '') first_name = models.CharField(_('First Name'), max_length=30, blank = False, default = '')
last_name = models.CharField(_('Last name'), max_length=30, blank = False,default = '') last_name = models.CharField(_('Last name'), max_length=30, blank = False,default = '')
@ -63,7 +64,6 @@ class Base_User(AbstractBaseUser,PermissionsMixin):
def __str__(self): def __str__(self):
return self.email return self.email
class Meta: class Meta:
verbose_name = "User" verbose_name = "User"
verbose_name_plural = "Users" verbose_name_plural = "Users"
@ -71,8 +71,6 @@ class Base_User(AbstractBaseUser,PermissionsMixin):
class NormalUser(models.Model): class NormalUser(models.Model):
user = models.OneToOneField(Base_User, on_delete=models.CASCADE, blank= True,null = True ) user = models.OneToOneField(Base_User, on_delete=models.CASCADE, blank= True,null = True )
#avatar = models.ImageField(upload_to='media/avatars', null = True, blank = True,)
birth_date = models.DateField(_('Birth date'),null=True, blank=True) birth_date = models.DateField(_('Birth date'),null=True, blank=True)
#add fields Country, state, postal code, city, address1, address2 #add fields Country, state, postal code, city, address1, address2

View File

@ -0,0 +1,10 @@
from django.conf.urls import url
from django.urls import path
from django.conf.urls.static import static
from . import views
urlpatterns = [
path('profile', views.ProfileView.as_view(), name = 'profile_view'),
path('logout', views.logout_view, name ='logout_user'),
]

View File

@ -1,7 +1,17 @@
from django.shortcuts import render from django.shortcuts import render
from .forms import CustomUserCreationForm from .forms import CustomUserCreationForm
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from .models import Base_User, NormalUser, OwnerUser
from django.views.generic import (
View,
)
from django.contrib.auth import logout
from django.conf import settings
from django.http import HttpResponseRedirect
from django.contrib import messages
from camper.models import Offer
# Create your views here. # Create your views here.
#REJESTRACJA BASE USERA NASTĘPNIE WYBOR JAKI RODZAJ KONTA UZYTKOWNIK CCHE ZALOZYC #REJESTRACJA BASE USERA NASTĘPNIE WYBOR JAKI RODZAJ KONTA UZYTKOWNIK CCHE ZALOZYC
@ -9,7 +19,6 @@ from django.shortcuts import render, redirect
class RegisterBaseUser(): # tworzy BaseUsera ze statusem BaseACC dla NormalUser i OwnerUser class RegisterBaseUser(): # tworzy BaseUsera ze statusem BaseACC dla NormalUser i OwnerUser
def register_create_base_user(self,request): def register_create_base_user(self,request):
pass pass
@ -19,11 +28,33 @@ class RegisterBaseUser(): # tworzy BaseUsera ze statusem BaseACC dla NormalUser
class UserPickAccStatus(): #uzytkownik wybiera swoj rodzaj konta i uzuieplnia danymi class UserPickAccStatus(): #uzytkownik wybiera swoj rodzaj konta i uzuieplnia danymi
pass pass
class EditProfile(): #edycja danych w profilu - zmiana hasłą + zmiana danych
pass
class UpgradeProfileToOwnerUser(): #uzytkownik moze w kazdej cwhili zmienic swoje konto na konto firmowe class UpgradeProfileToOwnerUser(): #uzytkownik moze w kazdej cwhili zmienic swoje konto na konto firmowe
pass pass
class DowngradeProfileToNormalUser(): #uzytkownik moze zawieisc swoje konto firmowa wracajac na status konta NormalUser class DowngradeProfileToNormalUser(): #uzytkownik moze zawieisc swoje konto firmowa wracajac na status konta NormalUser
pass pass
class ProfileView(View):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["offers"] = Offer.objects.filter(created_by = self.Base_User)
return context
@method_decorator(login_required,name='dispatch')
def get(self,request):
self.Base_User = request.user
return render(request,'users/profile.html', {'Base_User':Base_User})
class EditProfile(): #edycja danych w profilu - zmiana hasłą + zmiana danych
pass
def logout_view(request):
logout(request)
messages.success(request,'Zostałeś poprawnie wylogowany')
return HttpResponseRedirect('/')

Binary file not shown.

Binary file not shown.

View File

@ -43,6 +43,8 @@ INSTALLED_APPS = [
'address', 'address',
'django_extensions', 'django_extensions',
'reservation', 'reservation',
'phonenumber_field',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
@ -119,6 +121,7 @@ AUTH_PASSWORD_VALIDATORS = [
# https://docs.djangoproject.com/en/3.1/topics/i18n/ # https://docs.djangoproject.com/en/3.1/topics/i18n/
AUTH_USER_MODEL = 'users.Base_User' AUTH_USER_MODEL = 'users.Base_User'
LOGIN_REDIRECT_URL = '/'
LANGUAGE_CODE = 'en-us' LANGUAGE_CODE = 'en-us'

View File

@ -15,6 +15,7 @@ Including another URLconf
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import path,include from django.urls import path,include
from users import views
from camper import views from camper import views
from reservation import views from reservation import views
from django.conf.urls.static import static from django.conf.urls.static import static
@ -25,6 +26,7 @@ from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path(r'',include('users.urls')),
path(r'', include('camper.urls')), path(r'', include('camper.urls')),
path(r'', include('reservation.urls')), path(r'', include('reservation.urls')),