Update file

This commit is contained in:
Krzysztof Bonecki 2021-01-17 17:10:04 +01:00
parent 76acafa1b9
commit 70a86ca352
3688 changed files with 7463 additions and 137547 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -3,4 +3,6 @@ Pillow==8.0.1
django-address==0.2.5
mysqlclient==2.0.1
sqlparse==0.4.1
phonenumbers==8.12.13
phonenumbers==8.12.13
django_extensions==3.1.0
django-phonenumber-field==5.0.0

BIN
vagus/.DS_Store vendored

Binary file not shown.

3
vagus/.bashrc_profile Normal file
View File

@ -0,0 +1,3 @@
alias pyrun = 'python manage.py runserver'
alias sudokill = 'sudo lsof -t -i tcp:8000 | xargs kill -9'

View File

@ -1,16 +1,21 @@
from django.contrib import admin
from .models import Offer, Offer_Category, Image_offer
from reservation.models import Reservation
# Register your models here.
class OfferALlDetail(admin.StackedInline):
class ReservationOfferDetail(admin.TabularInline):
model = Reservation
can_delete = False
verbose_name = 'Rezerwację'
class OfferALlDetail(admin.TabularInline):
model = Image_offer
can_delete = True
verbose_name = 'Image'
class OfferAdmin(admin.ModelAdmin):
model = Offer
inlines = [OfferALlDetail]
list_display = ('id','title','category','date_added','status',)
inlines = [OfferALlDetail,ReservationOfferDetail]
list_display = ('id','title','category','date_added','status','slug')
order = 'date_added'
admin.site.register(Offer,OfferAdmin)

View File

@ -12,8 +12,9 @@ class OfferCreateForm(forms.ModelForm):
class OfferImageCreateForm(forms.ModelForm):
image = forms.ImageField()
class Meta:
model = Image_offer
fields = ('image','main_image')
OfferImageFormSet = formset_factory(OfferImageCreateForm, extra = 5, max_num = 5)
OfferImageFormSet = formset_factory(OfferImageCreateForm, extra = 2, max_num = 2)

View File

@ -1,27 +0,0 @@
if check_user_is_owner(request) == True or request.user.is_staff == True:
if request.method == 'POST':
form = OfferCreateForm(request.POST)
formset = OfferImageFormSet(request.POST, request.FILES)
if form.is_valid() and formset.is_valid():
offer = form.save(commit = False)
offer.created_by = request.user
offer.status = 'Verification'
offer.save()
for photo in formset:
imageoffer = photo.save(commit = False)
imageoffer.user = request.user
imageoffer.offer = offer
imageoffer.save()
messages.success(request,'Oferta utworzona i przesłana do weryfikacji')
return HttpResponseRedirect('/')
else:
messages.warning(request, 'Wprowadzone dane są nieprawidłowe.')
return render(request,'offer/offer.html', {'form': form, 'formset': formset} )
else:
messages.warning(request,'Spróbuj ponownie później!')
return redirect("/")
else:
messages.error(request, 'Nie masz uprawnień!')
return HttpResponseRedirect('/')

View File

