def new_contact_ticket(request): ticket_created = False if request.POST: form = __get_contact_form(request) if form.is_valid(): ticket = Ticket() ticket.title = form.cleaned_data['title'] ticket.source = TICKET_SOURCE_CONTACT_FORM ticket.status = TICKET_STATUS_NEW ticket.queue = Queue.objects.get(name=QUEUE_SUPPORT_REQUESTS) tc = TicketComment() if request.user.is_authenticated(): ticket.sender = request.user tc.sender = request.user else: ticket.sender_email = form.cleaned_data['email'] tc.text = form.cleaned_data['message'] ticket.save() tc.ticket = ticket tc.save() ticket_created = True # TODO: send email else: form = __get_contact_form(request, False) return render_to_response('tickets/contact.html', locals(), context_instance=RequestContext(request))
def ticket(request, ticket_key): can_view_moderator_only_messages = _can_view_mod_msg(request) clean_status_forms = True clean_comment_form = True ticket = get_object_or_404(Ticket, key=ticket_key) if ticket.content: # Becuase it can happen that some tickets have linked content which has dissapeared or on deletion time the ticket # has not been propertly updated, we need to check whether the sound that is linked does in fact exist. If it does # not, we set the linked content to None and the status of the ticket to closed as should have been set at sound # deletion time. sound_id = ticket.content.object_id try: Sound.objects.get(id=sound_id) except Sound.DoesNotExist: ticket.content = None ticket.status = TICKET_STATUS_CLOSED ticket.save() if request.method == 'POST': invalidate_template_cache("user_header", ticket.sender.id) invalidate_all_moderators_header_cache() # Left ticket message if is_selected(request, 'recaptcha') or (request.user.is_authenticated() and is_selected(request, 'message')): tc_form = _get_tc_form(request) if tc_form.is_valid(): tc = TicketComment() tc.text = tc_form.cleaned_data['message'] tc.moderator_only = tc_form.cleaned_data.get( 'moderator_only', False) if tc.text: if request.user.is_authenticated(): tc.sender = request.user tc.ticket = ticket tc.save() if not request.user.is_authenticated(): email_to = Ticket.MODERATOR_ONLY elif request.user == ticket.sender: email_to = Ticket.MODERATOR_ONLY else: email_to = Ticket.USER_ONLY ticket.send_notification_emails( ticket.NOTIFICATION_UPDATED, email_to) else: clean_comment_form = False # update sound ticket elif is_selected(request, 'tm') or is_selected(request, 'ss'): ticket_form = TicketModerationForm(request.POST, prefix="tm") sound_form = SoundStateForm(request.POST, prefix="ss") if ticket_form.is_valid() and sound_form.is_valid(): clean_status_forms = True clean_comment_form = True sound_state = sound_form.cleaned_data.get('state') # Sound should be deleted if sound_state == 'DE': if ticket.content: ticket.content.content_object.delete() ticket.content.delete() ticket.content = None ticket.status = TICKET_STATUS_CLOSED tc = TicketComment( sender=request.user, text= "Moderator %s deleted the sound and closed the ticket" % request.user, ticket=ticket, moderator_only=False) tc.save() ticket.send_notification_emails( ticket.NOTIFICATION_DELETED, ticket.USER_ONLY) # Set another sound state that's not delete else: if ticket.content: ticket.content.content_object.moderation_state = sound_state # Mark the index as dirty so it'll be indexed in Solr if sound_state == "OK": ticket.content.content_object.mark_index_dirty() ticket.content.content_object.save() ticket.status = ticket_form.cleaned_data.get('status') tc = TicketComment( sender=request.user, text= "Moderator %s set the sound to %s and the ticket to %s." % (request.user, 'pending' if sound_state == 'PE' else sound_state, ticket.status), ticket=ticket, moderator_only=False) tc.save() ticket.send_notification_emails( ticket.NOTIFICATION_UPDATED, ticket.USER_ONLY) ticket.save() if clean_status_forms: ticket_form = TicketModerationForm(initial={'status': ticket.status}, prefix="tm") state = ticket.content.content_object.moderation_state if ticket.content else 'DE' sound_form = SoundStateForm(initial={'state': state}, prefix="ss") if clean_comment_form: tc_form = _get_tc_form(request, False) num_sounds_pending = ticket.sender.profile.num_sounds_pending_moderation() tvars = { "ticket": ticket, "num_sounds_pending": num_sounds_pending, "tc_form": tc_form, "ticket_form": ticket_form, "sound_form": sound_form, "can_view_moderator_only_messages": can_view_moderator_only_messages } return render(request, 'tickets/ticket.html', tvars)
def ticket(request, ticket_key): can_view_moderator_only_messages = _can_view_mod_msg(request) clean_status_forms = True clean_comment_form = True ticket = get_object_or_404(Ticket, key=ticket_key) if request.method == 'POST': invalidate_template_cache("user_header", ticket.sender.id) invalidate_all_moderators_header_cache() # Left ticket message if is_selected(request, 'recaptcha') or (request.user.is_authenticated() and is_selected(request, 'message')): tc_form = _get_tc_form(request) if tc_form.is_valid(): tc = TicketComment() tc.text = tc_form.cleaned_data['message'] tc.moderator_only = tc_form.cleaned_data.get('moderator_only', False) if tc.text: if request.user.is_authenticated(): tc.sender = request.user tc.ticket = ticket tc.save() if not request.user.is_authenticated(): email_to = Ticket.MODERATOR_ONLY elif request.user == ticket.sender: email_to = Ticket.MODERATOR_ONLY else: email_to = Ticket.USER_ONLY ticket.send_notification_emails(ticket.NOTIFICATION_UPDATED, email_to) else: clean_comment_form = False # update sound ticket elif is_selected(request, 'tm') or is_selected(request, 'ss'): ticket_form = TicketModerationForm(request.POST, prefix="tm") sound_form = SoundStateForm(request.POST, prefix="ss") if ticket_form.is_valid() and sound_form.is_valid(): clean_status_forms = True clean_comment_form = True sound_state = sound_form.cleaned_data.get('state') # Sound should be deleted if sound_state == 'DE': if ticket.sound: ticket.sound.delete() ticket.sound = None ticket.status = TICKET_STATUS_CLOSED tc = TicketComment(sender=request.user, text="Moderator %s deleted the sound and closed the ticket" % request.user, ticket=ticket, moderator_only=False) tc.save() ticket.send_notification_emails(ticket.NOTIFICATION_DELETED, ticket.USER_ONLY) # Set another sound state that's not delete else: if ticket.sound: ticket.sound.moderation_state = sound_state # Mark the index as dirty so it'll be indexed in Solr if sound_state == "OK": ticket.sound.mark_index_dirty() ticket.sound.save() ticket.status = ticket_form.cleaned_data.get('status') tc = TicketComment(sender=request.user, text="Moderator %s set the sound to %s and the ticket to %s." % (request.user, 'pending' if sound_state == 'PE' else sound_state, ticket.status), ticket=ticket, moderator_only=False) tc.save() ticket.send_notification_emails(ticket.NOTIFICATION_UPDATED, ticket.USER_ONLY) ticket.save() if clean_status_forms: ticket_form = TicketModerationForm(initial={'status': ticket.status}, prefix="tm") state = ticket.sound.moderation_state if ticket.sound else 'DE' sound_form = SoundStateForm(initial={'state': state}, prefix="ss") if clean_comment_form: tc_form = _get_tc_form(request, False) num_sounds_pending = ticket.sender.profile.num_sounds_pending_moderation() tvars = {"ticket": ticket, "num_sounds_pending": num_sounds_pending, "tc_form": tc_form, "ticket_form": ticket_form, "sound_form": sound_form, "can_view_moderator_only_messages": can_view_moderator_only_messages} return render(request, 'tickets/ticket.html', tvars)
def ticket(request, ticket_key): can_view_moderator_only_messages = __can_view_mod_msg(request) clean_status_forms = True clean_comment_form = True ticket = get_object_or_404(Ticket, key=ticket_key) if request.method == 'POST': invalidate_template_cache("user_header", ticket.sender.id) invalidate_all_moderators_header_cache() # Left ticket message if is_selected(request, 'recaptcha') or (request.user.is_authenticated() and is_selected(request, 'message')): tc_form = __get_tc_form(request) if tc_form.is_valid(): tc = TicketComment() tc.text = tc_form.cleaned_data['message'] tc.moderator_only = tc_form.cleaned_data.get( 'moderator_only', False) if tc.text: if request.user.is_authenticated(): tc.sender = request.user tc.ticket = ticket tc.save() if not request.user.is_authenticated(): email_to = Ticket.MODERATOR_ONLY elif request.user == ticket.sender: email_to = Ticket.MODERATOR_ONLY else: email_to = Ticket.USER_ONLY ticket.send_notification_emails( ticket.NOTIFICATION_UPDATED, email_to) else: clean_comment_form = False # update sound ticket elif is_selected(request, 'tm') or is_selected(request, 'ss'): ticket_form = TicketModerationForm(request.POST, prefix="tm") sound_form = SoundStateForm(request.POST, prefix="ss") if ticket_form.is_valid() and sound_form.is_valid(): clean_status_forms = True clean_comment_form = True sound_state = sound_form.cleaned_data.get('state') # Sound should be deleted if sound_state == 'DE': if ticket.content: ticket.content.content_object.delete() ticket.content.delete() ticket.content = None ticket.status = TICKET_STATUS_CLOSED tc = TicketComment( sender=request.user, text= "Moderator %s deleted the sound and closed the ticket" % request.user, ticket=ticket, moderator_only=False) tc.save() ticket.send_notification_emails( ticket.NOTIFICATION_DELETED, ticket.USER_ONLY) # Set another sound state that's not delete else: if ticket.content: ticket.content.content_object.moderation_state = sound_state # Mark the index as dirty so it'll be indexed in Solr if sound_state == "OK": ticket.content.content_object.mark_index_dirty() ticket.content.content_object.save() ticket.status = ticket_form.cleaned_data.get('status') tc = TicketComment(sender=request.user, text="Moderator %s set the sound to %s and the ticket to %s." % \ (request.user, 'pending' if sound_state == 'PE' else sound_state, ticket.status), ticket=ticket, moderator_only=False) tc.save() ticket.send_notification_emails( ticket.NOTIFICATION_UPDATED, ticket.USER_ONLY) ticket.save() if clean_status_forms: ticket_form = TicketModerationForm(initial={'status': ticket.status}, prefix="tm") sound_form = SoundStateForm(initial={'state': ticket.content.content_object.moderation_state \ if ticket.content else 'DE'}, prefix="ss") if clean_comment_form: tc_form = __get_tc_form(request, False) return render_to_response('tickets/ticket.html', locals(), context_instance=RequestContext(request))
def ticket(request, ticket_key): can_view_moderator_only_messages = _can_view_mod_msg(request) clean_status_forms = True clean_comment_form = True ticket = get_object_or_404(Ticket.objects.select_related( 'sound__license', 'sound__user'), key=ticket_key) if request.method == 'POST': invalidate_template_cache("user_header", ticket.sender.id) invalidate_all_moderators_header_cache() # Left ticket message if is_selected(request, 'recaptcha') or (request.user.is_authenticated and is_selected(request, 'message')): tc_form = _get_tc_form(request) if tc_form.is_valid(): tc = TicketComment() tc.text = tc_form.cleaned_data['message'] tc.moderator_only = tc_form.cleaned_data.get( 'moderator_only', False) if tc.text: if request.user.is_authenticated: tc.sender = request.user tc.ticket = ticket tc.save() if not request.user.is_authenticated: email_to = Ticket.MODERATOR_ONLY elif request.user == ticket.sender: email_to = Ticket.MODERATOR_ONLY else: email_to = Ticket.USER_ONLY ticket.send_notification_emails( ticket.NOTIFICATION_UPDATED, email_to) else: clean_comment_form = False # update sound ticket elif is_selected(request, 'ss'): sound_form = SoundStateForm(request.POST, prefix='ss') if sound_form.is_valid(): clean_status_forms = True clean_comment_form = True sound_action = sound_form.cleaned_data.get('action') comment = 'Moderator {} '.format(request.user) notification = None # If there is no one assigned, then changing the state self-assigns the ticket if ticket.assignee is None: ticket.assignee = request.user if sound_action == 'Delete': if ticket.sound: ticket.sound.delete() ticket.sound = None ticket.status = TICKET_STATUS_CLOSED comment += 'deleted the sound and closed the ticket' notification = ticket.NOTIFICATION_DELETED elif sound_action == 'Defer': ticket.status = TICKET_STATUS_DEFERRED ticket.sound.change_moderation_state( 'PE') # not sure if this state have been used before comment += 'deferred the ticket' elif sound_action == "Return": ticket.status = TICKET_STATUS_NEW ticket.assignee = None ticket.sound.change_moderation_state('PE') comment += 'returned the ticket to new sounds queue' elif sound_action == 'Approve': ticket.status = TICKET_STATUS_CLOSED ticket.sound.change_moderation_state('OK') comment += 'approved the sound and closed the ticket' notification = ticket.NOTIFICATION_APPROVED elif sound_action == 'Whitelist': _whitelist_gearman([ ticket.id ]) # async job should take care of whitelisting comment += 'whitelisted all sounds from user {}'.format( ticket.sender) notification = ticket.NOTIFICATION_WHITELISTED if notification is not None: ticket.send_notification_emails(notification, ticket.USER_ONLY) if ticket.sound is not None: ticket.sound.save() ticket.save() tc = TicketComment(sender=request.user, text=comment, ticket=ticket, moderator_only=False) tc.save() if clean_status_forms: default_action = 'Return' if ticket.sound and ticket.sound.moderation_state == 'OK' else 'Approve' sound_form = SoundStateForm(initial={'action': default_action}, prefix="ss") if clean_comment_form: tc_form = _get_tc_form(request, False) num_sounds_pending = ticket.sender.profile.num_sounds_pending_moderation() tvars = { "ticket": ticket, "num_sounds_pending": num_sounds_pending, "tc_form": tc_form, "sound_form": sound_form, "can_view_moderator_only_messages": can_view_moderator_only_messages } return render(request, 'tickets/ticket.html', tvars)
def ticket(request, ticket_key): can_view_moderator_only_messages = __can_view_mod_msg(request) clean_status_forms = True clean_comment_form = True ticket = get_object_or_404(Ticket, key=ticket_key) if request.method == "POST": # Left ticket message if is_selected(request, "recaptcha") or (request.user.is_authenticated() and is_selected(request, "message")): tc_form = __get_tc_form(request) if tc_form.is_valid(): tc = TicketComment() tc.text = tc_form.cleaned_data["message"] tc.moderator_only = tc_form.cleaned_data.get("moderator_only", False) if tc.text: if request.user.is_authenticated(): tc.sender = request.user tc.ticket = ticket tc.save() if not request.user.is_authenticated(): email_to = Ticket.MODERATOR_ONLY elif request.user == ticket.sender: email_to = Ticket.MODERATOR_ONLY else: email_to = Ticket.USER_ONLY ticket.send_notification_emails(ticket.NOTIFICATION_UPDATED, email_to) else: clean_comment_form = False # update sound ticket elif is_selected(request, "tm") or is_selected(request, "ss"): ticket_form = TicketModerationForm(request.POST, prefix="tm") sound_form = SoundStateForm(request.POST, prefix="ss") if ticket_form.is_valid() and sound_form.is_valid(): clean_status_forms = True clean_comment_form = True sound_state = sound_form.cleaned_data.get("state") # Sound should be deleted if sound_state == "DE": if ticket.content: ticket.content.content_object.delete() ticket.content.delete() ticket.content = None ticket.status = TICKET_STATUS_CLOSED tc = TicketComment( sender=request.user, text="Moderator %s deleted the sound and closed the ticket" % request.user, ticket=ticket, moderator_only=False, ) tc.save() ticket.send_notification_emails(ticket.NOTIFICATION_DELETED, ticket.USER_ONLY) # Set another sound state that's not delete else: if ticket.content: ticket.content.content_object.moderation_state = sound_state # Mark the index as dirty so it'll be indexed in Solr if sound_state == "OK": ticket.content.content_object.mark_index_dirty() ticket.content.content_object.save() ticket.status = ticket_form.cleaned_data.get("status") tc = TicketComment( sender=request.user, text="Moderator %s set the sound to %s and the ticket to %s." % (request.user, "pending" if sound_state == "PE" else sound_state, ticket.status), ticket=ticket, moderator_only=False, ) tc.save() ticket.send_notification_emails(ticket.NOTIFICATION_UPDATED, ticket.USER_ONLY) ticket.save() if clean_status_forms: ticket_form = TicketModerationForm(initial={"status": ticket.status}, prefix="tm") sound_form = SoundStateForm( initial={"state": ticket.content.content_object.moderation_state if ticket.content else "DE"}, prefix="ss" ) if clean_comment_form: tc_form = __get_tc_form(request, False) return render_to_response("tickets/ticket.html", locals(), context_instance=RequestContext(request))