def get_success_url(self): action = Action(user=self.request.user, timestamp=timezone.now(), target=str(self.object)) if self.object.is_default: action.action = "edited built-in email template" else: action.action = "edited email template" action.save() return reverse_lazy('notifications')
def get_success_url(self): action = Action(user=self.request.user, timestamp=timezone.now(), target=str(self.object)) self.object = get_object_or_404(EventCategory, pk=self.kwargs.get('pk')) if self.object.is_default: action.action = "edited built-in event category" else: action.action = "edited event category" action.save() return reverse_lazy('eventcategories')
def set_as_admin(request, pk): user = get_object_or_404(User, pk=pk) if request.user.is_superuser: user.is_staff = True user.is_admin = True user.is_superuser = True try: user_data = user.userdata except UserData.DoesNotExist: user_data = UserData() user_data.user = user user_data.save() old_role = user_data.role user_data.role = "admin" user.is_staff = True user.is_superuser = True user_data.save() user.save() action = Action(user=request.user, target=str(user)) action.action = "set user as admin" action.timestamp = timezone.now() action.save() Cruise.objects.filter(leader=user).update( missing_information_cache_outdated=True) messages.add_message(request, messages.WARNING, mark_safe('User ' + str(user) + ' set as admin.')) if old_role == "": send_user_approval_email(request, user) else: raise PermissionDenied return redirect(request.META['HTTP_REFERER'])
def get_success_url(self): action = Action(user=self.request.user, timestamp=timezone.now(), target=str(self.object)) action.action = "deleted announcement" action.save() return reverse_lazy('announcements')
def mark_invoice_as_finalized(request, pk): invoice = get_object_or_404(InvoiceInformation, pk=pk) if (request.user.is_superuser): invoice.is_finalized = True invoice.save() action = Action(user=request.user, target=str(invoice)) action.action = "marked invoice as finalized" action.timestamp = timezone.now() action.save() messages.add_message( request, messages.SUCCESS, mark_safe( 'Invoice "' + str(invoice) + '" marked as finalized. It is now viewable by invoicers.')) invoicer_user_emails = [ invoice_user.email for invoice_user in list( User.objects.filter(userdata__role='invoicer')) ] send_template_only_email( invoicer_user_emails, EmailTemplate.objects.get(title='New invoice ready'), invoice=invoice) else: raise PermissionDenied return redirect(request.META['HTTP_REFERER'])
def form_valid(self, form): action = Action(user=self.request.user, timestamp=timezone.now(), target=form.instance) action.action = "updated invoice " + str(form.instance) action.save() return super(EditStandaloneInvoice, self).form_valid(form)
def create_additional_cruise_invoice(request, pk): if request.user.is_superuser: cruise = get_object_or_404(Cruise, pk=pk) invoice = cruise.get_invoice_info() if not invoice: invoice = InvoiceInformation() invoice.pk = None invoice.is_cruise_invoice = False invoice.title = 'Invoice for ' + str(cruise) invoice.is_finalized = False invoice.is_sent = False invoice.send_date = None invoice.is_paid = False invoice.paid_date = None invoice.save() action = Action(user=request.user, timestamp=timezone.now(), target=str(cruise)) action.action = "added an additional invoice to the cruise" action.save() Cruise.objects.filter(leader=request.user).update( missing_information_cache_outdated=True) messages.add_message(request, messages.SUCCESS, mark_safe('Additional invoice created.')) else: raise PermissionDenied try: return redirect(request.META['HTTP_REFERER']) except KeyError: return reverse_lazy('admin_invoices')
def get_success_url(self): action = Action(user=self.request.user, timestamp=timezone.now(), target=str(self.object)) action.action = "edited notification" action.save() return reverse_lazy('notifications')
def log_hijack_ended(sender, hijacker_id, hijacked_id, request, **kwargs): user = User.objects.get(id=hijacker_id) target_user = User.objects.get(id=hijacked_id) action = Action(user=user, target=str(target_user)) action.action = "released control of user" action.timestamp = timezone.now() action.save()
def get_success_url(self): action = Action(user=self.request.user, timestamp=timezone.now(), target=str(self.object)) action.action = "reset email template to default" action.save() return reverse_lazy('notifications')
def get_success_url(self): action = Action(user=self.request.user, timestamp=timezone.now(), target=str(self.object)) action.action = "deleted event category" action.save() return reverse_lazy('eventcategories')
def reject_invoice(request, pk): invoice = get_object_or_404(InvoiceInformation, pk=pk) if request.user.userdata.role == "invoicer": #message message = "" try: json_data = json.loads(request.body.decode("utf-8")) message = json_data["message"] except: message = "" #end message invoice.is_finalized = False invoice.is_sent = False invoice.is_paid = False invoice.rejection_message = message invoice.save() action = Action(user=request.user, target=str(invoice)) action.action = "rejected invoice" action.timestamp = timezone.now() action.save() messages.add_message( request, messages.SUCCESS, mark_safe('Invoice "' + str(invoice) + '" rejected.')) admin_user_emails = [ admin_user.email for admin_user in list(User.objects.filter(userdata__role='admin')) ] send_template_only_email( admin_user_emails, EmailTemplate.objects.get(title='Invoice rejected'), invoice=invoice) else: raise PermissionDenied return JsonResponse(json.dumps([], ensure_ascii=True), safe=False)
def form_valid(self, form): action = Action(user=self.request.user, timestamp=timezone.now(), target=form.instance.invoice) action.action = "updated list price " + str( form.instance) + " (" + str(form.instance.price) + " NOK)" action.save() return super(UpdateListPrice, self).form_valid(form)
def form_valid(self, form): action = Action(user=self.request.user, timestamp=timezone.now(), target=form.instance) action.action = "changed billing type of " + str( form.instance) + " to " + str(form.instance.billing_type) action.save() return super(UpdateCruiseBillingType, self).form_valid(form)
def get_success_url(self): action = Action(user=self.request.user, timestamp=timezone.now(), target=str(self.object)) action.action = "edited system settings" action.save() messages.add_message( self.request, messages.SUCCESS, mark_safe('System settings successfully updated.')) return reverse_lazy('settings')
def form_valid(self, form): invoice = form.save(commit=False) invoice.is_cruise_invoice = False invoice.save() action = Action(user=self.request.user, timestamp=timezone.now(), target=str(self.object)) action.action = "created standalone invoice" action.save() return HttpResponseRedirect(self.get_success_url())
def form_valid(self, form): form.instance.invoice = InvoiceInformation.objects.get( pk=self.kwargs['pk']) action = Action(user=self.request.user, timestamp=timezone.now(), target=form.instance.invoice) action.action = "added list price " + str(form.instance) + " (" + str( form.instance.price) + " NOK)" action.save() return super(CreateListPrice, self).form_valid(form)
def get_success_url(self): action = Action(user=self.request.user, timestamp=timezone.now(), target=self.object.invoice) action.action = "deleted list price " + str(self.object) + " (" + str( self.object.price) + " NOK)" action.save() if self.object.invoice.cruise: return reverse_lazy('cruise-invoices', kwargs={'pk': self.object.invoice.cruise.pk}) return reverse_lazy('admin-invoices')
def toggle_user_crew_status(request, pk): # is_staff is internally used to mark crew members for the off hour calculation view. user = get_object_or_404(User, pk=pk) if request.user.is_superuser: action = Action(user=request.user, target=str(user)) if user.is_staff: user.is_staff = False action.action = "set user as not crew" messages.add_message( request, messages.SUCCESS, mark_safe('User ' + str(user) + ' set as not crew.')) else: user.is_staff = True action.action = "set user as crew" messages.add_message( request, messages.SUCCESS, mark_safe('User ' + str(user) + ' set as crew.')) user.save() action.timestamp = timezone.now() action.save() else: raise PermissionDenied return redirect(request.META['HTTP_REFERER'])
def mark_invoice_as_unsent(request, pk): invoice = get_object_or_404(InvoiceInformation, pk=pk) if (request.user.userdata.role == "invoicer"): invoice.is_sent = False invoice.save() action = Action(user=request.user, target=str(invoice)) action.action = "marked as unsent" action.timestamp = timezone.now() action.save() messages.add_message( request, messages.SUCCESS, mark_safe('Invoice "' + str(invoice) + '" marked as unsent.')) else: raise PermissionDenied return redirect(request.META['HTTP_REFERER'])
def delete_user(request, pk): user = get_object_or_404(User, pk=pk) if request.user.is_superuser: user.userdata.role = "" user.is_active = False user.userdata.save() user.save() action = Action(user=request.user, target=str(user)) action.action = "deleted user" action.timestamp = timezone.now() action.save() Cruise.objects.filter(leader=user).update( missing_information_cache_outdated=True) messages.add_message(request, messages.WARNING, mark_safe('User ' + str(user) + ' deleted.')) else: raise PermissionDenied return redirect(request.META['HTTP_REFERER'])
def mark_invoice_as_unfinalized(request, pk): invoice = get_object_or_404(InvoiceInformation, pk=pk) if (request.user.is_superuser and not invoice.is_sent): invoice.is_finalized = False invoice.save() action = Action(user=request.user, target=str(invoice)) action.action = "marked invoice as unfinalized" action.timestamp = timezone.now() action.save() messages.add_message( request, messages.SUCCESS, mark_safe( 'Invoice "' + str(invoice) + '" marked as finalized. It is no longer viewable by invoicers.' )) else: raise PermissionDenied return redirect(request.META['HTTP_REFERER'])
def event_category_reset_view(request, pk): from reserver.utils import default_event_categories event_category = get_object_or_404(EventCategory, pk=pk) default = next(df for df in default_event_categories if df[0] == event_category.name) event_category.name = default[0] event_category.icon = default[1] event_category.colour = default[2] event_category.description = default[3] event_category.is_default = True event_category.save() action = Action(user=request.user, timestamp=timezone.now(), target=str(event_category)) action.action = "reset event category to default" action.save() messages.add_message( request, messages.SUCCESS, mark_safe('The contents of the event category "' + str(event_category) + '" was reset to its default values.')) return HttpResponseRedirect(reverse_lazy('eventcategories'))
def form_valid(self, form): """Called when all our forms are valid. Creates a Cruise with Participants and CruiseDays.""" season = form.save(commit=False) season_event = Event() season_event.category = EventCategory.objects.get(name="Season") season_event.name = 'Event for ' + form.cleaned_data.get("name") season_event.start_time = form.cleaned_data.get( "season_event_start_date") season_event.end_time = form.cleaned_data.get( "season_event_end_date").replace(hour=23, minute=59) season_event.save() internal_order_event = Event() internal_order_event.category = EventCategory.objects.get( name="Internal season opening") internal_order_event.name = 'Internal opening of ' + form.cleaned_data.get( "name") internal_order_event.start_time = form.cleaned_data.get( "internal_order_event_date") internal_order_event.save() external_order_event = Event() external_order_event.category = EventCategory.objects.get( name="External season opening") external_order_event.name = 'External opening of ' + form.cleaned_data.get( "name") external_order_event.start_time = form.cleaned_data.get( "external_order_event_date") external_order_event.save() season.season_event = season_event season.internal_order_event = internal_order_event season.external_order_event = external_order_event season.save() self.object = form.save() action = Action(user=self.request.user, timestamp=timezone.now(), target=str(season)) action.action = "created season" action.save() create_season_notifications(season) return HttpResponseRedirect(self.get_success_url())
def email_template_reset_view(request, pk): from reserver.utils import default_email_templates template = get_object_or_404(EmailTemplate, pk=pk) default = next(df for df in default_email_templates if df[0] == template.title) template.title = default[0] template.message = default[2] template.time_before = default[3] template.is_active = default[5] template.is_muteable = default[6] template.date = default[4] template.is_default = True template.group = default[1] template.save() action = Action(user=request.user, timestamp=timezone.now(), target=str(template)) action.action = "reset email template to default" action.save() messages.add_message( request, messages.SUCCESS, mark_safe('The contents of the email template "' + str(template) + '" was reset to its default values.')) return HttpResponseRedirect(reverse_lazy('notifications'))
def form_valid(self, form): """Called when all our forms are valid. Creates a Cruise with Participants and CruiseDays.""" season = form.save(commit=False) season.season_event.start_time = form.cleaned_data.get( "season_event_start_date") season.season_event.end_time = form.cleaned_data.get( "season_event_end_date").replace(hour=23, minute=59) season.season_event.save() season.internal_order_event.start_time = form.cleaned_data.get( "internal_order_event_date") season.internal_order_event.save() season.external_order_event.start_time = form.cleaned_data.get( "external_order_event_date") season.external_order_event.save() season.save() self.object = form.save() action = Action(user=self.request.user, timestamp=timezone.now(), target=str(season)) action.action = "updated season" action.save() delete_season_notifications(season) create_season_notifications(season) return HttpResponseRedirect(self.get_success_url())