@ -1,4 +1,4 @@
# Generated by Django 3.1.3 on 2021-01-07 21:01
# Generated by Django 3.1.3 on 2021-01-12 17:44
import camper.models
from django.conf import settings
@ -15,6 +15,12 @@ class Migration(migrations.Migration):
]
operations = [
migrations.CreateModel(
name='AlbumImage',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
],
),
migrations.CreateModel(
name='Offer_Category',
fields=[
@ -33,6 +39,7 @@ class Migration(migrations.Migration):
('date_added', models.DateTimeField(auto_now_add=True)),
('status', models.CharField(choices=[('Active', 'Active offer'), ('Inactive', 'Inactive offer'), ('Verification', 'Waiting for verication'), ('Blocked', 'Blocked Offer')], default='Inactive', max_length=32)),
('title', models.CharField(default='Tytuł oferty', max_length=50, verbose_name='Title')),
('slug', models.SlugField(default='', editable=False, max_length=70, unique=True)),
('price', models.DecimalField(decimal_places=2, max_digits=10)),
('DMC', models.CharField(choices=[('B', 'Do 3.5 tony.'), ('C', 'Między 3.5 a 7.5 tony'), ('C1', 'Powyzej 7.5 tony')], default='B', max_length=32)),
('Places_to_sleep', models.IntegerField(default=2)),
@ -46,9 +53,14 @@ class Migration(migrations.Migration):
('photovoltaic_panels', models.BooleanField(default=False)),
('gearbox', models.CharField(choices=[('Manual', 'Skrzynia manualna'), ('Automat', 'Skrzynia automatyczna')], default='Manual', max_length=32)),
('tempomat', models.BooleanField(default=False)),
('album', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='album', to='camper.albumimage', verbose_name='')),
('category', models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to='camper.offer_category')),
('created_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'Offer',
'verbose_name_plural': 'Offers',
},
),
migrations.CreateModel(
name='Image_offer',
@ -56,8 +68,7 @@ class Migration(migrations.Migration):
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('image', models.ImageField(blank=True, null=True, upload_to=camper.models._upload_path)),
('main_image', models.BooleanField(default=False)),
('offer', models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to='camper.offer', verbose_name='')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
('offer', models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, related_name='images', to='camper.offer', verbose_name='')),
],
),
migrations.CreateModel(

View File

@ -0,0 +1,20 @@
# Generated by Django 3.1.3 on 2021-01-12 17:48
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('camper', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='offer',
name='album',
),
migrations.DeleteModel(
name='AlbumImage',
),
]

View File

