예제 #1
0
class ExhibitView(TemplateView):
    template_name = 'curator/exhibits.html'

    @method_decorator(group_required('Museum_team'))
    @method_decorator(login_required(login_url='/auth/login'))
    def get(self, request, *a, **ka):
        exhibits = get_exhibit()
        return render(request, self.template_name, exhibits)

    @method_decorator(group_required('Museum_team'))
    @method_decorator(login_required(login_url='/auth/login'))
    def post(self, request, *a, **ka):
        exhibit_id = request.POST.get('id_exhibit', None)
        delete = request.POST.get('delete', None)
        preview = request.POST.get('preview', None)

        if exhibit_id is not None:
            if delete in ['1']:
                delete_exhibit(exhibit_id)
            elif preview in ['1']:
                url = '/curator/exhibit-preview?id=' + exhibit_id
                return redirect(url)

        exhibitions = get_exhibit()

        return render(request, self.template_name, exhibitions)
예제 #2
0
class AddExhibitView(TemplateView):
    template_name = 'curator/add-exhibit.html'
    form = NewExhibitForm
    exhibit_type = ''

    @method_decorator(group_required('Museum_team'))
    @method_decorator(login_required(login_url='/auth/login'))
    def get(self, request, *a, **ka):
        form = self.form()
        parameters = {'form': form, 'exhibit_type': self.exhibit_type}

        return render(request, self.template_name, parameters)

    @method_decorator(group_required('Museum_team'))
    @method_decorator(login_required(login_url='/auth/login'))
    def post(self, request, *a, **ka):
        request_form = self.form(request.POST, request.FILES)
        args = {'exhibit_type': self.exhibit_type}

        if request_form.is_valid():
            request_form.save()
            args['success'] = 'success'
            request_form = self.form()

        args['form'] = request_form

        return render(request, self.template_name, args)
예제 #3
0
class SchedulingView(TemplateView):
    template_name = 'curator/scheduling.html'

    @method_decorator(login_required(login_url='/auth/login'))
    def get(self, request, *a, **ka):
        exhibitions = get_exhibitions()
        return render(request, self.template_name, exhibitions)

    @method_decorator(group_required('Scheduling_team'))
    @method_decorator(login_required(login_url='/auth/login'))
    def post(self, request, *a, **ka):
        change_status = request.POST.get('changing_status', None)
        exhibition_id = request.POST.get('id_exhibition', None)
        editing = request.POST.get('editing', None)
        deleting = request.POST.get('delete', None)

        if editing in ['1'] and exhibition_id is not None:
            return redirect('/curator/scheduling-exhibition?id=' +
                            exhibition_id)

        if change_status in ['1'] and exhibition_id is not None:
            exhibition = Exhibition.objects.get(id=exhibition_id)
            exhibition.status = not exhibition.status
            exhibition.save()

        if deleting in ['1'] and exhibition_id is not None:
            exhibition = Exhibition.objects.get(id=exhibition_id)
            delete_exhibition(exhibition)

        exhibitions = get_exhibitions()

        return render(request, self.template_name, exhibitions)
예제 #4
0
class OpinionDeleterView(TemplateView):
    @method_decorator(group_required('Opinion_team'))
    @method_decorator(login_required(login_url='/auth/login'))
    def get(self, request, *a, **ka):
        response = {'status': 409}
        if delete_timeout_opinions():
            response['status'] = 200

        return JsonResponse(response)
예제 #5
0
class NewResourcesView(TemplateView):
    template_name = 'curator/new-resource.html'

    @method_decorator(group_required('Resources_team'))
    @method_decorator(login_required(login_url='/auth/login'))
    def get(self, request, *a, **ka):
        parameters = {}
        form_type = request.GET.get('resource', None)
        if form_type:
            form = POSSIBLE_RESOURCE.get(form_type, None)

            if form is not None:
                form = form['form']()
            else:
                form = TemplateForm()

            parameters = {'form': form, 'resource': form_type}

        return render(request, self.template_name, parameters)

    @method_decorator(group_required('Resources_team'))
    @method_decorator(login_required(login_url='/auth/login'))
    def post(self, request, *a, **ka):
        request_form = TemplateForm(request.POST, request.FILES)
        args = {}

        form_type = request.GET.get('resource', None)
        if form_type:
            args['resource'] = form_type
            form_type = POSSIBLE_RESOURCE.get(form_type, None)

            if form_type is not None:
                request_form = form_type['form'](request.POST, request.FILES)

        if request_form.is_valid():
            request_form.save()
            return redirect('/curator/resources?success=true&resource='+args['resource'])

        args['form'] = request_form

        return render(request, self.template_name, args)
