def add_presentation(request, presentation_id=None): if presentation_id: presentation = get_object_or_404(Presentation, pk=presentation_id) success = False title = "" description = "" new_presentation = None if request.method == "POST": presentation_form = PresentationForm(request.POST) if presentation_form.is_valid(): title = presentation_form.cleaned_data['title'] description = presentation_form.cleaned_data['description'] new_presentation = Presentation() new_presentation.title = title new_presentation.description = description new_presentation.save() success = True else: presentation_form = PresentationForm() ctx = { 'presentation_form': presentation_form, 'title': title, 'description': description, 'success': success, 'presentation': new_presentation, } return render_to_response('presentation/add_presentation.html', ctx)
def post(self, request): presentation_converted = PresentationHandler(request.POST, request.FILES) presentation = Presentation(title=presentation_converted.title, presentation=presentation_converted.path['presentation']) presentation.save() for i in range(len(presentation_converted.path['images'])): presentation.presentationimages_set.add(PresentationImages(image=presentation_converted.path['images'][i], image_min = presentation_converted.path['thumbnail'][i])) presentation.save() return HttpResponseRedirect(reverse('upload_presentation'))
def password(request, id, name): presentation = get_object_or_404( filter_by_access(request.user, Presentation).filter( Presentation.published_Q(request.user), id=id)) class PasswordForm(forms.Form): password = forms.CharField(widget=forms.PasswordInput) def clean_password(self): p = self.cleaned_data.get('password') if p != presentation.password: raise forms.ValidationError("Password is not correct.") return p if request.method == 'POST': form = PasswordForm(request.POST) if form.is_valid(): request.session.setdefault('passwords', dict())[presentation.id] = form.cleaned_data.get('password') request.session.modified = True return HttpResponseRedirect(request.GET.get('next', reverse('presentation-browse'))) else: form = PasswordForm() return render_to_response('presentation_password.html', {'form': form, 'presentation': presentation, 'next': request.GET.get('next', reverse('presentation-browse')), }, context_instance=RequestContext(request))
def new_presentation(course_id): course = Course.query.get(course_id) if request.method == "POST": name = request.form.get('name', None) display_at = request.form.get('display-at', None) file_ = request.files.get('file', None) if name and display_at and file_: filename = presentations.save(file_) presentation = Presentation( name=name, filename=filename, course_id=course.id) presentation.display_at = parse(display_at) course.add_presentation(presentation) db.session.add(presentation) db.session.commit() return redirect(url_for('list_presentations', course_id=course_id)) return render_template('presentation/new.html', course=course)
def password(request, id, name): presentation = get_object_or_404( filter_by_access(request.user, Presentation).filter( Presentation.published_q(request.user), id=id)) class PasswordForm(forms.Form): password = forms.CharField(widget=forms.PasswordInput) def clean_password(self): p = self.cleaned_data.get('password') if p != presentation.password: raise forms.ValidationError("Password is not correct.") return p if request.method == 'POST': form = PasswordForm(request.POST) if form.is_valid(): request.session.setdefault( 'passwords', dict())[presentation.id] = form.cleaned_data.get('password') request.session.modified = True return HttpResponseRedirect( request.GET.get('next', reverse('presentation-browse'))) else: form = PasswordForm() return render_to_response( 'presentation_password.html', { 'form': form, 'presentation': presentation, 'next': request.GET.get('next', reverse('presentation-browse')), }, context_instance=RequestContext(request))
def new_presentation(course_id): course = Course.query.get(course_id) if request.method == "POST": name = request.form.get('name', None) display_at = request.form.get('display-at', None) file_ = request.files.get('file', None) if name and display_at and file_: filename = presentations.save(file_) presentation = Presentation(name=name, filename=filename, course_id=course.id) presentation.display_at = parse(display_at) course.add_presentation(presentation) db.session.add(presentation) db.session.commit() return redirect(url_for('list_presentations', course_id=course_id)) return render_template('presentation/new.html', course=course)
def _get_presentation(obj, request, objid): if obj: if not isinstance(obj, Presentation): return None else: obj = Presentation.get_by_id_for_request(objid, request) if not obj: return None return obj
def post(self, key): presentation_filename = self.request.get("presentation_filename") speaker = Speaker() speaker.full_name = self.request.get("full_name") speaker.designation = self.request.get("designation") speaker.organization = self.request.get("organization") speaker.department = self.request.get("department") speaker.organization_website = self.request.get("organization_website") speaker.city = self.request.get("city") speaker.email = self.request.get("email") speaker.mobile_number = self.request.get("mobile_number") speaker.research_topic = self.request.get("research_topic") speaker.bio_sketch = self.request.get("bio_sketch") if presentation_filename: presentation = Presentation() presentation.filename = self.request.get("presentation_filename") presentation.content = db.Blob(self.request.get("presentation")) presentation.extension = splitext(presentation_filename)[1] presentation.put() speaker.presentation_file = presentation speaker.put() queue_mail_task( url="/worker/mail/thanks/speaker_nomination/", params=dict(full_name=speaker.full_name, email=speaker.email, key=str(speaker.key())), method="POST", ) self.response.out.write(speaker.to_json("full_name", "is_starred", "is_deleted", "is_active"))
def raw_manifest(request, id, name, offline=False): p = Presentation.get_by_id_for_request(id, request) if not p: return dict(result='error') owner = request.user if request.user.is_authenticated() else None slides = p.items.select_related('record').filter(hidden=False) return { '@context': reverse(manifest, kwargs=dict(id=p.id, name=p.name)), '@type': 'sc:Manifest', '@id': get_id(request, 'presentation', 'presentation%d' % p.id, 'manifest'), 'label': p.title, 'metadata': [], 'description': p.description, 'sequences': [{ '@id': get_id(request, 'presentation', 'presentation%d' % p.id, 'all'), '@type': 'sc:Range', 'label': 'All slides', 'canvases': [ slide_manifest( request, slide, owner, offline=offline, ) for slide in slides ] + [ special_slide( request, kind='blank', label='End of presentation', offline=offline, ) ] }], }
def post(self): from models import Presentation host_info = get_host_info(self.request) host_info.put() presentation_filename = self.request.get('presentation_filename') presentation = self.request.get('presentation') speaker = Speaker() speaker.full_name = self.request.get('full_name') speaker.designation = self.request.get('designation') speaker.organization = self.request.get('organization') speaker.department = self.request.get('department') speaker.organization_website = self.request.get('organization_website') speaker.city = self.request.get('city') speaker.email = self.request.get('email') speaker.mobile_number = self.request.get('mobile_number') speaker.research_topic = self.request.get('research_topic') speaker.bio_sketch = self.request.get('bio_sketch') speaker.host_info = host_info #if presentation_filename: # speaker.presentation = db.Blob(presentation) # speaker.presentation_filename = presentation_filename # speaker.presentation_extension = splitext(presentation_filename)[1] if presentation_filename: speaker_presentation = Presentation() speaker_presentation.filename = presentation_filename speaker_presentation.extension = splitext(presentation_filename)[1] speaker_presentation.content = db.Blob(presentation) speaker_presentation.put() speaker.presentation = speaker_presentation speaker.put() queue_mail_task(url='/worker/mail/thanks/speaker_nomination/', params=dict( full_name=speaker.full_name, email = speaker.email, key=str(speaker.key()) ), method='POST' ) response = render_template('thank_you.html', message_title='Thank you for nominating a speaker.', message_body='We appreciate your taking the time to nominating a speaker. We will get in touch with you soon') self.response.out.write(response)
def add_presentation(): teams = Team.query.all() if not teams: return render_template("no_teams.html") form = PresentationForm() form.team_id.choices = [(t.id, t.number) for t in sortTeamsWithPlaceholder(teams)] # Gather and preset the team ID field if provided in URL preselected_team = request.args.get('team_id', default=None, type=int) if preselected_team is not None: form.team_id.data = preselected_team repeat = request.args.get('repeat', default=False, type=bool) if request.method == 'POST' and request.form['end'] == 'reset': return redirect(url_for(".add_presentation", repeat=True)) elif request.method == 'POST' and request.form[ 'end'] == 'submit' and form.validate_on_submit(): presentation = Presentation() form.populate_obj(presentation) db.session.add(presentation) db.session.commit() if repeat: flash( 'Added presentation score for %s' % (presentation.team.number), 'success') return redirect(url_for(".add_presentation", repeat=True)) else: return redirect(url_for("review")) elif request.method == 'POST': flash('Failed validation', 'danger alert-auto-dismiss') return render_template("judging/presentation_form.html", form=form, id=None, repeat=repeat)
def browse(request, manage=False): if manage and not request.user.is_authenticated(): raise Http404() if request.user.is_authenticated() and not request.GET.items(): # retrieve past settings qs = load_settings(request.user, filter='presentation_browse_querystring') if qs.has_key('presentation_browse_querystring'): return HttpResponseRedirect('%s?%s' % ( reverse('presentation-manage' if manage else 'presentation-browse'), qs['presentation_browse_querystring'][0], )) presenter = request.GET.get('presenter') tags = filter(None, request.GET.getlist('t')) untagged = 1 if request.GET.get('ut') else 0 if untagged: tags = [] remove_tag = request.GET.get('rt') if remove_tag and remove_tag in tags: tags.remove(remove_tag) keywords = request.GET.get('kw', '') get = request.GET.copy() get.setlist('t', tags) if get.has_key('rt'): del get['rt'] if untagged: get['ut'] = '1' elif get.has_key('ut'): del get['ut'] if request.user.is_authenticated(): existing_tags = Tag.objects.usage_for_model(OwnedWrapper, filters=dict(user=request.user, content_type=OwnedWrapper.t(Presentation))) else: existing_tags = () if untagged and request.user.is_authenticated(): qs = TaggedItem.objects.filter(content_type=OwnedWrapper.t(OwnedWrapper)).values('object_id').distinct() qs = OwnedWrapper.objects.filter(user=request.user, content_type=OwnedWrapper.t(Presentation), id__in=qs).values('object_id') q = ~Q(id__in=qs) elif tags: qs = OwnedWrapper.objects.filter(content_type=OwnedWrapper.t(Presentation)) # get list of matching IDs for each individual tag, since tags may be attached by different owners ids = [list(TaggedItem.objects.get_by_model(qs, '"%s"' % tag).values_list('object_id', flat=True)) for tag in tags] q = Q(*(Q(id__in=x) for x in ids)) else: q = Q() if presenter: presenter = User.objects.get(username=presenter) qp = Q(owner=presenter) else: qp = Q() if keywords: qk = Q(*(Q(title__icontains=kw) | Q(description__icontains=kw) | Q(owner__last_name__icontains=kw) | Q(owner__first_name__icontains=kw) | Q(owner__username__icontains=kw) for kw in keywords.split())) else: qk = Q() if manage: qv = Q() presentations = filter_by_access(request.user, Presentation, write=True, manage=True) else: qv = Presentation.published_Q() presentations = filter_by_access(request.user, Presentation ) presentations = presentations.select_related('owner').filter(q, qp, qk, qv).order_by('title') if request.method == "POST": if manage and (request.POST.get('hide') or request.POST.get('unhide')) and request.user.has_perm('presentation.publish_presentations'): hide = request.POST.get('hide') or False ids = map(int, request.POST.getlist('h')) for presentation in Presentation.objects.filter(owner=request.user, id__in=ids): presentation.hidden = hide presentation.save() if manage and request.POST.get('delete'): ids = map(int, request.POST.getlist('h')) Presentation.objects.filter(owner=request.user, id__in=ids).delete() get['kw'] = request.POST.get('kw') if get['kw'] != request.POST.get('okw') and get.has_key('page'): # user entered keywords, reset page counter del get['page'] if request.POST.get('update_tags'): ids = map(int, request.POST.getlist('h')) update_actionbar_tags(request, *presentations.filter(id__in=ids)) # check for clicks on "add selected items" buttons for button in filter(lambda k: k.startswith('add-selected-items-'), request.POST.keys()): id = int(button[len('add-selected-items-'):]) presentation = get_object_or_404( filter_by_access(request.user, Presentation, write=True, manage=True).filter(id=id)) add_selected_items(request, presentation) return HttpResponseRedirect(reverse('presentation-edit', args=(presentation.id, presentation.name))) return HttpResponseRedirect(request.path + '?' + get.urlencode()) active_tags = tags active_presenter = presenter def col(model, field): qn = backend.DatabaseOperations().quote_name return '%s.%s' % (qn(model._meta.db_table), qn(model._meta.get_field(field).column)) if presentations and not manage: q = OwnedWrapper.objects.extra( tables=(Presentation._meta.db_table,), where=('%s=%s' % (col(OwnedWrapper, 'object_id'), col(Presentation, 'id')), '%s=%s' % (col(OwnedWrapper, 'user'), col(Presentation, 'owner')))).filter( object_id__in=presentations.values('id'), content_type=OwnedWrapper.t(Presentation)) tags = Tag.objects.usage_for_queryset(q, counts=True) for p in presentations: p.verify_password(request) else: tags = () if presentations and request.user.is_authenticated(): usertags = Tag.objects.usage_for_queryset(OwnedWrapper.objects.filter( user=request.user, object_id__in=presentations.values('id'), content_type=OwnedWrapper.t(Presentation)), counts=True) else: usertags = () presenters = User.objects.filter(presentation__in=presentations) \ .annotate(presentations=Count('presentation')).order_by('last_name', 'first_name') if request.user.is_authenticated() and presentations: # save current settings querystring = request.GET.urlencode() store_settings(request.user, 'presentation_browse_querystring', querystring) return render_to_response('presentation_browse.html', {'manage': manage, 'tags': tags if len(tags) > 0 else None, 'untagged': untagged, 'usertags': usertags if len(usertags) > 0 else None, 'active_tags': active_tags, 'active_presenter': presenter, 'presentations': presentations, 'presenters': presenters if len(presenters) > 1 else None, 'keywords': keywords, }, context_instance=RequestContext(request))
def browse(request, manage=False): if manage and not request.user.is_authenticated(): raise Http404() if request.user.is_authenticated() and not request.GET.items(): # retrieve past settings qs = load_settings(request.user, filter="presentation_browse_querystring") if qs.has_key("presentation_browse_querystring"): return HttpResponseRedirect( "%s?%s" % ( reverse("presentation-manage" if manage else "presentation-browse"), qs["presentation_browse_querystring"][0], ) ) presenter = request.GET.get("presenter") tags = filter(None, request.GET.getlist("t")) sortby = request.GET.get("sortby") if not sortby in ("title", "created", "modified"): sortby = "title" untagged = 1 if request.GET.get("ut") else 0 if untagged: tags = [] remove_tag = request.GET.get("rt") if remove_tag and remove_tag in tags: tags.remove(remove_tag) keywords = request.GET.get("kw", "") get = request.GET.copy() get.setlist("t", tags) if get.has_key("rt"): del get["rt"] if untagged: get["ut"] = "1" elif get.has_key("ut"): del get["ut"] if request.user.is_authenticated(): existing_tags = Tag.objects.usage_for_model( OwnedWrapper, filters=dict(user=request.user, content_type=OwnedWrapper.t(Presentation)) ) else: existing_tags = () if untagged and request.user.is_authenticated(): qs = TaggedItem.objects.filter(content_type=OwnedWrapper.t(OwnedWrapper)).values("object_id").distinct() qs = OwnedWrapper.objects.filter( user=request.user, content_type=OwnedWrapper.t(Presentation), id__in=qs ).values("object_id") q = ~Q(id__in=qs) elif tags: qs = OwnedWrapper.objects.filter(content_type=OwnedWrapper.t(Presentation)) # get list of matching IDs for each individual tag, since tags may be attached by different owners ids = [ list(TaggedItem.objects.get_by_model(qs, '"%s"' % tag).values_list("object_id", flat=True)) for tag in tags ] q = Q(*(Q(id__in=x) for x in ids)) else: q = Q() if presenter: presenter = User.objects.get(username=presenter) qp = Q(owner=presenter) else: qp = Q() if keywords: qk = Q( *( Q(title__icontains=kw) | Q(description__icontains=kw) | Q(owner__last_name__icontains=kw) | Q(owner__first_name__icontains=kw) | Q(owner__username__icontains=kw) for kw in keywords.split() ) ) else: qk = Q() if manage: qv = Q() presentations = filter_by_access(request.user, Presentation, write=True, manage=True) else: qv = Presentation.published_Q() presentations = filter_by_access(request.user, Presentation) presentations = presentations.select_related("owner").filter(q, qp, qk, qv) presentations = presentations.order_by("-" + sortby if sortby != "title" else sortby) if request.method == "POST": if ( manage and (request.POST.get("hide") or request.POST.get("unhide")) and request.user.has_perm("presentation.publish_presentations") ): hide = request.POST.get("hide") or False ids = map(int, request.POST.getlist("h")) for presentation in Presentation.objects.filter(owner=request.user, id__in=ids): presentation.hidden = hide presentation.save() if manage and request.POST.get("delete"): ids = map(int, request.POST.getlist("h")) Presentation.objects.filter(owner=request.user, id__in=ids).delete() get["kw"] = request.POST.get("kw") if get["kw"] != request.POST.get("okw") and get.has_key("page"): # user entered keywords, reset page counter del get["page"] if request.POST.get("update_tags"): ids = map(int, request.POST.getlist("h")) update_actionbar_tags(request, *presentations.filter(id__in=ids)) # check for clicks on "add selected items" buttons for button in filter(lambda k: k.startswith("add-selected-items-"), request.POST.keys()): id = int(button[len("add-selected-items-") :]) presentation = get_object_or_404( filter_by_access(request.user, Presentation, write=True, manage=True).filter(id=id) ) add_selected_items(request, presentation) return HttpResponseRedirect(reverse("presentation-edit", args=(presentation.id, presentation.name))) return HttpResponseRedirect(request.path + "?" + get.urlencode()) active_tags = tags active_presenter = presenter def col(model, field): qn = backend.DatabaseOperations().quote_name return "%s.%s" % (qn(model._meta.db_table), qn(model._meta.get_field(field).column)) if presentations and not manage: q = OwnedWrapper.objects.extra( tables=(Presentation._meta.db_table,), where=( "%s=%s" % (col(OwnedWrapper, "object_id"), col(Presentation, "id")), "%s=%s" % (col(OwnedWrapper, "user"), col(Presentation, "owner")), ), ).filter(object_id__in=presentations.values("id"), content_type=OwnedWrapper.t(Presentation)) tags = Tag.objects.usage_for_queryset(q, counts=True) for p in presentations: p.verify_password(request) else: tags = () if presentations and request.user.is_authenticated(): usertags = Tag.objects.usage_for_queryset( OwnedWrapper.objects.filter( user=request.user, object_id__in=presentations.values("id"), content_type=OwnedWrapper.t(Presentation) ), counts=True, ) else: usertags = () presenters = ( User.objects.filter(presentation__in=presentations) .annotate(presentations=Count("presentation")) .order_by("last_name", "first_name") ) if request.user.is_authenticated() and presentations: # save current settings querystring = request.GET.urlencode() store_settings(request.user, "presentation_browse_querystring", querystring) return render_to_response( "presentation_browse.html", { "manage": manage, "tags": tags if len(tags) > 0 else None, "untagged": untagged, "usertags": usertags if len(usertags) > 0 else None, "active_tags": active_tags, "active_presenter": presenter, "presentations": presentations, "presenters": presenters if len(presenters) > 1 else None, "keywords": keywords, "sortby": sortby, }, context_instance=RequestContext(request), )
def browse(request, manage=False): if manage and not request.user.is_authenticated(): raise Http404() if request.user.is_authenticated() and not request.GET.items(): # retrieve past settings qs = load_settings(request.user, filter='presentation_browse_querystring') if 'presentation_browse_querystring' in qs: # Don't restore the "untagged only" setting, as it confuses # a lot of users args = qs['presentation_browse_querystring'][0] args = '&'.join(p for p in args.split('&') if not p.startswith('ut=')) return HttpResponseRedirect('%s?%s' % ( reverse('presentation-manage' if manage else 'presentation-browse'), args, )) presenter = request.GET.get('presenter') tags = filter(None, request.GET.getlist('t')) sortby = request.GET.get('sortby') if sortby not in ('title', 'created', 'modified'): sortby = 'title' untagged = 1 if request.GET.get('ut') else 0 if untagged: tags = [] remove_tag = request.GET.get('rt') if remove_tag and remove_tag in tags: tags.remove(remove_tag) keywords = request.GET.get('kw', '') get = request.GET.copy() get.setlist('t', tags) if 'rt' in get: del get['rt'] if untagged: get['ut'] = '1' elif 'ut' in get: del get['ut'] if untagged and request.user.is_authenticated(): qs = TaggedItem.objects.filter(content_type=OwnedWrapper.t( OwnedWrapper)).values('object_id').distinct() qs = OwnedWrapper.objects.filter( user=request.user, content_type=OwnedWrapper.t(Presentation), id__in=qs).values('object_id') q = ~Q(id__in=qs) elif tags: qs = OwnedWrapper.objects.filter( content_type=OwnedWrapper.t(Presentation)) # get list of matching IDs for each individual tag, since tags # may be attached by different owners ids = [ list( TaggedItem.objects.get_by_model(qs, '"%s"' % tag).values_list( 'object_id', flat=True)) for tag in tags ] q = Q(*(Q(id__in=x) for x in ids)) else: q = Q() if presenter: presenter = User.objects.get(username=presenter) qp = Q(owner=presenter) else: qp = Q() if keywords: qk = Q(*(Q(title__icontains=kw) | Q(description__icontains=kw) | Q(owner__last_name__icontains=kw) | Q(owner__first_name__icontains=kw) | Q(owner__username__icontains=kw) for kw in keywords.split())) else: qk = Q() if manage: qv = Q() presentations = filter_by_access(request.user, Presentation, write=True, manage=True) else: qv = Presentation.published_q() presentations = filter_by_access(request.user, Presentation) presentations = presentations.select_related('owner').filter(q, qp, qk, qv) presentations = presentations.order_by( '-' + sortby if sortby != 'title' else sortby) if request.method == "POST": if manage and ( request.POST.get('hide') or request.POST.get('unhide') ) and request.user.has_perm('presentation.publish_presentations'): hide = request.POST.get('hide') or False ids = map(int, request.POST.getlist('h')) for presentation in Presentation.objects.filter(owner=request.user, id__in=ids): presentation.hidden = hide presentation.save() if manage and request.POST.get('delete'): ids = map(int, request.POST.getlist('h')) Presentation.objects.filter(owner=request.user, id__in=ids).delete() get['kw'] = request.POST.get('kw') if get['kw'] != request.POST.get('okw') and 'page' in get: # user entered keywords, reset page counter del get['page'] if request.POST.get('update_tags'): ids = map(int, request.POST.getlist('h')) update_actionbar_tags(request, *presentations.filter(id__in=ids)) # check for clicks on "add selected items" buttons for button in filter(lambda k: k.startswith('add-selected-items-'), request.POST.keys()): id = int(button[len('add-selected-items-'):]) presentation = get_object_or_404( filter_by_access(request.user, Presentation, write=True, manage=True).filter(id=id)) add_selected_items(request, presentation) return HttpResponseRedirect( reverse('presentation-edit', args=(presentation.id, presentation.name))) return HttpResponseRedirect(request.path + '?' + get.urlencode()) active_tags = tags def col(model, field): qn = connection.ops.quote_name return '%s.%s' % (qn( model._meta.db_table), qn(model._meta.get_field(field).column)) if presentations: q = OwnedWrapper.objects.extra( tables=(Presentation._meta.db_table, ), where=('%s=%s' % (col(OwnedWrapper, 'object_id'), col(Presentation, 'id')), '%s=%s' % (col(OwnedWrapper, 'user'), col(Presentation, 'owner')))).filter( object_id__in=presentations.values('id'), content_type=OwnedWrapper.t(Presentation)) tags = Tag.objects.usage_for_queryset(q, counts=True) if not manage: for p in presentations: p.verify_password(request) else: tags = () if presentations and request.user.is_authenticated(): usertags = Tag.objects.usage_for_queryset(OwnedWrapper.objects.filter( user=request.user, object_id__in=presentations.values('id'), content_type=OwnedWrapper.t(Presentation)), counts=True) else: usertags = () presenters = User.objects.filter(presentation__in=presentations) \ .annotate(presentations=Count('presentation')) \ .order_by('last_name', 'first_name') if request.user.is_authenticated() and presentations: # save current settings querystring = request.GET.urlencode() store_settings(request.user, 'presentation_browse_querystring', querystring) return render_to_response( 'presentation_browse.html', { 'manage': manage, 'tags': tags if len(tags) > 0 else None, 'untagged': untagged, 'usertags': usertags if len(usertags) > 0 else None, 'active_tags': active_tags, 'active_presenter': presenter, 'presentations': presentations, 'presenters': presenters if len(presenters) > 1 else None, 'keywords': keywords, 'sortby': sortby, }, context_instance=RequestContext(request))