def edit(request, order_id=None): context = get_base_context(request) context["add_poster_form"] = AddPosterForm() if order_id: poster = get_object_or_404(Poster, pk=order_id) else: poster = order_id selected_form = EditPosterForm if request.POST: if poster.title: selected_form = EditOtherForm form = selected_form(request.POST, instance=poster) if form.is_valid(): form.save() return HttpResponseRedirect("../detail/" + str(poster.id)) else: context["form"] = form context["poster"] = poster else: selected_form = EditPosterForm if poster.title: selected_form = EditOtherForm context["form"] = selected_form(instance=poster) context["poster"] = poster return render(request, "posters/dashboard/add.html", context)
def marks_edit(request, pk): if not has_access(request): raise PermissionDenied context = get_base_context(request) if request.method == "POST": mark = get_object_or_404(Mark, pk=pk) mark_form = MarkForm(request.POST, instance=mark) if not mark_form.is_valid(): messages.error(request, "Noen av de påkrevde feltene inneholder feil.") else: # Save the form data new_mark = mark_form.save() # Save the additional mark data new_mark.last_changed_by = request.user new_mark.last_changed_date = django.utils.timezone.now() new_mark.save() # Add news messages.success(request, "Prikken ble endret.") return redirect(marks_details, pk=new_mark.id) else: mark = get_object_or_404(Mark, pk=pk) context["form"] = MarkForm(instance=mark) return render(request, "marks/dashboard/marks_edit.html", context)
def index(request): """ Marks overview """ # Check access if not has_access(request): raise PermissionDenied # Get context context = get_base_context(request) # Find all marks and do additional fixes marks_collection = [] marks = Mark.objects.all().order_by("-added_date") for mark in marks: marks_temp = mark marks_temp.users_num = len(mark.given_to.all()) marks_temp.category_clean = mark.get_category_display() marks_collection.append(marks_temp) # Add collection to context context["marks"] = marks_collection # Render view return render(request, "marks/dashboard/index.html", context)
def detail(request, order_id=None): if not order_id: return HttpResponse(status=400) context = get_base_context(request) poster = get_object_or_404(Poster, pk=order_id) context['poster'] = poster if not has_view_perms(request.user, poster): raise PermissionDenied order_type = poster.order_type type_names = ("Plakat", "Bong", "Generell ") type_name = type_names[order_type - 1] context["order_type_name"] = type_name if request.method == 'POST': if not has_edit_perms(request.user, poster): raise PermissionDenied poster_status = request.POST.get('completed') if poster_status == 'true' or poster_status == 'false': poster.toggle_finished() return render(request, 'posters/dashboard/details.html', context)
def detail(request, pk): """ Detailed company view per PK """ if not has_access(request): raise PermissionDenied context = get_base_context(request) context['company'] = get_object_or_404(Company, pk=pk) if request.method == 'POST': company_form = CompanyForm(request.POST, instance=context['company']) if not company_form.is_valid(): messages.error(request, 'Noen av de påkrevde feltene inneholder feil.') else: company_form.save() messages.success(request, 'Bedriften ble oppdatert.') context['form'] = company_form else: context['form'] = CompanyForm(instance=context['company']) return render(request, 'company/dashboard/detail.html', context)
def app_details(request, app_pk): """ Viewcontroller for detailed view of a specific registered app :param request: Django request object :return: An HttpResponse """ _log = logging.getLogger('%s.%s' % (__name__, app_details.__name__)) # Force only the almighty dotKom to access this view if not request.user.is_superuser: raise PermissionDenied context = get_base_context(request) client = get_object_or_404(Client, pk=app_pk) context['app'] = client # If we have some action to perform if request.method == 'POST': if 'action' in request.POST: if request.POST['action'] == 'delete': app_id = context['app'].id app_name = context['app'].name context['app'].delete() _log.info('%s deleted external auth client %s (%d)' % (request.user, app_name, app_id)) messages.success(request, 'App-klienten ble slettet') return redirect(reverse('sso:index')) # Add the registered scopes for the client to the context as a list of scope:description tuples scopes_available = oauth2_settings.user_settings['SCOPES'] scopes = [(s, scopes_available[s]) for s in client.get_scopes()] context['scopes'] = scopes return render(request, 'sso/dashboard/app_details.html', context)
def new(request): """ Create new companyprofile """ if not has_access(request): raise PermissionDenied context = get_base_context(request) if request.method == 'POST': company_form = CompanyForm(request.POST) if not company_form.is_valid(): messages.error(request, 'Noen av de påkrevde feltene inneholder feil.') else: company_form.save() messages.success(request, 'Bedriften ble opprettet.') return redirect(index) context['form'] = company_form else: context['form'] = CompanyForm() return render(request, 'company/dashboard/new.html', context)
def index(request): # The group with members who should populate the dropdownlist group = Group.objects.get(name='proKom') users_to_populate = group.user_set.all() context = get_base_context(request) # View to show if user not in committee, but wanting to see own orders if not has_view_all_perms(request.user): context['your_orders'] = [ x for x in Poster.objects.filter(ordered_by=request.user) if request.user.has_perm('view_poster_order', x) ] return render(request, 'posters/dashboard/index.html', context) orders = Poster.objects.all() context['new_orders'] = orders.filter(assigned_to=None) context['active_orders'] = orders.filter(finished=False).exclude( assigned_to=None) context['old_orders'] = orders.filter(finished=True) context['workers'] = users_to_populate return render(request, 'posters/dashboard/index.html', context)
def details(request, item_pk): # Generic check to see if user has access to dashboard. (In Komiteer or superuser) if not has_access(request): raise PermissionDenied # Create the base context needed for the sidebar context = get_base_context(request) context['item'] = get_object_or_404(Item, pk=item_pk) if request.method == 'POST': if 'inventory.change_item' not in context['user_permissions']: raise PermissionDenied item_form = ItemForm(request.POST, instance=context['item']) if not item_form.is_valid(): messages.error(request, 'Noen av de påkrevde feltene inneholder feil.') else: item_form.save() messages.success(request, 'Varen ble oppdatert') context['form'] = item_form else: context['form'] = ItemForm(instance=context['item']) context['new_batch_form'] = BatchForm() context['batch_forms'] = [ (b.id, BatchForm(instance=b)) for b in Batch.objects.filter(item=context['item']) ] return render(request, 'inventory/dashboard/details.html', context)
def statistics(request): # if not has_access(request): # raise PermissionDenied context = get_base_context(request) return render(request, 'inventory/dashboard/statistics.html', context)
def new(request): if not has_access(request): raise PermissionDenied # Get base context context = get_base_context(request) if request.method == 'POST': inventory_form = ItemForm(request.POST) if not inventory_form.is_valid(): messages.error(request, 'Noen av de påkrevde feltene inneholder feil.') else: item = inventory_form.save() messages.success(request, 'Varen ble opprettet') return redirect(details, item.id) context['form'] = inventory_form else: context['form'] = ItemForm() return render(request, 'inventory/dashboard/new.html', context)
def category_details(request, category_pk): # Generic check to see if user has access to dashboard. (In Komiteer or superuser) if not has_access(request): raise PermissionDenied # Create the base context needed for the sidebar context = get_base_context(request) context['category'] = get_object_or_404(ItemCategory, pk=category_pk) if request.method == 'POST': form = CategoryForm(request.POST, instance=context['category']) if not form.is_valid(): messages.error(request, 'Noen av de påkrevde feltene inneholder feil.') else: form.save() messages.success(request, 'Kategorien ble oppdatert') return redirect(category_index) context['form'] = form else: context['form'] = CategoryForm(instance=context['category']) return render(request, 'inventory/dashboard/category_new.html', context)
def edit(request, order_id=None): context = get_base_context(request) context['add_poster_form'] = AddPosterForm() if order_id: poster = get_object_or_404(Poster, pk=order_id) else: poster = order_id if order_id and request.user != poster.ordered_by and 'proKom' not in request.user.groups.all( ): raise PermissionDenied selected_form = EditPosterForm if request.POST: if poster.title: selected_form = EditOtherForm form = selected_form(request.POST, instance=poster) if form.is_valid(): form.save() return HttpResponseRedirect("../detail/" + str(poster.id)) else: context["form"] = form context["poster"] = poster else: selected_form = EditPosterForm if poster.title: selected_form = EditOtherForm context["form"] = selected_form(instance=poster) context["poster"] = poster return render(request, 'posters/dashboard/add.html', context)
def detail(request, opportunity_id=None): logger = logging.getLogger(__name__) logger.debug('Editing careeropportunity with id: %s' % (opportunity_id)) if not has_access(request): raise PermissionDenied context = get_base_context(request) cop = None if opportunity_id: cop = get_object_or_404(CareerOpportunity, pk=opportunity_id) context['cop'] = cop context['form'] = AddCareerOpportunityForm(instance=cop) else: context['form'] = AddCareerOpportunityForm() if request.method == 'POST': if cop: form = AddCareerOpportunityForm(data=request.POST, instance=cop) else: form = AddCareerOpportunityForm(data=request.POST) if form.is_valid(): form.save() messages.success(request, 'La til ny karrieremulighet') return redirect(index) else: context['form'] = form messages.error( request, 'Skjemaet ble ikke korrekt utfylt. Se etter markerte felter for å se hva som gikk galt.' ) return render(request, 'careeropportunity/dashboard/detail.html', context)
def _create_details_context(request, event_id): """ Prepare a context to be shared for all detail views. """ event = get_object_or_404(Event, pk=event_id) # Start with adding base context and the event itself context = get_base_context(request) context["event"] = event # Add forms context["change_event_form"] = dashboard_forms.ChangeEventForm( instance=event) if event.is_attendance_event(): context[ "change_attendance_form"] = dashboard_forms.ChangeAttendanceEventForm( instance=event.attendance_event) if event.attendance_event.has_reservation: context[ "change_reservation_form"] = dashboard_forms.ChangeReservationForm( instance=event.attendance_event.reserved_seats) seats = event.attendance_event.reserved_seats.seats ReserveeFormSet = modelformset_factory( Reservee, max_num=seats, extra=seats, fields=["name", "note", "allergies"], ) context["change_reservees_formset"] = ReserveeFormSet( queryset=event.attendance_event.reserved_seats.reservees.all()) return context
def marks_new(request): if not has_access(request): raise PermissionDenied context = get_base_context(request) if request.method == "POST": mark_form = MarkForm(request.POST) if not mark_form.is_valid(): messages.error(request, "Noen av de påkrevde feltene inneholder feil.") else: # Save the form data new_mark = mark_form.save() # Save the additional mark data new_mark.given_by = request.user new_mark.last_changed_by = request.user new_mark.save() # Add news messages.success(request, "Prikken ble lagret.") return redirect(marks_details, pk=new_mark.id) else: context["form"] = MarkForm() return render(request, "marks/dashboard/marks_new.html", context)
def event_change_attendees(request, event_id, active_tab="attendees"): if not has_access(request): raise PermissionDenied context = _create_details_context(request, event_id) context["active_tab"] = "attendees" event = context["event"] if not event.is_attendance_event(): messages.error(request, _("Dette er ikke et påmeldingsarrangement.")) return redirect("dashboard_event_details_active", event_id=event.id, active_tab="details") # AJAX if request.method == "POST": if request.is_ajax and "action" in request.POST: if not event.is_attendance_event: return HttpResponse( _("Dette er ikke et påmeldingsarrangement."), status=400) return JsonResponse(event_ajax_handler(event, request)) # NON AJAX context = get_base_context(request) context["event"] = event context["active_tab"] = active_tab extras = {} if event.is_attendance_event() and event.attendance_event.extras: for extra in event.attendance_event.extras.all(): extras[extra] = { "type": extra, "attending": 0, "waits": 0, "allergics": [] } count_extras(extras, "attending", event.attendance_event.attending_attendees_qs) count_extras(extras, "waits", event.attendance_event.waitlist_qs) context["change_event_form"] = dashboard_forms.ChangeEventForm( instance=event) if event.is_attendance_event(): context[ "change_attendance_form"] = dashboard_forms.ChangeAttendanceEventForm( instance=event.attendance_event) prices = _payment_prices(event.attendance_event) context["payment_prices"] = prices[0] context["payment_price_summary"] = prices[1] context["extras"] = extras context["change_event_form"] = dashboard_forms.ChangeEventForm( instance=event) return render(request, "events/dashboard/details.html", context)
def index(request): if not has_access(request): raise PermissionDenied context = get_base_context(request) return render(request, "resourcecenter/dashboard/index.html", context)
def index(request): if not has_access(request): raise PermissionDenied context = get_base_context(request) return render(request, "hobbygroups/dashboard/index.html", context)
def attendee_details(request, attendee_id): context = get_base_context(request) attendee = get_object_or_404(Attendee, pk=attendee_id) context["attendee"] = attendee return render(request, "events/dashboard/attendee.html", context)
def article_detail(request, article_id): check_access_or_403(request) article = get_object_or_404(Article, pk=article_id) context = get_base_context(request) context["article"] = article return render(request, "article/dashboard/article_detail.html", context)
def discontinued(request): if not has_access(request): raise PermissionDenied # Create the base context needed for the sidebar context = get_base_context(request) # Select all items that are not available for purchase context["items"] = Item.objects.filter(available=False).order_by("name") return render(request, "inventory/dashboard/discontinued.html", context)
def members_new(request): """ Create new membership form and handling """ if not has_access(request): raise PermissionDenied context = get_base_context(request) return render(request, "auth/dashboard/members_new.html", context)
def members_new(request): """ Create new allowedusername form and handling """ if not has_access(request): raise PermissionDenied context = get_base_context(request) return render(request, 'auth/dashboard/members_new.html', context)
def index(request): """ This is the main dashboard view """ if not has_access(request): raise PermissionDenied context = get_base_context(request) return render(request, "dashboard/dashboard.html", context)
def index(request): # Generic check to see if user has access to dashboard. (In Komiteer or superuser) if not has_access(request): raise PermissionDenied # Create the base context needed for the sidebar context = get_base_context(request) context['items'] = Item.objects.all().order_by('name') return render(request, 'inventory/dashboard/index.html', context)
def index(request): # Generic check to see if user has access to dashboard. (Is staff or superuser) if not has_access(request): raise PermissionDenied # Create the base context needed for the sidebar context = get_base_context(request) # Select all items that are available for purchase context["items"] = Item.objects.filter(available=True).order_by("name") return render(request, "inventory/dashboard/index.html", context)
def category_index(request): # Generic check to see if user has access to dashboard. (Is staff or superuser) if not has_access(request): raise PermissionDenied # Create the base context needed for the sidebar context = get_base_context(request) context["categories"] = ItemCategory.objects.all() return render(request, "inventory/dashboard/category_index.html", context)
def past(request): if not has_access(request): raise PermissionDenied allowed_events = get_group_restricted_events(request.user, True) events = allowed_events.filter( event_start__lt=timezone.now().date()).order_by('-event_start') context = get_base_context(request) context['events'] = events return render(request, 'events/dashboard/index.html', context)
def index(request): """ This is the main companyprofile dashboard view """ if not has_access(request): raise PermissionDenied context = get_base_context(request) context['companies'] = Company.objects.all().order_by('name') return render(request, 'company/dashboard/index.html', context)