def production_edit_cast(request, play_id, play, production_id): """For picking someone to edit, or adding a new Part""" try: production = check_parameters(play_id, play, production_id) except UnmatchingSlugException as e: return HttpResponsePermanentRedirect(e.args[0].get_edit_cast_url()) initial = {'production': production} if request.GET.get('person'): initial['person'] = Person.objects.get( id=base32_to_int(request.GET.get('person'))) part_form = PartForm(data=request.POST or None, editing=False, initial=initial) if request.method == 'POST': if part_form.is_valid(): part_form.instance.production = production part_form.save() messages.success(request, "Your new part has been added; thank you.") return HttpResponseRedirect(production.get_edit_cast_url()) return render( request, 'productions/edit-parts.html', { 'production': production, 'places': production.place_set_ordered(), 'form': part_form, 'parts': production.part_set.order_by('-cast', 'order', 'role', 'person__last_name', 'person__first_name'), })
def view(request, photo_id): photo_id = base32_to_int(photo_id) photo = get_object_or_404(Photo, id=photo_id) next_photo = Photo.objects.filter(id__gt=photo.id) if next_photo: next_photo = next_photo[0] previous_photo = Photo.objects.filter(id__lt=photo.id).order_by('-id') if previous_photo: previous_photo = previous_photo[0] attached_title = 'Unknown' if isinstance(photo.content_object, Production): attached_title = photo.content_object.play.get_title_display() elif isinstance(photo.content_object, Play): attached_title = photo.content_object.get_title_display() elif isinstance(photo.content_object, Place): attached_title = str(photo.content_object) elif isinstance(photo.content_object, Person): attached_title = str(photo.content_object) return render(request, 'photos/view.html', { 'photo': photo, 'next_photo': next_photo, 'previous_photo': previous_photo, 'attached_title': attached_title, })
def check_url(type, id, slug=None): mistyped = False try: id = base32_to_int(id) except MistypedIDException, e: mistyped = True id = e.args[0]
def view(request, photo_id): photo_id = base32_to_int(photo_id) photo = get_object_or_404(Photo, id=photo_id) next_photo = Photo.objects.filter(id__gt=photo.id) if next_photo: next_photo = next_photo[0] previous_photo = Photo.objects.filter(id__lt=photo.id).order_by('-id') if previous_photo: previous_photo = previous_photo[0] attached_title = 'Unknown' if isinstance(photo.content_object, Production): attached_title = photo.content_object.play.get_title_display() elif isinstance(photo.content_object, Play): attached_title = photo.content_object.get_title_display() elif isinstance(photo.content_object, Place): attached_title = str(photo.content_object) elif isinstance(photo.content_object, Person): attached_title = str(photo.content_object) return render( request, 'photos/view.html', { 'photo': photo, 'next_photo': next_photo, 'previous_photo': previous_photo, 'attached_title': attached_title, })
def confirm(request, id, token): try: id = base32_to_int(id) except ValueError: raise Http404 confirmation = get_object_or_404(EmailConfirmation, id=id) if confirmation.check_token(token): confirmation.confirmed = True confirmation.save() return HttpResponseRedirect(confirmation.url_after_confirm()) return HttpResponseRedirect('/')
def check_token(self, token): try: rand, hash = token.split("-") except: return False try: rand = base32_to_int(rand) except: return False if self.make_token(rand) != token: return False return True
def register_confirm(request, uidb32, token): try: uid_int = base32_to_int(uidb32) except ValueError: raise Http404 user = get_object_or_404(User, id=uid_int) if default_token_generator.check_token(user, token): p = user.profile p.email_validated = True p.save() perform_login(request, user) # Decide what to do with someone confirming registration return render(request, 'registration/validated.html', { 'user': user, }) return HttpResponseRedirect('/')
def register_confirm(request, uidb32, token): try: uid_int = base32_to_int(uidb32) except ValueError: raise Http404 user = get_object_or_404(User, id=uid_int) if default_token_generator.check_token(user, token): p = user.get_profile() p.email_validated = True p.save() perform_login(request, user) # Decide what to do with someone confirming registration return render(request, 'registration/validated.html', { 'user': user, }) return HttpResponseRedirect('/')
def check_url(type, id, slug=None): mistyped = False try: id = base32_to_int(id) except MistypedIDException as e: mistyped = True id = e.args[0] except: raise Http404('Could not match id %s' % id) try: obj = type.objects.get(id=id) except type.DoesNotExist: content_type = ContentType.objects.get_for_model(type) try: redir = Redirect.objects.get(old_object_id=id, content_type=content_type) obj = redir.new_object mistyped = True except Redirect.DoesNotExist: raise Http404('No %s matches the given query.' % type._meta.object_name) if (slug is not None and obj.slug != slug) or mistyped: raise UnmatchingSlugException(obj) return obj
def get(self, **kwargs): b32 = kwargs.pop('Bid', None) if b32: kwargs['id'] = base32_to_int(b32) return super(PlaceManager, self).get(**kwargs)
'place_formset': place_formset, 'companies_formset': companies_formset, 'production': production, 'places': production.place_set.order_by('start_date', 'press_date'), }) @login_required def production_edit_cast(request, play_id, play, production_id): """For picking someone to edit, or adding a new Part""" try: production = check_parameters(play_id, play, production_id) except UnmatchingSlugException, e: return HttpResponsePermanentRedirect(e.args[0].get_edit_cast_url()) initial = { 'production': production } if request.GET.get('person'): initial['person'] = Person.objects.get(id=base32_to_int(request.GET.get('person'))) part_form = PartForm(data=request.POST or None, editing=False, initial=initial) if request.method == 'POST': if part_form.is_valid(): part_form.instance.production = production part_form.save() messages.success(request, "Your new part has been added; thank you.") return HttpResponseRedirect(production.get_edit_cast_url()) return render(request, 'productions/edit-parts.html', { 'production': production, 'places': production.place_set.order_by('start_date', 'press_date'), 'form': part_form, 'parts': production.part_set.order_by('-cast', 'order', 'role', 'person__last_name', 'person__first_name'), })
def get_person(name): m = re.match('(.*?); (.*)$', name) if m: first_name, last_name = m.group(2), m.group(1) name = '%s %s' % (first_name, last_name) else: first_name, last_name = '', name year = None m = re.match('(.*) \((\d+)\s*-', first_name) if m: first_name, year = m.groups() m = re.match('(.*) \(\s*-', first_name) if m: first_name = m.group(1) first_name = re.sub('(Sir|Lord|Dame);', r'\1', first_name) first_name = first_name.decode('iso-8859-1') last_name = last_name.decode('iso-8859-1') if last_name == 'Stoppard' or last_name == 'Smith' or last_name == 'Gielgud' or last_name=='Richardson': first_name = first_name.replace('Sir ', '').replace('Dame ', '') if last_name == 'Priestley' and first_name == 'John Boynton': first_name = 'J. B.' if last_name == 'Sophocles (c496-406/5 BC)': last_name = 'Sophocles' if last_name == 'Maugham': first_name = 'W. Somerset' if first_name == 'Sir James M' and last_name == 'Barrie': first_name = 'J. M.' if first_name == 'Ena Lamont' and last_name == 'Stewart': first_name = 'Ena' last_name = 'Lamont Stewart' multis = { ('Robert', 'Walker'): '3ga', ('John', 'David'): 'zcb', ('Mike', 'Ockrent'): '4y3', ('Lucy', 'Bailey'): '19pc', ('Geoffrey', 'Hutchings'): '3q7', ('Tom', 'Watson'): '8he', ('Oliver Ford', 'Davies'): '115k', ('David', 'Price'): '20c', ('Giles', 'Croft'): '11mx', ('Paul', 'Harris'): 'x6x', ('Mark', 'Smith'): '12dj', ('Anita', 'Dobson'): '13na', ('Tim', 'Mitchell'): '84g', ('Caroline', 'Smith'): '1jj8', ('Richard', 'Harvey'): '1jxd', ('Richard', 'Owen'): '1jyh', ('Jill', 'McMillan'): '1hbq', ('Anthony', 'Howell'): '8g1', ('Laura', 'Williams'): '1dmj', ('Mark', 'Pollard'): '18v6', ('Robert', 'Day'): '1hfe', ('Jeremy', 'Franklin'): '9wh', ('Jack', 'O\'Brien'): '1kcs', ('John', 'Adams'): '16y7', ('David', 'Graham'): 'vfy', ('Alan', 'Jackson'): '1hpd', ('James', 'Barry'): '18ww', } if (first_name, last_name) in multis: person = Person.objects.get(id=base32_to_int(multis[(first_name, last_name)])) else: try: person = Person.objects.get(first_name=first_name, last_name=last_name) except: person = None return person