@ -4,20 +4,11 @@ from django.urls import reverse
from users.models import Base_User
import users
from django.conf import settings
from django.template.defaultfilters import slugify
from django import template
register = template.Library()
class Offer_Category(models.Model):
id = models.AutoField(primary_key= True)
name = models.CharField(max_length=50)
class Meta:
verbose_name = 'Category'
verbose_name_plural = 'Categories'
def __str__(self):
return self.name
STATUS = (
('Active',_('Active offer')),
('Inactive',_('Inactive offer')),
@ -41,6 +32,19 @@ GEARBOX_Option = (
('Manual',_('Skrzynia manualna')),
('Automat',_('Skrzynia automatyczna')),
)
class Offer_Category(models.Model):
id = models.AutoField(primary_key= True)
name = models.CharField(max_length=50)
class Meta:
verbose_name = 'Category'
verbose_name_plural = 'Categories'
def __str__(self):
return self.name
class Offer(models.Model):
id = models.AutoField(primary_key= True)
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
@ -48,6 +52,8 @@ class Offer(models.Model):
status = models.CharField(max_length=32, choices=STATUS, default='Inactive')
title = models.CharField(_("Title"), max_length=50,default='Tytuł oferty')
slug = models.SlugField(max_length=70, editable = False,default='' , unique=True,)
category = models.ForeignKey(Offer_Category ,default= None,on_delete= models.CASCADE)
price = models.DecimalField(max_digits=10, decimal_places=2)
DMC = models.CharField(max_length=32, choices=DMC_Value, default='B')
@ -66,32 +72,33 @@ class Offer(models.Model):
tempomat = models.BooleanField(default=False)
class Meta:
pass
verbose_name = 'Offer'
verbose_name_plural = 'Offers'
def __str__(self):
return self.id
return self.title
def save(self,*args,**kwargs):
super(Offer, self).save(*args,**kwargs)
self.slug = slugify(f'{self.title}-{self.id}')
return super(Offer, self).save(*args, **kwargs)
def get_absolute_url(self):
return reverse('offer_detail', kwargs = {'pk': self.id })
return reverse('detail_offer_page', kwargs = {'slug': self.slug })
def _upload_path(instance,filename):
return instance.get_upload_path(filename)
class Image_offer(models.Model):
offer = models.ForeignKey("Offer", verbose_name="", on_delete = models.CASCADE, default=None)
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
offer = models.ForeignKey("Offer", verbose_name="", on_delete = models.CASCADE, default=None, related_name='images')
image = models.ImageField(upload_to=_upload_path, null = True, blank = True)
main_image = models.BooleanField(default= False)
def get_upload_path(self,filename):
return "uploads/user/id-"+str(self.user.id)+"/"+str(self.offer.id) + "/" +filename
def get_absolute_url(self):
return reverse("model_detail", kwargs={"pk": self.pk})
return "uploads/offer-images"+ "/" + 'id-'+str(self.offer.id) + "/" +filename
class Favourite_Offers(models.Model):
user = models.ForeignKey('users.Base_User', on_delete=models.CASCADE,)
offer = models.ForeignKey('Offer', on_delete=models.SET_NULL, null = True)

View File

@ -7,7 +7,7 @@ from django.conf.urls.static import static
urlpatterns = [
re_path('add-offer/', views.CreateOffer.as_view(), name='create_offer'),
path('offer/<int:pk>', views.OfferDetailView.as_view(), name = 'offer_detail'),
#path('offer/<slug:slug>', views.OfferDetailView.as_view(), name = 'offer_detail_view'),
path('offers/', views.OfferListView.as_view(), name = 'list_offers'),
path('', views.Home.as_view(), name='homepage')

View File

@ -1,3 +1,3 @@
from .offer_create_and_edit import *
from .offer_detail import *
from .offer_stats import *
from .create_offer import *
from .detail_page import *
from .statistic_offer import *

View File

@ -0,0 +1,90 @@
from django.shortcuts import render,redirect,get_object_or_404
from camper.models import Offer,Offer_Category,Image_offer
from users.models import Base_User
from django.views.generic import (
CreateView,
UpdateView,
DeleteView,
)
from camper.forms import OfferCreateForm,OfferImageCreateForm,OfferImageFormSet
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.contrib import messages
from django.http import HttpResponseRedirect
import users
def check_user_is_auth(request):
if request.users.Base_user.is_authenticated():
return True
else:
render (request,'signup.html')
def check_user_is_owner(request):
if check_user_is_auth == True:
if request.users.Base_user.status =="Company_Account": # check if user has status 'owner':
pass
else:
render (request,'upgrade-to-onwer.html')
#def check_offer_belong_to_user(request):
# if request.check_user_is_owner() == True:
# if offer.author == request.users.id:
# return True
# else:
# raise ValueError("To chyba nie twoje :)")
# if check_users_is_owner == True:
# Create your views here.
class CreateOffer(CreateView):
@method_decorator(login_required)
def get(self, request,*args,**kwargs):
form = OfferCreateForm()
formset = OfferImageFormSet()
context = {
'form': form,
'formset': formset,
}
#if check_user_is_owner(request) == True or request.Base_user.is_staff == True:
return render(request,'offer/add-offer.html', context)
@method_decorator(login_required)
def post(self,request,*args,**kwargs):
if check_user_is_owner(request) == True or request.user.is_staff == True:
if request.method == 'POST':
form = OfferCreateForm(request.POST)
formset = OfferImageFormSet(request.POST or None, request.FILES or None)
if form.is_valid() and formset.is_valid():
offer = form.save(commit = False)
offer.created_by = request.user
offer.status = 'Verification'
offer.save()
for photo in formset:
try:
imageoffer = Image_offer(offer = offer,main_image = photo.cleaned_data['main_image'],image = photo.cleaned_data['image'])
imageoffer.save()
except Exception:
offer.status = 'Inactive'
offer.save()
messages.success(request,'Dodaj zdjęcia aby przesłać ofertę do weryfikacji')
return redirect('/') #Redirect to offer page or user's offers list
messages.success(request,'Oferta utworzona i przesłana do weryfikacji')
return redirect('/') #Redirect to offer page or user's offers list
else:
messages.warning(request, 'Wprowadzone dane są nieprawidłowe.')
return render(request,'offer/add-offer.html', {'form': form, 'formset': formset} )
else:
form = OfferCreateForm()
formset = OfferImageFormSet()
return render(request,'offer/add-offer.html', {'form': form, 'formset': formset} )
else:
messages.error(request, 'Nie masz uprawnień!')
return redirect('/') #Redirect to login / register page for owner

View File

@ -0,0 +1,31 @@
from django.shortcuts import render,redirect, get_object_or_404
from django.views.generic import (
ListView,
DetailView,
View
)
from camper.models import Offer, Image_offer
from django.http import Http404, HttpResponseRedirect
class Home(View):
def get(self, request, *args, **kwargs):
return render(request, 'index.html')
class OfferDetailView(DetailView):
template_name = 'offer/offer-detail.html'
model = Offer
context_object_name = 'offer'
class OfferListView(ListView):
model = Offer
template_name = 'offer/offers.html'
context_object_name = 'active_offers_list'
def get_queryset(self):
return Offer.objects.filter(status = 'Active')
#def book_detail_view(request, primary_key):
# book = get_object_or_404(Book, pk=primary_key)
# return render(request, 'catalog/book_detail.html', context={'book': book})

View File

@ -1,82 +0,0 @@
from django.shortcuts import render,redirect,get_object_or_404
from camper.models import Offer,Offer_Category,Image_offer
from users.models import Base_User
from django.views.generic import (
CreateView,
UpdateView,
DeleteView,
)
from camper.forms import OfferCreateForm,OfferImageCreateForm,OfferImageFormSet
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.contrib import messages
from django.http import HttpResponseRedirect
import users
def check_user_is_auth(request):
if request.users.Base_user.is_authenticated():
return True
else:
render (request,'signup.html')
def check_user_is_owner(request):
if check_user_is_auth == True:
if request.users.Base_user.status =="Company_Account": # check if user has status 'owner':
pass
else:
render (request,'upgrade-to-onwer.html')
#def check_offer_belong_to_user(request):
# if request.check_user_is_owner() == True:
# if offer.author == request.users.id:
# return True
# else:
# raise ValueError("To chyba nie twoje :)")
# if check_users_is_owner == True:
# Create your views here.
class CreateOffer(CreateView):
@method_decorator(login_required)
def get(self, request,*args,**kwargs):
form = OfferCreateForm()
formset = OfferImageFormSet()
context = {
'form': form,
'formset': formset,
}
#if check_user_is_owner(request) == True or request.Base_user.is_staff == True:
return render(request,'offer/add-offer.html', context)
@method_decorator(login_required)
def post(self,request,*args,**kwargs):
if check_user_is_owner(request) == True or request.user.is_staff == True:
if request.method == 'POST':
form = OfferCreateForm(request.POST)
formset = OfferImageFormSet(request.POST, request.FILES)
if form.is_valid() and formset.is_valid():
offer = form.save(commit = False)
offer.created_by = request.user
offer.status = 'Verification'
offer.save()
for photo in formset:
imageoffer = photo.save(commit = False)
imageoffer.user = request.user
imageoffer.offer = offer
imageoffer.save()
messages.success(request,'Oferta utworzona i przesłana do weryfikacji')
return HttpResponseRedirect('/')
else:
messages.warning(request, 'Wprowadzone dane są nieprawidłowe.')
return render(request,'offer/add-offer.html', {'form': form, 'formset': formset} )
else:
messages.warning(request,'Spróbuj ponownie później!')
return redirect("/")
else:
messages.error(request, 'Nie masz uprawnień!')
return HttpResponseRedirect('/')

View File

@ -1,31 +0,0 @@
from django.shortcuts import render,redirect, get_object_or_404
from django.views.generic import (
ListView,
DetailView,
View
)
from camper.models import Offer, Image_offer
from django.http import Http404, HttpResponseRedirect
class Home(View):
def get(self, request, *args, **kwargs):
return render(request, 'index.html')
class OfferDetailView(DetailView):
template_name = 'offer/offer-detail.html'
model = Offer
#def get_context_data(self, **kwargs):
#context = super(OfferDetailView,self).get_context_data(**kwargs)
#context["images"] = self.queryset
#return context
class OfferListView(ListView):
model = Offer
template_name = 'offer/offers.html'
def get_queryset(self):
return Offer.objects.filter(status = 'Active')

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 385 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 385 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,11 @@
from django.contrib import admin
from .models import Reservation
from .forms import ReservationForm
class ReservationAdmin(admin.ModelAdmin):
list_display = ('__str__','offer','status')
ordering = ['reservation_start_date']
group_by = ['offer','user']
admin.site.register(Reservation, ReservationAdmin)

Some files were not shown because too many files have changed in this diff Show More