예제 #6
0
class PreviewExhibitView(TemplateView):
    @method_decorator(group_required('Museum_team'))
    @method_decorator(login_required(login_url='/auth/login'))
    def get(self, request, *a, **ka):
        exhibit_id = request.GET.get('id', None)

        if exhibit_id is None:
            return redirect('/curator')

        exhibit = get_exhibit_model(exhibit_id)
        template = MUSEUM_TYPES[exhibit.exhibit_type.name]['template']

        args = get_exhibit_data(exhibit_id)

        return render(request, template, args)
예제 #7
0
class SchedulingExhibitionView(TemplateView):
    template_name = 'curator/scheduling-exhibition.html'
    default_selector = {'options': []}

    def get_current_selector(self, exclude_elements=list()):
        current_selector = copy.deepcopy(self.default_selector)
        exhibits = get_exhibits_data(exclude_elements)
        for exhibit in exhibits:
            exhibit_template = {
                'value': exhibit['id'],
                'display': exhibit['name']
            }
            current_selector['options'].append(exhibit_template)
        return current_selector

    @method_decorator(group_required('Scheduling_team'))
    @method_decorator(login_required(login_url='/auth/login'))
    def get(self, request, *a, **ka):
        selector = {}
        editing_id = request.GET.get('id', None)

        if editing_id is not None:
            exhibition = Exhibition.objects.get(id=editing_id)
            exhibits = exhibition.exhibits.all()
            exhibit_array = []
            if len(exhibits) > 0:
                for exhibit in exhibits:
                    exhibit_template = {
                        'value': exhibit.id,
                        'display': exhibit.name
                    }
                    exhibit_array.append(exhibit_template)
            selector = self.get_current_selector(exhibits)
            selector['current_exhibition'] = {
                'id': editing_id,
                'name': exhibition.name,
                'exhibits': exhibit_array,
                'initial': exhibition.start_date,
                'end': exhibition.end_date
            }
        else:
            selector = self.get_current_selector()
        return render(request, self.template_name, selector)

    @method_decorator(group_required('Scheduling_team'))
    @method_decorator(login_required(login_url='/auth/login'))
    def post(self, request, *a, **ka):
        selector = self.get_current_selector()

        name = request.POST.get('name', None)
        exhibits = request.POST.getlist('exhibit', None)
        start_date = request.POST.get('initial', None)
        end_date = request.POST.get('end', None)

        id_editing = request.POST.get('id_exhibition', None)

        try:
            if start_date is not None:
                start_date = datetime.strptime(start_date, "%d/%m/%Y")
            if end_date is not None:
                end_date = datetime.strptime(end_date, "%d/%m/%Y")
            if end_date < start_date:
                raise ValueError('The end date is before the start date')
        except ValueError as err:
            selector['failure'] = True
            return render(request, self.template_name, selector)

        if name is not None \
                and exhibits is not None \
                and start_date is not None \
                and end_date is not None:
            if id_editing is not None:
                exhibition = Exhibition.objects.get(id=id_editing)
                exhibition_exhibits = exhibition.exhibits.all()
                for old_exhibit in exhibition_exhibits:
                    exhibition.exhibits.remove(old_exhibit)
            else:
                exhibition = Exhibition()
            exhibition.name = name
            exhibition.start_date = start_date
            exhibition.end_date = end_date

            exhibits_objects = list()
            for exhibit in exhibits:
                exhibits_objects.append(Exhibit.objects.get(id=exhibit))

            sid = transaction.savepoint()

            exhibition.save()

            try:
                for exhibit in exhibits_objects:
                    exhibition.exhibits.add(exhibit)
                exhibition.save()
                transaction.savepoint_commit(sid)
                if id_editing is not None:
                    selector[
                        'success'] = 'The exhibition was correctly edited.'
                else:
                    selector['success'] = 'The new exhibition was added.'
            except IntegrityError:
                transaction.savepoint_rollback(sid)
                selector['failure'] = True
        else:
            selector['failure'] = True
        return render(request, self.template_name, selector)
