def sponsors(request, sel_event_id): # Check for form data if request.method == 'POST': # Check for permissions if not request.user.has_perm('screenshow.add_sponsor'): raise Http403 # Handle data sponsorform = SponsorForm(request.POST, request.FILES) if sponsorform.is_valid(): data = sponsorform.save(commit=False) data.event_id = sel_event_id data.save() logger.info('Sponsor "{}" added.'.format(data.name), extra={'user': request.user, 'event_id': sel_event_id}) return HttpResponseRedirect(reverse('manage-screenshow:sponsors', args=(sel_event_id,))) else: sponsorform = SponsorForm() # Get sponsors sponsors = Sponsor.objects.filter(event_id=sel_event_id) # Dump template return admin_render(request, "admin_screenshow/sponsors.html", { 'selected_event_id': int(sel_event_id), 'sponsorform': sponsorform, 'sponsors': sponsors, })
def playlist(request, sel_event_id): # Check for form data if request.method == 'POST': # Check for permissions if not request.user.has_perm('screenshow.add_playlistvideo'): raise Http403 # Handle data playlistform = PlaylistVideoForm(request.POST) if playlistform.is_valid(): data = playlistform.save(commit=False) data.event_id = sel_event_id data.save() logger.info('Video "{}" added to playlist.'.format(data.name), extra={'user': request.user, 'event_id': sel_event_id}) return HttpResponseRedirect(reverse('manage-screenshow:playlist', args=(sel_event_id,))) else: playlistform = PlaylistVideoForm() # Get messages videos = PlaylistVideo.objects.filter(event_id=sel_event_id).order_by('-index') # Dump template return admin_render(request, "admin_screenshow/playlist.html", { 'selected_event_id': int(sel_event_id), 'videos': videos, 'playlistform': playlistform, })
def edit(request, sel_event_id, entry_id): # Check for permissions if not request.user.has_perm('ext_blog.change_blogentry'): raise Http403 # Get old entry entry = get_object_or_404(BlogEntry, pk=entry_id) # Go ahead and edit if request.method == 'POST': form = BlogEntryEditForm(request.POST, instance=entry) if form.is_valid(): entry = form.save() logger.info('Blog entry "' + entry.title + '" edited.', extra={ 'user': request.user, 'event_id': sel_event_id }) return HttpResponseRedirect( reverse('manage-blog:index', args=(sel_event_id, ))) else: form = BlogEntryEditForm(instance=entry) # Render response return admin_render(request, "admin_blog/edit.html", { 'editform': form, 'selected_event_id': int(sel_event_id), })
def message_edit(request, sel_event_id, message_id): # Check for permissions if not request.user.has_perm('screenshow.change_message'): raise Http403 # Get initial data message = get_object_or_404(Message, pk=message_id) # Check for form data if request.method == 'POST': messageform = MessageForm(request.POST, instance=message) if messageform.is_valid(): messageform.save() logger.info('Message edited.', extra={'user': request.user, 'event_id': sel_event_id}) return HttpResponseRedirect(reverse('manage-screenshow:messages', args=(sel_event_id,))) else: messageform = MessageForm(instance=message) # Dump template return admin_render(request, "admin_screenshow/message_edit.html", { 'selected_event_id': int(sel_event_id), 'message_id': int(message_id), 'messageform': messageform, })
def editcat(request, sel_event_id, category_id): # Check for permissions if not request.user.has_perm("arkisto.change_othervideocategory"): raise Http403 # Get event event = get_object_or_404(Event, pk=sel_event_id) # Get category category = get_object_or_404(OtherVideoCategory, pk=category_id, event=event) # Handle form if request.method == "POST": catform = VideoCategoryForm(request.POST, instance=category) if catform.is_valid(): r_cat = catform.save() logger.info( "Edited archive video category {}".format(r_cat.name), extra={"user": request.user, "event": event} ) return HttpResponseRedirect(reverse("manage-arkisto:vidcats", args=(sel_event_id,))) else: catform = VideoCategoryForm(instance=category) # Render response return admin_render( request, "admin_arkisto/editcat.html", {"catform": catform, "cat": category, "selected_event_id": int(sel_event_id)}, )
def index(request): # Handle form data, if any if request.method == 'POST': # CHeck for permissions if not request.user.has_perm('kompomaatti.add_event'): raise Http403 # Handle form eventform = EventForm(request.POST) if eventform.is_valid(): data = eventform.save(commit=False) data.archived = False data.save() logger.info('Event "'+data.name+'" added.', extra={'user': request.user}) return HttpResponseRedirect(reverse('manage-events:index')) else: eventform = EventForm() # Get all events events = Event.objects.all() # Render response return admin_render(request, "admin_events/index.html", { 'events': events, 'eventform': eventform, })
def index(request, sel_event_id): event = get_object_or_404(Event, pk=sel_event_id) # Handle form data if request.method == 'POST': if not request.user.has_perm('tickets.add_ticket'): raise Http403 # Handle data ticketform = TicketForm(request.POST, event=event) if ticketform.is_valid(): ticket = ticketform.save(commit=False) ticket.event = event for i in range(10): try: ticket.key = gen_sha('0|%s|%s|%s|%s' % (event.id, ticket.storeitem.id, random.random(), time.time())) ticket.save() except IntegrityError as ex: logger.warning("SHA-1 Collision in admin-ticket (WTF!) Key: %s, exception: %s." % (ticket.key, ex)) logger.info('New ticket created.', extra={'user': request.user, 'event_id': sel_event_id}) return HttpResponseRedirect(reverse('manage-tickets:index', args=(sel_event_id))) else: ticketform = TicketForm(event=event) # Get tickets tickets = Ticket.objects.filter(event=sel_event_id) # Render response return admin_render(request, "admin_tickets/index.html", { 'tickets': tickets, 'ticketform': ticketform, 'selected_event_id': int(sel_event_id), })
def editvid(request, sel_event_id, video_id): # Check for permissions if not request.user.has_perm("arkisto.change_othervideo"): raise Http403 # Get Video video = get_object_or_404(OtherVideo, pk=video_id) # Get event event = get_object_or_404(Event, pk=sel_event_id) # Handle form if request.method == "POST": vidform = VideoForm(request.POST, instance=video, event=event) if vidform.is_valid(): r_video = vidform.save() logger.info("Edited archive video {}".format(r_video.name), extra={"user": request.user, "event": event}) return HttpResponseRedirect(reverse("manage-arkisto:vids", args=(sel_event_id,))) else: vidform = VideoForm(instance=video, event=event) # Render response return admin_render( request, "admin_arkisto/editvid.html", {"vidform": vidform, "vid": video, "selected_event_id": int(sel_event_id)}, )
def editcat(request, sel_event_id, category_id): # Check for permissions if not request.user.has_perm('arkisto.change_othervideocategory'): raise Http403 # Get event event = get_object_or_404(Event, pk=sel_event_id) # Get category category = get_object_or_404(OtherVideoCategory, pk=category_id, event=event) # Handle form if request.method == "POST": catform = VideoCategoryForm(request.POST, instance=category) if catform.is_valid(): r_cat = catform.save() logger.info('Edited archive video category '+r_cat.name, extra={'user': request.user, 'event': event}) return HttpResponseRedirect(reverse('manage-arkisto:vidcats', args=(sel_event_id))) else: catform = VideoCategoryForm(instance=category) # Render response return admin_render(request, "admin_arkisto/editcat.html", { 'catform': catform, 'cat': category, 'selected_event_id': int(sel_event_id), })
def index(request, sel_event_id): # Render response return admin_render( request, "admin_slides/index.html", { 'compos': Compo.objects.filter(event_id=sel_event_id), 'selected_event_id': int(sel_event_id), })
def editcat(request, sel_event_id, category_id): # Check for permissions if not request.user.has_perm('arkisto.change_othervideocategory'): raise Http403 # Get event event = get_object_or_404(Event, pk=sel_event_id) # Get category category = get_object_or_404(OtherVideoCategory, pk=category_id, event=event) # Handle form if request.method == "POST": catform = VideoCategoryForm(request.POST, instance=category) if catform.is_valid(): r_cat = catform.save() logger.info('Edited archive video category {}'.format(r_cat.name), extra={ 'user': request.user, 'event': event }) return HttpResponseRedirect( reverse('manage-arkisto:vidcats', args=(sel_event_id, ))) else: catform = VideoCategoryForm(instance=category) # Render response return admin_render( request, "admin_arkisto/editcat.html", { 'catform': catform, 'cat': category, 'selected_event_id': int(sel_event_id), })
def editvid(request, sel_event_id, video_id): # Check for permissions if not request.user.has_perm('arkisto.change_othervideo'): raise Http403 # Get Video video = get_object_or_404(OtherVideo, pk=video_id) # Get event event = get_object_or_404(Event, pk=sel_event_id) # Handle form if request.method == "POST": vidform = VideoForm(request.POST, instance=video, event=event) if vidform.is_valid(): r_video = vidform.save() logger.info('Edited archive video {}'.format(r_video.name), extra={ 'user': request.user, 'event': event }) return HttpResponseRedirect( reverse('manage-arkisto:vids', args=(sel_event_id, ))) else: vidform = VideoForm(instance=video, event=event) # Render response return admin_render(request, "admin_arkisto/editvid.html", { 'vidform': vidform, 'vid': video, 'selected_event_id': int(sel_event_id), })
def cats(request, sel_event_id): # Get event event = get_object_or_404(Event, pk=sel_event_id) # Handle form if request.method == "POST": # Check for permissions if not request.user.has_perm('arkisto.add_othervideocategory'): raise Http403 # Handle form catform = VideoCategoryForm(request.POST) if catform.is_valid(): cat = catform.save(commit=False) cat.event = event cat.save() logger.info('Added archive video category '.format(cat.name), extra={'user': request.user, 'event': event}) return HttpResponseRedirect(reverse('manage-arkisto:vidcats', args=(sel_event_id,))) else: catform = VideoCategoryForm() # Get videos belonging to selected event categories = OtherVideoCategory.objects.filter(event_id=int(sel_event_id)) # Render response return admin_render(request, "admin_arkisto/cats.html", { 'categories': categories, 'catform': catform, 'selected_event_id': int(sel_event_id), })
def playlist_edit(request, sel_event_id, video_id): # Check for permissions if not request.user.has_perm('screenshow.change_playlistvideo'): raise Http403 # Get initial data playlist = get_object_or_404(PlaylistVideo, pk=video_id) # Check for form data if request.method == 'POST': playlistform = PlaylistVideoForm(request.POST, instance=playlist) if playlistform.is_valid(): v = playlistform.save() logger.info('Video "{}" edited on playlist.'.format(v.name), extra={ 'user': request.user, 'event_id': sel_event_id }) return HttpResponseRedirect( reverse('manage-screenshow:playlist', args=(sel_event_id, ))) else: playlistform = PlaylistVideoForm(instance=playlist) # Dump template return admin_render( request, "admin_screenshow/playlist_edit.html", { 'selected_event_id': int(sel_event_id), 'video_id': int(video_id), 'playlistform': playlistform, })
def edit_ticket(request, sel_event_id, ticket_id): if not request.user.has_perm('tickets.change_ticket'): raise Http403 # Get event event = get_object_or_404(Event, pk=sel_event_id) # Get ticket ticket = get_object_or_404(Ticket, pk=ticket_id) # Handle form data if request.method == 'POST': ticketform = TicketForm(request.POST, instance=ticket, event=event) if ticketform.is_valid(): ticketform.save() logger.info('Ticket '+ticket.key+' edited.', extra={'user': request.user, 'event_id': sel_event_id}) return HttpResponseRedirect(reverse('manage-tickets:index', args=(sel_event_id))) else: ticketform = TicketForm(instance=ticket, event=event) # Render response return admin_render(request, "admin_tickets/edit.html", { 'ticketform': ticketform, 'selected_event_id': int(sel_event_id), })
def vids(request, sel_event_id): # Get event event = get_object_or_404(Event, pk=sel_event_id) # Handle form if request.method == "POST": # Check for permissions if not request.user.has_perm("arkisto.add_othervideo"): raise Http403 # Handle form vidform = VideoForm(request.POST, event=event) if vidform.is_valid(): video = vidform.save() logger.info("Added archive video {}".format(video.name), extra={"user": request.user, "event": event}) return HttpResponseRedirect(reverse("manage-arkisto:vids", args=(sel_event_id,))) else: vidform = VideoForm(event=event) # Get videos belonging to selected event categories = OtherVideoCategory.objects.filter(event_id=int(sel_event_id)) videos = [] for cat in categories: vlist = OtherVideo.objects.filter(category=cat) for video in vlist: videos.append(video) # Render response return admin_render( request, "admin_arkisto/vids.html", {"videos": videos, "vidform": vidform, "selected_event_id": int(sel_event_id)}, )
def apps(request): # Handle adding new apps if request.method == 'POST': add_form = ApiApplicationForm(request.POST, user=request.user) if add_form.is_valid(): app = add_form.save() logger.info('Application %s created.', app.name, extra={'user': request.user}) return HttpResponseRedirect(reverse('manage-users:apps')) else: add_form = ApiApplicationForm() # Apps owned by the current user m_apps = Application.objects.filter(user=request.user) # Get all applications for superusers only all_apps = None if request.user.is_superuser: all_apps = Application.objects.all() return admin_render(request, "admin_users/api_tokens.html", { 'apps': m_apps, 'add_form': add_form, 'all_apps': all_apps })
def cats(request, sel_event_id): # Get event event = get_object_or_404(Event, pk=sel_event_id) # Handle form if request.method == "POST": # Check for permissions if not request.user.has_perm("arkisto.add_othervideocategory"): raise Http403 # Handle form catform = VideoCategoryForm(request.POST) if catform.is_valid(): cat = catform.save(commit=False) cat.event = event cat.save() logger.info("Added archive video category ".format(cat.name), extra={"user": request.user, "event": event}) return HttpResponseRedirect(reverse("manage-arkisto:vidcats", args=(sel_event_id,))) else: catform = VideoCategoryForm() # Get videos belonging to selected event categories = OtherVideoCategory.objects.filter(event_id=int(sel_event_id)) # Render response return admin_render( request, "admin_arkisto/cats.html", {"categories": categories, "catform": catform, "selected_event_id": int(sel_event_id)}, )
def index(request): # Handle form data, if any if request.method == 'POST': # CHeck for permissions if not request.user.has_perm('kompomaatti.add_event'): raise Http403 # Handle form eventform = EventForm(request.POST) if eventform.is_valid(): data = eventform.save(commit=False) data.archived = False data.save() logger.info('Event "' + data.name + '" added.', extra={'user': request.user}) return HttpResponseRedirect(reverse('manage-events:index')) else: eventform = EventForm() # Get all events events = Event.objects.all() # Render response return admin_render(request, "admin_events/index.html", { 'events': events, 'eventform': eventform, })
def votecodes(request, sel_event_id): # Handle form if request.method == 'POST': # CHeck for permissions if not request.user.has_perm('kompomaatti.add_votecode'): raise Http403 # Handle form gentokensform = CreateTokensForm(request.POST) if gentokensform.is_valid(): amount = int(gentokensform.cleaned_data['amount']) for n in range(amount): try: c = VoteCode() c.event_id = int(sel_event_id) c.key = str(hashlib.md5(bytes(os.urandom(8))).hexdigest()[:8]) c.save() except IntegrityError: n -= 1 logger.info('Votecodes generated.', extra={'user': request.user, 'event_id': sel_event_id}) return HttpResponseRedirect(reverse('manage-kompomaatti:votecodes', args=(sel_event_id,))) else: gentokensform = CreateTokensForm() # Get tokens tokens = VoteCode.objects.filter(event_id=int(sel_event_id)) # Render response return admin_render(request, "admin_kompomaatti/votecodes.html", { 'tokens': tokens, 'gentokensform': gentokensform, 'selected_event_id': int(sel_event_id), })
def edit(request, event_id): # Check for permissions if not request.user.has_perm('kompomaatti.change_event'): raise Http403 # Get event, or show 404 if it doesn't exist event = get_object_or_404(Event, pk=event_id) # Handle form data, if any if request.method == 'POST': eventform = EventForm(request.POST, instance=event) if eventform.is_valid(): data = eventform.save(commit=False) data.archived = False data.save() logger.info('Event "' + data.name + '" edited.', extra={'user': request.user}) return HttpResponseRedirect(reverse('manage-events:index')) else: eventform = EventForm(instance=event) # Render response return admin_render(request, "admin_events/edit.html", { 'eventform': eventform, })
def index(request, sel_event_id): # Post if request.method == 'POST': # Check for permissions if not request.user.has_perm('ext_blog.add_blogentry'): raise Http403 # Handle form form = BlogEntryForm(request.POST) if form.is_valid(): entry = form.save(commit=False) entry.event_id = int(sel_event_id) entry.date = timezone.now() entry.user = request.user entry.save() logger.info('Blog entry "' + entry.title + '" added.', extra={ 'user': request.user, 'event_id': sel_event_id }) return HttpResponseRedirect( reverse('manage-blog:index', args=(sel_event_id, ))) else: form = BlogEntryForm() # Get events entries = BlogEntry.objects.filter(event_id=sel_event_id) # Render response return admin_render( request, "admin_blog/index.html", { 'entries': entries, 'selected_event_id': int(sel_event_id), 'addform': form, })
def edit_item(request, item_id): if not request.user.has_perm('store.change_storeitem'): raise Http403 StoreItemFormSet = inlineformset_factory( parent_model=StoreItem, model=StoreItemVariant, form=StoreItemVariantForm, extra=3) # Get Item item = get_object_or_404(StoreItem, pk=item_id) # Handle form data if request.method == 'POST': variant_formset = StoreItemFormSet(request.POST, instance=item) item_form = StoreItemForm(request.POST, request.FILES, instance=item) if item_form.is_valid() and variant_formset.is_valid(): item_form.save() variant_formset.save() logger.info('Store Item "{}" edited.'.format(item.name), extra={'user': request.user}) return HttpResponseRedirect(reverse('manage-store:edit_item', args=(item.id,))) else: item_form = StoreItemForm(instance=item) variant_formset = StoreItemFormSet(instance=item) # Render response return admin_render(request, "admin_store/itemedit.html", { 'item_form': item_form, 'variant_formset': variant_formset })
def messages(request, sel_event_id): # Check for form data if request.method == 'POST': # Check for permissions if not request.user.has_perm('screenshow.add_message'): raise Http403 # Handle data messageform = MessageForm(request.POST) if messageform.is_valid(): data = messageform.save(commit=False) data.event_id = sel_event_id data.save() logger.info('Message added.', extra={'user': request.user, 'event_id': sel_event_id}) return HttpResponseRedirect(reverse('manage-screenshow:messages', args=(sel_event_id,))) else: messageform = MessageForm() # Get messages messages = Message.objects.filter(event_id=sel_event_id) # Dump template return admin_render(request, "admin_screenshow/messages.html", { 'selected_event_id': int(sel_event_id), 'messageform': messageform, 'messages': messages, })
def items(request): StoreItemFormSet = inlineformset_factory( parent_model=StoreItem, model=StoreItemVariant, form=StoreItemVariantForm, extra=5) # Handle form data if request.method == 'POST': if not request.user.has_perm('store.add_storeitem'): raise Http403 item_form = StoreItemForm(request.POST, request.FILES) variant_formset = StoreItemFormSet(request.POST, prefix="nested", instance=item_form.instance) if item_form.is_valid() and variant_formset.is_valid(): item = item_form.save() variant_formset.save() logger.info('Store Item "{}" added.'.format(item.name), extra={'user': request.user}) return HttpResponseRedirect(reverse('manage-store:items')) else: item_form = StoreItemForm() variant_formset = StoreItemFormSet(prefix="nested", instance=item_form.instance) # Get items m_items = StoreItem.objects.all() # Render response return admin_render(request, "admin_store/items.html", { 'items': m_items, 'item_form': item_form, 'variant_formset': variant_formset })
def config(request, sel_event_id): # Try to get configuration for event conf = None try: conf = ScreenConfig.objects.get(event_id=sel_event_id) except: pass # Handle post data if request.method == 'POST': # Check for permissions if not request.user.has_perm('screenshow.change_screenconfig'): raise Http403 # Handle form configform = ScreenConfigForm(request.POST, instance=conf) if configform.is_valid(): data = configform.save(commit=False) data.event_id = sel_event_id data.save() logger.info('Screenshow configuration changed.', extra={'user': request.user, 'event_id': sel_event_id}) return HttpResponseRedirect(reverse('manage-screenshow:config', args=(sel_event_id,))) else: configform = ScreenConfigForm(instance=conf) # Dump template contents return admin_render(request, "admin_screenshow/config.html", { 'selected_event_id': int(sel_event_id), 'configform': configform, })
def index(request, sel_event_id): # Create form if request.method == "POST": # Check rights if not request.user.has_perm('ext_programme.add_programmeevent'): raise Http403 # Handle form form = ProgrammeEventForm(request.POST, request.FILES) if form.is_valid(): data = form.save(commit=False) data.event_id = int(sel_event_id) data.save() logger.info('Programme event "{}" added.'.format(data.title), extra={ 'user': request.user, 'event_id': sel_event_id }) return HttpResponseRedirect( reverse('manage-programme:index', args=(sel_event_id, ))) else: form = ProgrammeEventForm() # Filter programme events by selected event pevs = ProgrammeEvent.objects.filter(event_id=int(sel_event_id)) # Render response return admin_render(request, "admin_programme/index.html", { 'pevs': pevs, 'selected_event_id': int(sel_event_id), 'eventform': form, })
def sponsor_edit(request, sel_event_id, sponsor_id): # Check for permissions if not request.user.has_perm('screenshow.change_sponsor'): raise Http403 # Get initial data sponsor = get_object_or_404(Sponsor, pk=sponsor_id) # Check for form data if request.method == 'POST': sponsorform = SponsorForm(request.POST, request.FILES, instance=sponsor) if sponsorform.is_valid(): s = sponsorform.save() logger.info('Sponsor "{}" edited.'.format(s.name), extra={'user': request.user, 'event_id': sel_event_id}) return HttpResponseRedirect(reverse('manage-screenshow:sponsors', args=(sel_event_id,))) else: sponsorform = SponsorForm(instance=sponsor) # Dump template return admin_render(request, "admin_screenshow/sponsor_edit.html", { 'selected_event_id': int(sel_event_id), 'sponsor_id': int(sponsor_id), 'sponsorform': sponsorform, })
def edit(request, sel_event_id, pev_id): # Check rights if not request.user.has_perm('ext_programme.change_programmeevent'): raise Http403 # Get event pev = get_object_or_404(ProgrammeEvent, pk=pev_id) # Create form if request.method == "POST": form = ProgrammeEventForm(request.POST, request.FILES, instance=pev) if form.is_valid(): data = form.save() logger.info('Programme event "{}" edited.'.format(data.title), extra={ 'user': request.user, 'event_id': sel_event_id }) return HttpResponseRedirect( reverse('manage-programme:index', args=(sel_event_id, ))) else: form = ProgrammeEventForm(instance=pev) # Render response return admin_render(request, "admin_programme/edit.html", { 'eventform': form, 'event': pev, 'selected_event_id': int(sel_event_id), })
def vids(request, sel_event_id): # Get event event = get_object_or_404(Event, pk=sel_event_id) # Handle form if request.method == "POST": # Check for permissions if not request.user.has_perm('arkisto.add_othervideo'): raise Http403 # Handle form vidform = VideoForm(request.POST, event=event) if vidform.is_valid(): video = vidform.save() logger.info('Added archive video {}'.format(video.name), extra={'user': request.user, 'event': event}) return HttpResponseRedirect(reverse('manage-arkisto:vids', args=(sel_event_id,))) else: vidform = VideoForm(event=event) # Get videos belonging to selected event categories = OtherVideoCategory.objects.filter(event_id=int(sel_event_id)) videos = [] for cat in categories: vlist = OtherVideo.objects.filter(category=cat) for video in vlist: videos.append(video) # Render response return admin_render(request, "admin_arkisto/vids.html", { 'videos': videos, 'vidform': vidform, 'selected_event_id': int(sel_event_id), })
def playlist_edit(request, sel_event_id, video_id): # Check for permissions if not request.user.has_perm('screenshow.change_playlistvideo'): raise Http403 # Get initial data playlist = get_object_or_404(PlaylistVideo, pk=video_id) # Check for form data if request.method == 'POST': playlistform = PlaylistVideoForm(request.POST, instance=playlist) if playlistform.is_valid(): v = playlistform.save() logger.info('Video "{}" edited on playlist.'.format(v.name), extra={'user': request.user, 'event_id': sel_event_id}) return HttpResponseRedirect(reverse('manage-screenshow:playlist', args=(sel_event_id,))) else: playlistform = PlaylistVideoForm(instance=playlist) # Dump template return admin_render(request, "admin_screenshow/playlist_edit.html", { 'selected_event_id': int(sel_event_id), 'video_id': int(video_id), 'playlistform': playlistform, })
def index(request, sel_event_id): # Post if request.method == 'POST': # Check for permissions if not request.user.has_perm('ext_blog.add_blogentry'): raise Http403 # Handle form form = BlogEntryForm(request.POST) if form.is_valid(): entry = form.save(commit=False) entry.event_id = int(sel_event_id) entry.date = datetime.now() entry.user = request.user entry.save() logger.info('Blog entry "'+entry.title+'" added.', extra={'user': request.user, 'event_id': sel_event_id}) return HttpResponseRedirect(reverse('manage-blog:index', args=(sel_event_id,))) else: form = BlogEntryForm() # Get events entries = BlogEntry.objects.filter(event_id = sel_event_id) # Render response return admin_render(request, "admin_blog/index.html", { 'entries': entries, 'selected_event_id': int(sel_event_id), 'addform': form, })
def competitions_browse(request, sel_event_id): # Get competitions competitions = Competition.objects.filter(event_id=int(sel_event_id)) # Form handling if request.method == "POST": # CHeck for permissions if not request.user.has_perm('kompomaatti.add_competition'): raise Http403 # Handle form competitionform = AdminCompetitionForm(request.POST) if competitionform.is_valid(): data = competitionform.save(commit=False) data.event_id = int(sel_event_id) data.save() logger.info('Competition "{}" added.'.format(data.name), extra={ 'user': request.user, 'event_id': sel_event_id }) return HttpResponseRedirect( reverse('manage-kompomaatti:competitions', args=(sel_event_id, ))) else: competitionform = AdminCompetitionForm() # Render response return admin_render( request, "admin_kompomaatti/competitions.html", { 'competitions': competitions, 'competitionform': competitionform, 'selected_event_id': int(sel_event_id), })
def competition_score(request, sel_event_id, competition_id): # Get competition competition = get_object_or_404(Competition, pk=competition_id) # Handle form if request.method == 'POST': # Check permissions if not request.user.has_perm('kompomaatti.change_competitionparticipation'): raise Http403 # Handle form scoreform = AdminCompetitionScoreForm(request.POST, competition=competition) if scoreform.is_valid(): scoreform.save() logger.info('Competition scores set.', extra={'user': request.user, 'event_id': sel_event_id}) return HttpResponseRedirect(reverse('manage-kompomaatti:competitions', args=(sel_event_id,))) else: scoreform = AdminCompetitionScoreForm(competition=competition) # Render response return admin_render(request, "admin_kompomaatti/competition_score.html", { 'competition': competition, 'scoreform': scoreform, 'selected_event_id': int(sel_event_id), })
def messages(request, sel_event_id): # Check for form data if request.method == 'POST': # Check for permissions if not request.user.has_perm('screenshow.add_message'): raise Http403 # Handle data messageform = MessageForm(request.POST) if messageform.is_valid(): data = messageform.save(commit=False) data.event_id = sel_event_id data.save() logger.info('Message added.', extra={ 'user': request.user, 'event_id': sel_event_id }) return HttpResponseRedirect( reverse('manage-screenshow:messages', args=(sel_event_id, ))) else: messageform = MessageForm() # Get messages messages = Message.objects.filter(event_id=sel_event_id) # Dump template return admin_render( request, "admin_screenshow/messages.html", { 'selected_event_id': int(sel_event_id), 'messageform': messageform, 'messages': messages, })
def entry_edit(request, sel_event_id, entry_id): # CHeck for permissions if not request.user.has_perm('kompomaatti.change_entry'): raise Http403 # Check ID entry = get_object_or_404(Entry, pk=entry_id) # Get event event = get_object_or_404(Event, pk=sel_event_id) # Handle form if request.method == "POST": editform = AdminEntryEditForm(request.POST, request.FILES, instance=entry, event=event) if editform.is_valid(): e = editform.save() logger.info('Compo entry "{}" edited.'.format(e.name), extra={'user': request.user, 'event_id': sel_event_id}) return HttpResponseRedirect(reverse('manage-kompomaatti:entries', args=(sel_event_id,))) else: editform = AdminEntryEditForm(instance=entry, event=event) # Render response return admin_render(request, "admin_kompomaatti/entry_edit.html", { 'entry': entry, 'editform': editform, 'selected_event_id': int(sel_event_id), })
def results(request, sel_event_id): # Get compos. competitions compos = Compo.objects.filter(event_id=int(sel_event_id)) competitions = Competition.objects.filter(event_id=int(sel_event_id)) # Get the entries compo_results = {} for compo in compos: compo_results[compo] = entrysort.sort_by_score(Entry.objects.filter(compo=compo)) # Get competition participations competition_results = {} for competition in competitions: rankby = '-score' if competition.score_sort == 1: rankby = 'score' competition_results[competition.name] = \ CompetitionParticipation.objects.filter(competition=competition).order_by(rankby) # Render response return admin_render(request, "admin_kompomaatti/results.html", { 'compo_results': compo_results, 'competition_results': competition_results, 'selected_event_id': int(sel_event_id), })
def results(request, sel_event_id): # Get compos. competitions compos = Compo.objects.filter(event_id=int(sel_event_id)) competitions = Competition.objects.filter(event_id=int(sel_event_id)) # Get the entries compo_results = {} for compo in compos: compo_results[compo] = entrysort.sort_by_score( Entry.objects.filter(compo=compo)) # Get competition participations competition_results = {} for competition in competitions: rankby = '-score' if competition.score_sort == 1: rankby = 'score' competition_results[competition.name] = \ CompetitionParticipation.objects.filter(competition=competition).order_by(rankby) # Render response return admin_render( request, "admin_kompomaatti/results.html", { 'compo_results': compo_results, 'competition_results': competition_results, 'selected_event_id': int(sel_event_id), })
def entry_browse(request, sel_event_id): # Get event event = get_object_or_404(Event, pk=sel_event_id) # Form handling if request.method == "POST": # CHeck for permissions if not request.user.has_perm('kompomaatti.add_entry'): raise Http403 # Handle form entryform = AdminEntryAddForm(request.POST, request.FILES, event=event) if entryform.is_valid(): e = entryform.save() logger.info('Compo entry "{}" added.'.format(e.name), extra={'user': request.user, 'event_id': sel_event_id}) return HttpResponseRedirect(reverse('manage-kompomaatti:entries', args=(sel_event_id,))) else: entryform = AdminEntryAddForm(event=event) # Get Entries compos = Compo.objects.filter(event=int(sel_event_id)) entries = Entry.objects.filter(compo__in=compos) # Render response return admin_render(request, "admin_kompomaatti/entry_browse.html", { 'entries': entries, 'entryform': entryform, 'selected_event_id': int(sel_event_id), })
def competition_participation_edit(request, sel_event_id, competition_id, pid): # CHeck for permissions if not request.user.has_perm('kompomaatti.change_competitionparticipation'): raise Http403 # Get competition, participation competition = get_object_or_404(Competition, pk=int(competition_id)) participant = get_object_or_404(CompetitionParticipation, pk=int(pid)) # Handle form if request.method == 'POST': pform = AdminParticipationEditForm(request.POST, instance=participant) if pform.is_valid(): pform.save() logger.info('Competition participation information edited.', extra={'user': request.user, 'event_id': sel_event_id}) return HttpResponseRedirect(reverse('manage-kompomaatti:participations', args=(sel_event_id, competition_id,))) else: pform = AdminParticipationEditForm(instance=participant) # Render response return admin_render(request, "admin_kompomaatti/participation_edit.html", { 'pform': pform, 'selected_event_id': int(sel_event_id), 'competition': competition, })
def competitions_browse(request, sel_event_id): # Get competitions competitions = Competition.objects.filter(event_id=int(sel_event_id)) # Form handling if request.method == "POST": # CHeck for permissions if not request.user.has_perm('kompomaatti.add_competition'): raise Http403 # Handle form competitionform = AdminCompetitionForm(request.POST) if competitionform.is_valid(): data = competitionform.save(commit=False) data.event_id = int(sel_event_id) data.save() logger.info('Competition "{}" added.'.format(data.name), extra={'user': request.user, 'event_id': sel_event_id}) return HttpResponseRedirect(reverse('manage-kompomaatti:competitions', args=(sel_event_id,))) else: competitionform = AdminCompetitionForm() # Render response return admin_render(request, "admin_kompomaatti/competitions.html", { 'competitions': competitions, 'competitionform': competitionform, 'selected_event_id': int(sel_event_id), })
def sponsor_edit(request, sel_event_id, sponsor_id): # Check for permissions if not request.user.has_perm('screenshow.change_sponsor'): raise Http403 # Get initial data sponsor = get_object_or_404(Sponsor, pk=sponsor_id) # Check for form data if request.method == 'POST': sponsorform = SponsorForm(request.POST, request.FILES, instance=sponsor) if sponsorform.is_valid(): s = sponsorform.save() logger.info('Sponsor "{}" edited.'.format(s.name), extra={ 'user': request.user, 'event_id': sel_event_id }) return HttpResponseRedirect( reverse('manage-screenshow:sponsors', args=(sel_event_id, ))) else: sponsorform = SponsorForm(instance=sponsor) # Dump template return admin_render( request, "admin_screenshow/sponsor_edit.html", { 'selected_event_id': int(sel_event_id), 'sponsor_id': int(sponsor_id), 'sponsorform': sponsorform, })
def playlist(request, sel_event_id): # Check for form data if request.method == 'POST': # Check for permissions if not request.user.has_perm('screenshow.add_playlistvideo'): raise Http403 # Handle data playlistform = PlaylistVideoForm(request.POST) if playlistform.is_valid(): data = playlistform.save(commit=False) data.event_id = sel_event_id data.save() logger.info('Video "{}" added to playlist.'.format(data.name), extra={ 'user': request.user, 'event_id': sel_event_id }) return HttpResponseRedirect( reverse('manage-screenshow:playlist', args=(sel_event_id, ))) else: playlistform = PlaylistVideoForm() # Get messages videos = PlaylistVideo.objects.filter( event_id=sel_event_id).order_by('-index') # Dump template return admin_render( request, "admin_screenshow/playlist.html", { 'selected_event_id': int(sel_event_id), 'videos': videos, 'playlistform': playlistform, })
def sponsors(request, sel_event_id): # Check for form data if request.method == 'POST': # Check for permissions if not request.user.has_perm('screenshow.add_sponsor'): raise Http403 # Handle data sponsorform = SponsorForm(request.POST, request.FILES) if sponsorform.is_valid(): data = sponsorform.save(commit=False) data.event_id = sel_event_id data.save() logger.info('Sponsor "{}" added.'.format(data.name), extra={ 'user': request.user, 'event_id': sel_event_id }) return HttpResponseRedirect( reverse('manage-screenshow:sponsors', args=(sel_event_id, ))) else: sponsorform = SponsorForm() # Get sponsors sponsors = Sponsor.objects.filter(event_id=sel_event_id) # Dump template return admin_render( request, "admin_screenshow/sponsors.html", { 'selected_event_id': int(sel_event_id), 'sponsorform': sponsorform, 'sponsors': sponsors, })
def message_edit(request, sel_event_id, message_id): # Check for permissions if not request.user.has_perm('screenshow.change_message'): raise Http403 # Get initial data message = get_object_or_404(Message, pk=message_id) # Check for form data if request.method == 'POST': messageform = MessageForm(request.POST, instance=message) if messageform.is_valid(): messageform.save() logger.info('Message edited.', extra={ 'user': request.user, 'event_id': sel_event_id }) return HttpResponseRedirect( reverse('manage-screenshow:messages', args=(sel_event_id, ))) else: messageform = MessageForm(instance=message) # Dump template return admin_render( request, "admin_screenshow/message_edit.html", { 'selected_event_id': int(sel_event_id), 'message_id': int(message_id), 'messageform': messageform, })
def config(request, sel_event_id): # Try to get configuration for event conf = None try: conf = ScreenConfig.objects.get(event_id=sel_event_id) except: pass # Handle post data if request.method == 'POST': # Check for permissions if not request.user.has_perm('screenshow.change_screenconfig'): raise Http403 # Handle form configform = ScreenConfigForm(request.POST, instance=conf) if configform.is_valid(): data = configform.save(commit=False) data.event_id = sel_event_id data.save() logger.info('Screenshow configuration changed.', extra={ 'user': request.user, 'event_id': sel_event_id }) return HttpResponseRedirect( reverse('manage-screenshow:config', args=(sel_event_id, ))) else: configform = ScreenConfigForm(instance=conf) # Dump template contents return admin_render(request, "admin_screenshow/config.html", { 'selected_event_id': int(sel_event_id), 'configform': configform, })
def compo_edit(request, sel_event_id, compo_id): # CHeck for permissions if not request.user.has_perm('kompomaatti.change_compo'): raise Http403 # Get compo compo = get_object_or_404(Compo, pk=compo_id) # Handle form if request.method == "POST": editform = AdminCompoForm(request.POST, instance=compo) if editform.is_valid(): c = editform.save() logger.info('Compo "{}" edited.'.format(c.name), extra={ 'user': request.user, 'event_id': sel_event_id }) return HttpResponseRedirect( reverse('manage-kompomaatti:compos', args=(sel_event_id, ))) else: editform = AdminCompoForm(instance=compo) # Render response return admin_render( request, "admin_kompomaatti/compo_edit.html", { 'compo': compo, 'editform': editform, 'selected_event_id': int(sel_event_id), })
def compo_edit(request, sel_event_id, compo_id): # CHeck for permissions if not request.user.has_perm('kompomaatti.change_compo'): raise Http403 # Get compo compo = get_object_or_404(Compo, pk=compo_id) # Handle form if request.method == "POST": editform = AdminCompoForm(request.POST, instance=compo) if editform.is_valid(): c = editform.save() logger.info('Compo "{}" edited.'.format(c.name), extra={'user': request.user, 'event_id': sel_event_id}) return HttpResponseRedirect(reverse('manage-kompomaatti:compos', args=(sel_event_id,))) else: editform = AdminCompoForm(instance=compo) # Render response return admin_render(request, "admin_kompomaatti/compo_edit.html", { 'compo': compo, 'editform': editform, 'selected_event_id': int(sel_event_id), })
def entry_browse(request, sel_event_id): # Get event event = get_object_or_404(Event, pk=sel_event_id) # Form handling if request.method == "POST": # CHeck for permissions if not request.user.has_perm('kompomaatti.add_entry'): raise Http403 # Handle form entryform = AdminEntryAddForm(request.POST, request.FILES, event=event) if entryform.is_valid(): e = entryform.save() logger.info('Compo entry "{}" added.'.format(e.name), extra={ 'user': request.user, 'event_id': sel_event_id }) return HttpResponseRedirect( reverse('manage-kompomaatti:entries', args=(sel_event_id, ))) else: entryform = AdminEntryAddForm(event=event) # Get Entries compos = Compo.objects.filter(event=int(sel_event_id)) entries = Entry.objects.filter(compo__in=compos) # Render response return admin_render( request, "admin_kompomaatti/entry_browse.html", { 'entries': entries, 'entryform': entryform, 'selected_event_id': int(sel_event_id), })
def slide_entries(request, sel_event_id, compo_id): # Get the compo c = get_object_or_404(Compo, pk=compo_id) # Get the entries s_entries = entrysort.sort_by_score(Entry.objects.filter(compo=c, disqualified=False)) i = 0 flip = False f_entries = [] for entry in s_entries: if flip: g = 180 else: g = 0 f_entries.append({ 'id': entry.id, 'creator': entry.creator, 'name': entry.name, 'x': 0, 'y': -i * 2500, 'z': 0, 'rot_y': 0, 'rot_x': g, 'rot_z': 0, }) i = i + 1 flip = not flip # Render return admin_render(request, 'admin_slides/slide_entries.html', { 'entries': f_entries, 'compo': c, 'last_y': - i * 2500, 'last_rot_x': flip, 'selected_event_id': int(sel_event_id), })
def edit_item(request, item_id): if not request.user.has_perm('store.change_storeitem'): raise Http403 StoreItemFormSet = inlineformset_factory(parent_model=StoreItem, model=StoreItemVariant, form=StoreItemVariantForm, extra=3) # Get Item item = get_object_or_404(StoreItem, pk=item_id) # Handle form data if request.method == 'POST': variant_formset = StoreItemFormSet(request.POST, instance=item) item_form = StoreItemForm(request.POST, request.FILES, instance=item) if item_form.is_valid() and variant_formset.is_valid(): item_form.save() variant_formset.save() logger.info('Store Item "{}" edited.'.format(item.name), extra={'user': request.user}) return HttpResponseRedirect( reverse('manage-store:edit_item', args=(item.id, ))) else: item_form = StoreItemForm(instance=item) variant_formset = StoreItemFormSet(instance=item) # Render response return admin_render(request, "admin_store/itemedit.html", { 'item_form': item_form, 'variant_formset': variant_formset })
def editfile(request, sel_event_id, file_id): # Check for permissions if not request.user.has_perm('admin_upload.change_uploadedfile'): raise Http403 # Get previously uploaded file uploadedfile = get_object_or_404(UploadedFile, pk=file_id) # Handle form data if request.method == 'POST': uploadform = UploadForm(request.POST, request.FILES, instance=uploadedfile) if uploadform.is_valid(): data = uploadform.save() logger.info('File "{}" edited.'.format(data.file.name), extra={ 'user': request.user, 'event_id': sel_event_id }) return HttpResponseRedirect( reverse('manage-uploads:index', args=(sel_event_id, ))) else: uploadform = UploadForm(instance=uploadedfile) # Render response return admin_render(request, "admin_upload/edit.html", { 'uploadform': uploadform, 'selected_event_id': int(sel_event_id), })
def index(request, sel_event_id): # Handle form data, if any if request.method == 'POST': # Check for permissions if not request.user.has_perm('admin_upload.add_uploadedfile'): raise Http403 # Handle form uploadform = UploadForm(request.POST, request.FILES) if uploadform.is_valid(): data = uploadform.save(commit=False) data.user = request.user data.date = timezone.now() data.event_id = int(sel_event_id) data.save() logger.info('File "{}" uploaded.'.format(data.file.name), extra={'user': request.user, 'event_id': sel_event_id}) return HttpResponseRedirect(reverse('manage-uploads:index', args=(sel_event_id,))) else: uploadform = UploadForm() # Get filelist files = UploadedFile.objects.filter(event_id=sel_event_id) # Render response return admin_render(request, "admin_upload/index.html", { 'files': files, 'uploadform': uploadform, 'selected_event_id': int(sel_event_id), })
def index(request, sel_event_id): # Handle form data, if any if request.method == 'POST': # Check for permissions if not request.user.has_perm('admin_upload.add_uploadedfile'): raise Http403 # Handle form uploadform = UploadForm(request.POST, request.FILES) if uploadform.is_valid(): data = uploadform.save(commit=False) data.user = request.user data.date = timezone.now() data.event_id = int(sel_event_id) data.save() logger.info('File "{}" uploaded.'.format(data.file.name), extra={ 'user': request.user, 'event_id': sel_event_id }) return HttpResponseRedirect( reverse('manage-uploads:index', args=(sel_event_id, ))) else: uploadform = UploadForm() # Get filelist files = UploadedFile.objects.filter(event_id=sel_event_id) # Render response return admin_render( request, "admin_upload/index.html", { 'files': files, 'uploadform': uploadform, 'selected_event_id': int(sel_event_id), })
def edit(request, sel_event_id, pev_id): # Check rights if not request.user.has_perm('ext_programme.change_programmeevent'): raise Http403 # Get event pev = get_object_or_404(ProgrammeEvent, pk=pev_id) # Create form if request.method == "POST": form = ProgrammeEventForm(request.POST, request.FILES, instance=pev) if form.is_valid(): data = form.save() logger.info('Programme event "{}" edited.'.format(data.title), extra={'user': request.user, 'event_id': sel_event_id}) return HttpResponseRedirect(reverse('manage-programme:index', args=(sel_event_id, ))) else: form = ProgrammeEventForm(instance=pev) # Render response return admin_render(request, "admin_programme/edit.html", { 'eventform': form, 'event': pev, 'selected_event_id': int(sel_event_id), })
def index(request, sel_event_id): # Create form if request.method == "POST": # Check rights if not request.user.has_perm('ext_programme.add_programmeevent'): raise Http403 # Handle form form = ProgrammeEventForm(request.POST, request.FILES) if form.is_valid(): data = form.save(commit=False) data.event_id = int(sel_event_id) data.save() logger.info('Programme event "{}" added.'.format(data.title), extra={'user': request.user, 'event_id': sel_event_id}) return HttpResponseRedirect(reverse('manage-programme:index', args=(sel_event_id, ))) else: form = ProgrammeEventForm() # Filter programme events by selected event pevs = ProgrammeEvent.objects.filter(event_id=int(sel_event_id)) # Render response return admin_render(request, "admin_programme/index.html", { 'pevs': pevs, 'selected_event_id': int(sel_event_id), 'eventform': form, })
def competition_score(request, sel_event_id, competition_id): # Get competition competition = get_object_or_404(Competition, pk=competition_id) # Handle form if request.method == 'POST': # Check permissions if not request.user.has_perm( 'kompomaatti.change_competitionparticipation'): raise Http403 # Handle form scoreform = AdminCompetitionScoreForm(request.POST, competition=competition) if scoreform.is_valid(): scoreform.save() logger.info('Competition scores set.', extra={ 'user': request.user, 'event_id': sel_event_id }) return HttpResponseRedirect( reverse('manage-kompomaatti:competitions', args=(sel_event_id, ))) else: scoreform = AdminCompetitionScoreForm(competition=competition) # Render response return admin_render( request, "admin_kompomaatti/competition_score.html", { 'competition': competition, 'scoreform': scoreform, 'selected_event_id': int(sel_event_id), })
def ircmessages(request, sel_event_id): # Get messages messages = IRCMessage.objects.filter(event_id=sel_event_id) # Dump template return admin_render(request, "admin_screenshow/ircmessages.html", { 'selected_event_id': int(sel_event_id), 'messages': messages, })
def votecoderequests(request, sel_event_id): # Get all requests requests = VoteCodeRequest.objects.filter(event_id=int(sel_event_id, )) # Render response return admin_render(request, "admin_kompomaatti/vcrequests.html", { 'requests': requests, 'selected_event_id': int(sel_event_id), })
def ticket_votecodes(request, sel_event_id): # Get tokens tokens = TicketVoteCode.objects.filter(event_id=sel_event_id) # Render response return admin_render(request, "admin_kompomaatti/ticketvotecodes.html", { 'tokens': tokens, 'selected_event_id': int(sel_event_id), })