def display(request): """ Subpage to show all videos sorted into fitting era :param request: url request to get subpage /videos :return: rendering the subpage based on videos.html with a context variable to get Videos sorted in eras """ register_visit(request, "Videoseite") # pylint: disable = no-member eras = Era.objects.filter(visible_on_video_page=True).exclude( year_from=None) eras = sorted(eras, key=lambda er_a: er_a.get_year_as_signed_int()[0]) eras_context = [] # Add all eras that do not have a year_from # pylint: disable = no-member eras = eras + list( Era.objects.filter(year_from=None, visible_on_video_page=True)) i = 0 for i in range(len(eras)): # Era on the last position has no next color nextcolor = None if i != len(eras) - 1: nextcolor = eras[i + 1].color_code videos = Video.get_era(Video, eras[i].name) # alphanumeric sort of videos videos = sorted(videos, key=lambda v: v.title) eras_context.append((eras[i], videos, nextcolor)) context = { 'Era': eras_context, 'Kurs_Link': get_course_link(), 'announcements': get_announcements(), } return render(request, 'videos.html', context)
def start(request): """ Subpage start :param request: url request to get subpage /start :return: rendering the subpage based on start.html with a context variable to get the intro-video """ register_visit(request, "Introseite") texts = IntroTexts.objects.all() intro_text = "" timeline_card_text = "" buildings_card_text = "" video_card_text = "" if texts.first() is not None: intro_text = texts.first().intro_text timeline_card_text = texts.first().timeline_card_text buildings_card_text = texts.first().buildings_card_text video_card_text = texts.first().video_card_text video = Video.get_intro(Video) context = { 'Video': video, 'intro_text': intro_text, 'timeline_card_text': timeline_card_text, 'buildings_card_text': buildings_card_text, 'video_card_text': video_card_text, 'Kurs_Link': get_course_link(), 'announcements': get_announcements(), } return render(request, 'start.html', context)
def material(request): """ Subpage to show the characteristics of a building :param request: url request to get materials_page :return: rendering the subpage based on material.html with a context variable to get the characteristics """ register_visit(request, "Materialseite", alter_url="materials_page") # this code ist for adding colors to the materials # for visual difference, both colors will take turns colors = ["2F4B33", "B43B44"] materials = get_categories_and_corresponding_files() materials_with_colors = [] i = 0 for category in materials.keys(): color = None nextcolor = None if i % 2 == 0: color = colors[0] nextcolor = colors[1] else: color = colors[1] nextcolor = colors[0] materials_with_colors.append( [category, materials[category], color, nextcolor]) i += 1 context = { 'Materials': materials_with_colors, 'Kurs_Link': get_course_link(), 'announcements': get_announcements(), } return render(request, "material.html", context)
def impressum(request): """ Subpage to show the impressum and the moodle_link :param request: url request to get impressum :return: rendering the subpage based on impressum.html with a context variable to get the characteistics """ register_visit(request, "Impressum") context = { 'Kurs_Link': get_course_link(), 'announcements': get_announcements(), } return render(request, "impressum.html", context)
def search(request): """ Function to search in buildings :param request: url request to make a search with the search criteria :return: rendering the subpage based on search.html with context context: Variable to search all buildings with the criteria got from the request """ search_request = request.GET.get('search_request', '') results = Building.objects.filter(Q(name__icontains=search_request) | Q(city__icontains=search_request) | \ Q(region__icontains=search_request) | \ Q(country__icontains=search_request) | \ Q(era__name__icontains=search_request) | \ Q(architect__icontains=search_request) | \ Q(context__icontains=search_request) | \ Q(builder__icontains=search_request) | \ Q(construction_type__icontains=search_request) | \ Q(design__icontains=search_request) | \ Q(function__icontains=search_request) | \ Q(column_order__icontains=search_request) | \ Q(material__icontains=search_request) | \ Q(construction__icontains=search_request)) # order results alphabetically: results = results.order_by("name") # adding thumbnails: results = [(result, result.get_thumbnail()) for result in results] context = { 'Result': results, 'Active_Filter': request.GET, 'Kurs_Link': get_course_link(), 'announcements': get_announcements(), } # register visit for analytics search_term = search_request if len(search_term) >= 100: search_term = search_term[:95] + "..." register_visit(request, search_term) return render(request, 'search.html', context)
def timeline(request): """ Subpage "Zeitachse" :param request: url request to get subpage /timeline :return: rendering the subpage based on timeline.html """ register_visit(request, "Zeitachse") # get only buildings with dates set # pylint: disable = no-member buildings = Building.objects.all() # get historic dates (they must have a date (not nullable database field)) historic_dates = HistoricDate.objects.all() # Make lists from QuerySets # because otherwise pythons list concatenation and sorting will not work items = list(buildings) + list(historic_dates) context = { 'Eras_Buildings': sorted_eras_with_buildings(items), 'Kurs_Link': get_course_link(), 'announcements': get_announcements(), } return render(request, 'timeline.html', context)
def detailed(request, building_id): """ Subpage to show the characteristics of a building :param request: url request to get details_page :param building_id: id of the building to open the right detailed_page :return: rendering the subpage based on detailed.html with a context variable to get the characteristics """ context = { 'Name': Building.get_name(Building, building_id), 'Era': Building.get_era(Building, building_id), 'Beschreibung': Building.get_description(Building, building_id), 'Ort': Building.get_city(Building, building_id), 'Region': Building.get_region(Building, building_id), 'Land': Building.get_country(Building, building_id), 'Datum_von': Building.get_year_from(Building, building_id), 'Datum_von_BC_oder_AD': Building.get_year_from_bc_or_ad(Building, building_id), 'Datum_bis': Building.get_year_to(Building, building_id), 'Datum_bis_BC_oder_AD': Building.get_year_to_bc_or_ad(Building, building_id), 'Datum_ca': Building.get_year_ca(Building, building_id), 'Datum_Jahrhundert': Building.get_year_century(Building, building_id), 'Datum': Building.objects.get(pk=building_id).get_year_as_str(), 'Architekt': Building.get_architect(Building, building_id), 'Kontext_Lage': Building.get_context(Building, building_id), 'Bauherr': Building.get_builder(Building, building_id), 'Bautypus': Building.get_construction_type(Building, building_id), 'Bauform': Building.get_design(Building, building_id), 'Gattung_Funktion': Building.get_function(Building, building_id), 'Länge': Building.get_length(Building, building_id), 'Breite': Building.get_width(Building, building_id), 'Höhe': Building.get_height(Building, building_id), 'Umfang': Building.get_circumference(Building, building_id), 'Fläche': Building.get_area(Building, building_id), 'Säulenordung': Building.get_column_order(Building, building_id), 'Konstruktion': Building.get_construction(Building, building_id), 'Material': Building.get_material(Building, building_id), 'Literatur': Building.get_literature(Building, building_id), 'Links': Building.get_links(Building, building_id), 'Bilder': Picture.get_picture_for_building(Picture, building_id), 'Baupläne': Blueprint.get_blueprint_for_building(Blueprint, building_id), 'Videos': Timestamp.get_timestamps_by_building(Timestamp, building_id), 'Kurs_Link': get_course_link(), 'announcements': get_announcements(), } name = context["Name"] if len(name) > 80: name = name[:75] + "..." register_visit(request, name + "," + str(building_id), alter_url="details_page") return render(request, 'detailed.html', context)
def display_building_filter(request): # pylint: disable=too-many-locals """ Subpage "Gebäudefilter" with context :param request: url request to get subpage /filter :return: rendering the subpage based on filter.html with context context: Variable to filter all buildings with the criteria got from the request """ register_visit(request, "Filterseite") # We can filter by this options: # era, country, region, city, architect, builders, column_orders, designs, material, function keys = [ "era", "country", "region", "city", "architect", "builder", "column_order", "design", "material", "function" ] urls_parameters = request.GET # Set all, to return all. # This will take care of returning all Buildings, if no filter is set. # pylint: disable = no-member result = Building.objects.all() # If there is something set, it will start filtering here: for key in keys: if key in urls_parameters: # If here the key is in it, it will be filtered by. querys = urls_parameters.getlist(key) if len(querys) > 1: # Here it is an list with more than one element. # Therefore, we will not update data types. result_for_lst = None for query in querys: # There are more than one of this filter type (key): Use of OR on the results. # OR means we keep all filtering attributes, just discard duplications. # Therefore, we added up everything here, just need to check, # if there are duplications if result_for_lst is None: result_for_lst = my_filter(result, key, query) else: # This will add querysets to each other: # (Similar to SQL UNION Statement) result_for_lst = result_for_lst | my_filter( result, key, query) # Set it to the result. We had to work on a temporary var, otherwise # it would be impossible to use an OR logic (for AND it will be easier). result = result_for_lst elif len(querys) == 1 and querys[0] != "": # Here there is just one filter of its type. # Therefore we update datatype to string. query = querys[0] result = my_filter(result, key, query) else: # If length == 0: just pass pass # Different Key filters, will use AND on the results. # Will will archive this by just filtering on. # If the object meets all filters, it will be in the result. else: pass # Here we must take all of the objects in the list. # Theoretically we add everything here and do AND. # But this is unnecessary, because, we started with all() # order results alphabetically result = result.order_by("name") # Append Thumbnails result = [(res, res.get_thumbnail()) for res in result] filter_names = [ 'Stadt', 'Region', 'Land', 'Epoche', 'Architekt', 'Bauherr', 'Bauform', 'Säulenordnung', 'Material', 'Gattung/Funktion' ] # pylint: disable = no-member buildings = Building.objects.all() # pylint: disable = no-member eras = Era.objects.all().exclude(name=None).values('name').distinct() eras = delete_duplicates(splitting(one_dict_set_to_string_list(eras))) eras = sorted(eras, key=lambda x: x.lower()) countries = buildings.only('country').exclude( country=None).values('country').distinct() countries = delete_duplicates( splitting(one_dict_set_to_string_list(countries))) countries = sorted(countries, key=lambda x: x.lower()) regions = buildings.only('region').exclude( region=None).values('region').distinct() regions = delete_duplicates(splitting( one_dict_set_to_string_list(regions))) regions = sorted(regions, key=lambda x: x.lower()) cities = buildings.only('city').exclude( city=None).values('city').distinct() cities = delete_duplicates(splitting(one_dict_set_to_string_list(cities))) cities = sorted(cities, key=lambda x: x.lower()) architects = buildings.only('architect').exclude( architect=None).values('architect').distinct() architects = delete_duplicates( splitting(one_dict_set_to_string_list(architects))) architects = sorted(architects, key=lambda x: x.lower()) builders = buildings.only('builder').exclude( builder=None).values('builder').distinct() builders = delete_duplicates( splitting(one_dict_set_to_string_list(builders))) builders = sorted(builders, key=lambda x: x.lower()) column_orders = buildings.only('column_order').exclude( column_order=None).values('column_order').distinct() column_orders = delete_duplicates( splitting(one_dict_set_to_string_list(column_orders))) column_orders = sorted(column_orders, key=lambda x: x.lower()) designs = buildings.only('design').exclude( design=None).values('design').distinct() designs = delete_duplicates(splitting( one_dict_set_to_string_list(designs))) designs = sorted(designs, key=lambda x: x.lower()) material = buildings.only('material').exclude( material=None).values('material').distinct() material = delete_duplicates( splitting(one_dict_set_to_string_list(material))) material = sorted(material, key=lambda x: x.lower()) function = buildings.only('function').exclude( function=None).values('function').distinct() function = delete_duplicates( splitting(one_dict_set_to_string_list(function))) function = sorted(function, key=lambda x: x.lower()) context = { 'Cities': cities, 'Regions': regions, 'Countries': countries, 'Eras': eras, 'Architects': architects, 'Builders': builders, 'Designs': designs, 'Column_Orders': column_orders, 'Materials': material, 'Functions': function, 'Filter_Result': result, 'Filter_Names': filter_names, 'Active_Filter': dict(urls_parameters), 'Kurs_Link': get_course_link(), 'announcements': get_announcements(), } return render(request, 'filter.html', context)