Refractoring
This commit is contained in:
parent
652e3d50eb
commit
002aeff50a
@ -31,7 +31,7 @@ urlpatterns = [
|
||||
path('api/', include('roomservice.api.urls')),
|
||||
|
||||
# API Docs
|
||||
# path('api/docs/', include_docs_urls(title='Respool API Docs', public=True,
|
||||
# authentication_classes=[BasicAuthentication, ],
|
||||
# permission_classes=[AllowAny, ])),
|
||||
path('api/docs/', include_docs_urls(title='Respool API Docs', public=True,
|
||||
authentication_classes=[BasicAuthentication, ],
|
||||
permission_classes=[AllowAny, ])),
|
||||
]
|
||||
|
||||
@ -1,16 +1,18 @@
|
||||
from django.contrib import admin
|
||||
from .models import Staff, Room, RoomType, BookingGroup, Booking, Equipment, Location, Building, NumEquipment, \
|
||||
AccessPoint, Favorite
|
||||
from .models import Room, Building, RoomType, OrgUnit, Equipment, Staff, Lecture, LectureSpecifiaction, LectureType
|
||||
|
||||
# Register your models here.
|
||||
admin.site.register(Lecture)
|
||||
admin.site.register(LectureSpecifiaction)
|
||||
admin.site.register(LectureType)
|
||||
admin.site.register(Staff)
|
||||
admin.site.register(Room)
|
||||
admin.site.register(RoomType)
|
||||
admin.site.register(BookingGroup)
|
||||
admin.site.register(Booking)
|
||||
# admin.site.register(BookingGroup)
|
||||
# admin.site.register(Booking)
|
||||
admin.site.register(Equipment)
|
||||
admin.site.register(Location)
|
||||
admin.site.register(Building)
|
||||
admin.site.register(NumEquipment)
|
||||
admin.site.register(AccessPoint)
|
||||
admin.site.register(Favorite)
|
||||
# admin.site.register(NumEquipment)
|
||||
# admin.site.register(AccessPoint)
|
||||
# admin.site.register(Favorite)
|
||||
admin.site.register(OrgUnit)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
from roomservice.models import Booking, Room
|
||||
from roomservice.models import Room
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
@ -8,13 +8,13 @@ class RoomSerializer(serializers.HyperlinkedModelSerializer):
|
||||
fields = ('id',)
|
||||
|
||||
|
||||
class BookingSerializer(serializers.HyperlinkedModelSerializer):
|
||||
room = RoomSerializer(many=False, read_only=True)
|
||||
start_date = serializers.DateField(format='iso-8601')
|
||||
end_date = serializers.DateField(format='iso-8601')
|
||||
start_time = serializers.TimeField(format='iso-8601')
|
||||
end_time = serializers.TimeField(format='iso-8601')
|
||||
|
||||
class Meta:
|
||||
model = Booking
|
||||
fields = ('id', 'room', 'start_date', 'end_date', 'start_time', 'end_time')
|
||||
# class BookingSerializer(serializers.HyperlinkedModelSerializer):
|
||||
# room = RoomSerializer(many=False, read_only=True)
|
||||
# start_date = serializers.DateField(format='iso-8601')
|
||||
# end_date = serializers.DateField(format='iso-8601')
|
||||
# start_time = serializers.TimeField(format='iso-8601')
|
||||
# end_time = serializers.TimeField(format='iso-8601')
|
||||
#
|
||||
# class Meta:
|
||||
# model = Booking
|
||||
# fields = ('id', 'room', 'start_date', 'end_date', 'start_time', 'end_time')
|
||||
|
||||
@ -3,5 +3,5 @@ from . import views
|
||||
|
||||
app_name = 'roomservice.api'
|
||||
urlpatterns = [
|
||||
path('booking', views.ApiBooking.as_view(), name='api-booking'),
|
||||
# path('booking', views.ApiBooking.as_view(), name='api-booking'),
|
||||
]
|
||||
@ -1,21 +1,22 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from roomservice.models import Booking
|
||||
from roomservice.api.serializers import BookingSerializer
|
||||
# from roomservice.models import Booking
|
||||
# from roomservice.api.serializers import BookingSerializer
|
||||
|
||||
from rest_framework import generics
|
||||
from rest_framework.decorators import permission_classes
|
||||
from rest_framework.permissions import IsAuthenticated, AllowAny
|
||||
|
||||
|
||||
@permission_classes((AllowAny,))
|
||||
class ApiBooking(generics.ListAPIView):
|
||||
serializer_class = BookingSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = Booking.objects.all()
|
||||
roomId = self.request.query_params.get('room_id')
|
||||
|
||||
if roomId:
|
||||
queryset = queryset.filter(room=roomId)
|
||||
return queryset
|
||||
#
|
||||
# @permission_classes((AllowAny,))
|
||||
# class ApiBooking(generics.ListAPIView):
|
||||
# """Lists all Bookings"""
|
||||
# serializer_class = BookingSerializer
|
||||
#
|
||||
# def get_queryset(self):
|
||||
# queryset = Booking.objects.all()
|
||||
# roomId = self.request.query_params.get('room_id')
|
||||
#
|
||||
# if roomId:
|
||||
# queryset = queryset.filter(room=roomId)
|
||||
# return queryset
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
from django.db import models
|
||||
from .models import Favorite
|
||||
from django.forms import ModelForm
|
||||
|
||||
|
||||
class FavoriteForm(ModelForm):
|
||||
class Meta:
|
||||
model = Favorite
|
||||
fields = ['room']
|
||||
# from django.db import models
|
||||
# from .models import Favorite
|
||||
# from django.forms import ModelForm
|
||||
#
|
||||
#
|
||||
# class FavoriteForm(ModelForm):
|
||||
# class Meta:
|
||||
# model = Favorite
|
||||
# fields = ['room']
|
||||
|
||||
@ -63,7 +63,7 @@ class Room(models.Model):
|
||||
description = models.CharField(max_length=64, null=True, blank=True)
|
||||
equipment = models.ManyToManyField(Equipment)
|
||||
|
||||
orgname = models.ForeignKey(OrgUnit, on_delete=models.PROTECT, related_name='orgname', null=True, blank=True)
|
||||
orgname = models.ForeignKey(OrgUnit, on_delete=models.PROTECT, related_name='room_orgname', null=True, blank=True)
|
||||
orgunits = models.ManyToManyField(OrgUnit)
|
||||
|
||||
# seating = models.BooleanField()
|
||||
@ -89,8 +89,45 @@ class Room(models.Model):
|
||||
# def __str__(self):
|
||||
# return '{} - {} - {}'.format(self.room.room_number, self.equipment.name, self.count)
|
||||
#
|
||||
class Exclude_Term(models.Model):
|
||||
date = models.DateField()
|
||||
# class Exclude_Term(models.Model):
|
||||
# date = models.DateField()
|
||||
|
||||
class LectureSpecifiaction(models.Model):
|
||||
univis_id = models.CharField(max_length=8)
|
||||
name = models.CharField(max_length=32)
|
||||
|
||||
def __str__(self):
|
||||
return '{}'.format(self.univis_id)
|
||||
|
||||
|
||||
class LectureType(models.Model):
|
||||
name = models.CharField(max_length=32)
|
||||
|
||||
def __str__(self):
|
||||
return '{}'.format(self.name)
|
||||
|
||||
|
||||
class Lecture(models.Model):
|
||||
univis_id = models.IntegerField(unique=True)
|
||||
univis_key = models.CharField(unique=True, max_length=64)
|
||||
type = models.ForeignKey(LectureType, on_delete=models.PROTECT, null=True, blank=True)
|
||||
title = models.CharField(max_length=64)
|
||||
short = models.CharField(max_length=16, null=True, blank=True)
|
||||
ects = models.FloatField(null=True, blank=True)
|
||||
sws = models.FloatField(null=True, blank=True)
|
||||
estimated_visitor = models.PositiveIntegerField(null=True, blank=True)
|
||||
specification = models.ManyToManyField(LectureSpecifiaction)
|
||||
orgname = models.ForeignKey(OrgUnit, on_delete=models.PROTECT, related_name='lecture_orgname', null=True,
|
||||
blank=True)
|
||||
orgunits = models.ManyToManyField(OrgUnit)
|
||||
url_description = models.URLField(null=True, blank=True)
|
||||
|
||||
organizational = models.TextField(max_length=64, null=True, blank=True)
|
||||
time_description = models.TextField(max_length=64, null=True, blank=True)
|
||||
summary = models.TextField(max_length=64, null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return '{}'.format(self.title)
|
||||
|
||||
# class Lecture_Term(models.Model):
|
||||
# room = models.ForeignKey(Room, on_delete=models.CASCADE)
|
||||
|
||||
@ -3,8 +3,8 @@ from . import views
|
||||
|
||||
app_name = 'roomservice'
|
||||
urlpatterns = [
|
||||
path('', views.favorites, name='home'),
|
||||
path('favorite/', views.add_favorites, name='add-fav'),
|
||||
# path('', views.favorites, name='home'),
|
||||
# path('favorite/', views.add_favorites, name='add-fav'),
|
||||
|
||||
path('error/', views.error, name='error'),
|
||||
path('success/', views.success, name='success'),
|
||||
|
||||
0
roofis2/roomservice/utils/__init__.py
Normal file
0
roofis2/roomservice/utils/__init__.py
Normal file
66
roofis2/roomservice/utils/migrate_data_vgn_coords.py
Normal file
66
roofis2/roomservice/utils/migrate_data_vgn_coords.py
Normal file
@ -0,0 +1,66 @@
|
||||
from apps.donar.models import VGN_Coords
|
||||
|
||||
|
||||
def migrate():
|
||||
locations = []
|
||||
locations.append(
|
||||
{'location': 'Erba', 'vgn_key': 'coord%3A4418901%3A629758%3ANAV4%3ABamberg%2C An der Weberei 5',
|
||||
'lat': '49.90316',
|
||||
'lon': '10.86932'})
|
||||
locations.append(
|
||||
{'location': 'Feki', 'vgn_key': 'coord%3A4421412%3A629361%3ANAV4%3ABamberg%2C Feldkirchenstraße 21',
|
||||
'lat': '49,9070328',
|
||||
'lon': '10,9041714'})
|
||||
locations.append(
|
||||
{'location': 'Markushaus', 'vgn_key': 'coord%3A4419902%3A630599%3ANAV4%3ABamberg%2C Markusplatz 3',
|
||||
'lat': '49.89552',
|
||||
'lon': '10.88348'})
|
||||
locations.append(
|
||||
{'location': 'Austraße', 'vgn_key': 'coord%3A4420153%3A630781%3ANAV4%3ABamberg%2C An der Universität 7',
|
||||
'lat': '49.89411',
|
||||
'lon': '10.88726'})
|
||||
locations.append(
|
||||
{'location': 'Kranen', 'vgn_key': 'coord%3A4420141%3A630965%3ANAV4%3ABamberg%2C Am Kranen 10',
|
||||
'lat': '49.89259',
|
||||
'lon': '10.88701'})
|
||||
locations.append(
|
||||
{'location': 'Kärntenstr', 'vgn_key': 'coord%3A4421130%3A628738%3ANAV4%3ABamberg%2C Kärntenstraße 7',
|
||||
'lat': '49.91256',
|
||||
'lon': '10.90028'})
|
||||
locations.append(
|
||||
{'location': 'Kapellenstr', 'vgn_key': 'coord%3A4421682%3A631169%3ANAV4%3ABamberg%2C Kapellenstraße 13',
|
||||
'lat': '49.89063',
|
||||
'lon': '10.90846'})
|
||||
locations.append(
|
||||
{'location': 'Volkspark', 'vgn_key': 'coord%3A4423077%3A629976%3ANAV4%3ABamberg%2C Pödeldorfer Straße 180',
|
||||
'lat': '49.90087',
|
||||
'lon': '10.92998'})
|
||||
locations.append(
|
||||
{'location': 'K16', 'vgn_key': 'coord%3A4420069%3A630807%3ANAV4%3ABamberg%2C Kapuzinerstraße 16',
|
||||
'lat': '48.127',
|
||||
'lon': '11.5572'})
|
||||
locations.append(
|
||||
{'location': 'Zwinger', 'vgn_key': 'coord%3A4420461%3A631411%3ANAV4%3ABamberg%2C Am Zwinger 4',
|
||||
'lat': '49.88843',
|
||||
'lon': '10.8918'})
|
||||
locations.append(
|
||||
{'location': 'AULA', 'vgn_key': 'coord%3A4420062%3A631052%3ANAV4%3ABamberg%2C Dominikanerstraße 2',
|
||||
'lat': '49.89165',
|
||||
'lon': '10.88602'})
|
||||
locations.append(
|
||||
{'location': 'Fischstr', 'vgn_key': 'coord%3A4420141%3A630930%3ANAV4%3ABamberg%2C Fischstraße 5',
|
||||
'lat': '49.89277',
|
||||
'lon': '10.88717'})
|
||||
locations.append(
|
||||
{'location': 'Fleischstr', 'vgn_key': 'coord%3A4420204%3A630739%3ANAV4%3ABamberg%2C Fleischstraße 2',
|
||||
'lat': '49.89453',
|
||||
'lon': '10.88791'})
|
||||
for location in locations:
|
||||
location_obj, created = VGN_Coords.objects.get_or_create(name=location['location'], coords=location['vgn_key'],
|
||||
latitude=location['lat'], longitude=location['lon'])
|
||||
if not created:
|
||||
print("Duplicate! Start Update: " + location['location'])
|
||||
location_obj.name = location['location']
|
||||
location_obj.coords = location['vgn_key']
|
||||
location_obj.latitude = location['lat']
|
||||
location_obj.longitude = location['lon']
|
||||
@ -1,5 +1,5 @@
|
||||
from roomservice.models import Room, Favorite, Booking, Staff
|
||||
from .forms import FavoriteForm
|
||||
from roomservice.models import Room
|
||||
# from .forms import FavoriteForm
|
||||
from django.shortcuts import render
|
||||
from roomservice.models import Room
|
||||
import logging
|
||||
@ -17,30 +17,6 @@ def search(request):
|
||||
# logger.info(barrierfree)
|
||||
if search_token:
|
||||
rooms = rooms.filter(room_number__contains=search_token)
|
||||
# else:
|
||||
# # barrierfree = request.POST['barrierfree']
|
||||
#
|
||||
# if barrierfree:
|
||||
# # barrierfree = request.POST['barrierfree']
|
||||
# if barrierfree == 'on':
|
||||
# rooms = rooms.filter(barrierfree=True)
|
||||
#
|
||||
# if 'seating' in request.POST:
|
||||
# seating = request.POST['seating']
|
||||
# if seating == 'on':
|
||||
# rooms = rooms.filter(seating=True)
|
||||
#
|
||||
# if 'cooling' in request.POST:
|
||||
# cooling = request.POST['cooling']
|
||||
# if cooling == 'on':
|
||||
# rooms = rooms.filter(cooling=True)
|
||||
#
|
||||
# if 'capatacity' in request.POST:
|
||||
# capatacity = request.POST['capatacity']
|
||||
# if not capatacity == '-1':
|
||||
# rooms = rooms.filter(capacity__gte=capatacity)
|
||||
|
||||
# logger.info(search_token, barrierfree, seating, cooling, capatacity)
|
||||
|
||||
return render(request, 'search.jinja',
|
||||
{"title": "rooF(i)S is love rooF(i)S is live!!", "rooms": rooms, "result_count": rooms.count()})
|
||||
@ -56,29 +32,29 @@ def booking(request, id):
|
||||
def admin(request):
|
||||
return render(request, 'admin.jinja', {"title": "rooF(i)S is love rooF(i)S is live!!"})
|
||||
|
||||
|
||||
def favorites(request):
|
||||
if request.user.is_authenticated:
|
||||
favorites = Favorite.objects.filter(staff__user=request.user)
|
||||
return render(request, 'favorites.jinja',
|
||||
{"title": "rooF(i)S is love rooF(i)S is live!!", 'favorites': favorites})
|
||||
return render(request, 'favorites.jinja',
|
||||
{"title": "rooF(i)S is love rooF(i)S is live!!"})
|
||||
#
|
||||
# def favorites(request):
|
||||
# if request.user.is_authenticated:
|
||||
# favorites = Favorite.objects.filter(staff__user=request.user)
|
||||
# return render(request, 'favorites.jinja',
|
||||
# {"title": "rooF(i)S is love rooF(i)S is live!!", 'favorites': favorites})
|
||||
# return render(request, 'favorites.jinja',
|
||||
# {"title": "rooF(i)S is love rooF(i)S is live!!"})
|
||||
|
||||
|
||||
def add_favorites(request):
|
||||
if request.method == 'POST':
|
||||
form = FavoriteForm(request.POST)
|
||||
if form.is_valid():
|
||||
staff = Staff.objects.get(user=request.user)
|
||||
room = form.cleaned_data['room']
|
||||
Favorite.objects.create(staff=staff, room=room)
|
||||
return render(request, 'success.jinja', {})
|
||||
else:
|
||||
return render(request, 'error.jinja', {})
|
||||
else:
|
||||
form = FavoriteForm()
|
||||
return render(request, 'add_fav.jinja', {"title": "Add a new Favorite", 'form': form})
|
||||
# def add_favorites(request):
|
||||
# if request.method == 'POST':
|
||||
# form = FavoriteForm(request.POST)
|
||||
# if form.is_valid():
|
||||
# staff = Staff.objects.get(user=request.user)
|
||||
# room = form.cleaned_data['room']
|
||||
# Favorite.objects.create(staff=staff, room=room)
|
||||
# return render(request, 'success.jinja', {})
|
||||
# else:
|
||||
# return render(request, 'error.jinja', {})
|
||||
# else:
|
||||
# form = FavoriteForm()
|
||||
# return render(request, 'add_fav.jinja', {"title": "Add a new Favorite", 'form': form})
|
||||
|
||||
|
||||
def location_based_search(request):
|
||||
|
||||
@ -24,4 +24,31 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
{% macro home_item_with_icon_2(icon, icon_size='fa-4x', url_id='', payload='', link='', title='') -%}
|
||||
<div class="col-12 col-sm-6 col-lg-6 col-xl-6 p-3">
|
||||
<div class="card">
|
||||
{% if url_id %}
|
||||
<a href="{{ url(url_id, args=[payload]) }}">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title text-center"><i class="fa {{ icon }} {{ icon_size }}"
|
||||
aria-hidden="true"></i></h4>
|
||||
{% if title %}
|
||||
<p class="text-center">{{ title }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="{{ link }}">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title text-center"><i class="fa {{ icon }} {{ icon_size }}"
|
||||
aria-hidden="true"></i></h4>
|
||||
{% if title %}
|
||||
<p class="text-center">{{ title }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
@ -13,7 +13,7 @@
|
||||
{% if request.user.is_authenticated %}
|
||||
{% for favorite in favorites %}
|
||||
<div class="col-12 col-md-6">
|
||||
{{ macros.home_item_with_icon(icon='fa-star', icon_size='fa-4x', url_id='', link=favorite.room.id, title=favorite.room.room_number, attr='') }}
|
||||
{{ macros.home_item_with_icon_2(icon='fa-star', icon_size='fa-4x', url_id='roomservice:booking', payload=favorite.room.id, link=favorite.room.id, title=favorite.room.room_number) }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
<div class="col-12 col-md-6">
|
||||
|
||||
@ -83,7 +83,7 @@
|
||||
<p>Capacity: {{ room.capacity }} Persons</p>
|
||||
<p>Room type: {{ room.room_type.type }}</p></div>
|
||||
<a href="{{ url('roomservice:booking', args=[room.id]) }}" class="card-link">Detail</a>
|
||||
<a href="#" class="card-link">Another link</a>
|
||||
{# <a href="#" class="card-link">Another link</a>#}
|
||||
</div>
|
||||
</div>
|
||||
<p></p></br>
|
||||
|
||||
Reference in New Issue
Block a user