예제 #8
0
class ResourcesView(TemplateView):
    template_name = 'curator/resources/resources.html'
    selector = {'header': {'display': 'Models, Music, Images, etc:',
                           'selected': 'selected'}, 'options': []}
    for resource in POSSIBLE_RESOURCE:
        resource = POSSIBLE_RESOURCE[resource]
        local_dict = {'value': resource['name'],
                      'display': resource['name'],
                      'selected': ''}
        selector['options'].append(local_dict)

    def selector_current(self, specific_resource):

        specific_selector = copy.deepcopy(self.selector)
        specific_template = self.template_name

        if specific_resource:
            specific_selector['header']['selected'] = ''
            specific_template = POSSIBLE_RESOURCE.get(specific_resource, None)

            if specific_template is not None:
                specific_template = specific_template['template']
                for option in specific_selector['options']:
                    if option['value'] == specific_resource:
                        option['selected'] = 'selected'
        return specific_selector, specific_template

    @method_decorator(group_required('Resources_team'))
    @method_decorator(login_required(login_url='/auth/login'))
    def get(self, request, *a, **ka):
        specific_resource = request.GET.get('resource', None)
        specific_selector, specific_template = self.selector_current(specific_resource)

        if specific_resource is not None:
            specific_selector['current_selection'] = specific_resource

        resource_list = POSSIBLE_RESOURCE.get(specific_resource, None)

        if resource_list is not None:
            resource_list = resource_list['elements']()
            specific_selector['elements'] = resource_list

        success = request.GET.get('success', None)
        if success is not None and success == 'true':
            specific_selector['success'] = True

        return render(request, specific_template, specific_selector)

    @method_decorator(group_required('Resources_team'))
    @method_decorator(login_required(login_url='/auth/login'))
    def post(self, request, *a, **ka):

        specific_resource = request.POST.get('resource', None)
        new = request.POST.get('new-resource', None)
        delete_resource = request.POST.get('delete', '0')
        specific_selector, specific_template = self.selector_current(specific_resource)

        if delete_resource not in ['0']:
            try:
                deleter = POSSIBLE_RESOURCE[specific_resource]['delete']
                deleter(delete_resource)
                specific_selector['success_delete'] = True
            except IOError:
                specific_selector['error'] = 'True'

        resource_list = POSSIBLE_RESOURCE.get(specific_resource, None)

        if specific_resource is not None:
            specific_selector['current_selection'] = specific_resource

        if resource_list is not None:
            resource_list = resource_list['elements']()
            specific_selector['elements'] = resource_list

        if new in ['1']:
            url = '/curator/new-resources?resource='+specific_resource
            return redirect(url)

        return render(request, specific_template, specific_selector)
예제 #9
0
class OpinionsView(TemplateView):
    template_name = 'curator/opinions.html'
    selector = {
        'header': {
            'display': 'Select a Exhibit from the list:',
            'selected': 'selected'
        },
        'options': [],
        'approved': '',
        'pending': ''
    }

    def get_current_selector(self):
        current_selector = copy.deepcopy(self.selector)
        exhibits = get_exhibits_data()
        for exhibit in exhibits:
            exhibit_template = {
                'id': exhibit['id'],
                'display': exhibit['name'],
                'selected': ''
            }
            current_selector['options'].append(exhibit_template)
        return current_selector

    @method_decorator(group_required('Opinion_team'))
    @method_decorator(login_required(login_url='/auth/login'))
    def get(self, request, *a, **ka):
        current_selector = self.get_current_selector()
        return render(request, self.template_name, current_selector)

    @method_decorator(group_required('Opinion_team'))
    @method_decorator(login_required(login_url='/auth/login'))
    def post(self, request, *a, **ka):
        current_selector = self.get_current_selector()

        current_exhibit = request.POST.get('exhibit', None)
        checkbox_approved = request.POST.get('approved', None)
        checkbox_pending = request.POST.get('pending', None)
        opinion_id = request.POST.get('id_opinion', None)

        reverse_option = request.POST.get('reverse', None)
        delete_option = request.POST.get('delete', None)

        if reverse_option is not None and reverse_option in ['1']:
            reverse_opinion_status(opinion_id)

        elif delete_option is not None and delete_option in ['1']:
            delete_opinion(opinion_id)

        approved = False
        pending = False

        if checkbox_approved is not None:
            current_selector['approved'] = 'checked'
            approved = True
        if checkbox_pending is not None:
            current_selector['pending'] = 'checked'
            pending = True

        if current_exhibit is not None:
            current_selector['current_exhibit'] = current_exhibit
            current_selector['header']['selected'] = ''
            for option in current_selector['options']:
                if option['id'] == int(current_exhibit):
                    option['selected'] = 'selected'
                    break

            opinions = query_opinion(current_exhibit, approved, pending)
            current_selector['opinions'] = opinions

        return render(request, self.template_name, current_selector)