def redirect_shortlink(request, shortname): try: linkobj = ShortLink.objects.get(user_profile=request.user.profile, shortname=shortname) return redirect(to=linkobj.url, permanent=True) except ShortLink.DoesNotExist: return redirecterror(request, 'Shortlink not found.') except Exception as e: print repr(e) return redirecterror(request, 'Multiple instances found or shortlink points to invalid url.')
def redirect_shortlink(request, shortname): try: linkobj = ShortLink.objects.get(user_profile=request.user.profile, shortname=shortname) return redirect(to=linkobj.url, permanent=True) except ShortLink.DoesNotExist: return redirecterror(request, 'Shortlink not found.') except Exception as e: print repr(e) return redirecterror( request, 'Multiple instances found or shortlink points to invalid url.')
def manage_monitor_course(request): if not request.user.profile.is_contact_set: return redirecterror( request, 'You need to set up your cell phone or email first.') params = {} params.update(csrf(request)) return xrender(request, 'manage_monitor_course.html', params)
def decorator(request, *args, **kwargs): try: return fn(request, *args, **kwargs) except Exception as e: errorlog(repr(e), function=fn) if request.method == 'POST': return JsonError('Unknown error') else: return redirecterror(request, 'Unknown error')
def edit_shortlink(request, shortname): link_obj_list = ShortLink.objects.filter(user_profile=request.user.profile, shortname=shortname) if request.method == 'POST': try: if not request.POST.get('shortname') or not request.POST.get( 'url'): return JsonError('Must provide both shortname and url.') if not link_obj_list.count(): return JsonError('Shortlink not found.') if link_obj_list.count() > 1: return JsonError('Multiple ShortLink instances found.') url = request.POST['url'] shortname = request.POST['shortname'] linkobj = link_obj_list[0] print url if not urlvalid(url): return JsonError( 'Url format incorrect (common mistake: must start with http or https)' ) if linkobj.shortname != shortname and ShortLink.objects.filter( shortname=shortname, user_profile=request.user.profile).count(): return JsonError('Name already in use.') linkobj.shortname = shortname linkobj.url = url linkobj.save() return JsonSuccess('Updated.') except Exception as e: print repr(e) return JsonError('Unknown error.') else: if not link_obj_list.count(): return redirecterror(request, 'Shortlink not found.') if link_obj_list.count() > 1: return redirecterror(request, 'Multiple ShortLink instances found.') linkobj = link_obj_list[0] params = {} params['form'] = ShortLinkForm(instance=linkobj) params['shortlink'] = linkobj params.update(csrf(request)) return xrender(request, 'edit_shortlink.html', params)
def delete_shortlink(request, shortname): try: linkobj = ShortLink.objects.get(user_profile=request.user.profile, shortname=shortname) linkobj.delete() return redirect('manage_shortlink') except ShortLink.DoesNotExist: return redirecterror(request, 'Shortlink not found.') except Exception as e: print repr(e) return redirect('index')
def edit_shortlink(request, shortname): link_obj_list = ShortLink.objects.filter(user_profile=request.user.profile, shortname=shortname) if request.method == 'POST': try: if not request.POST.get('shortname') or not request.POST.get('url'): return JsonError('Must provide both shortname and url.') if not link_obj_list.count(): return JsonError('Shortlink not found.') if link_obj_list.count() > 1: return JsonError('Multiple ShortLink instances found.') url = request.POST['url'] shortname = request.POST['shortname'] linkobj = link_obj_list[0] print url if not urlvalid(url): return JsonError('Url format incorrect (common mistake: must start with http or https)') if linkobj.shortname != shortname and ShortLink.objects.filter(shortname=shortname, user_profile=request.user.profile).count(): return JsonError('Name already in use.') linkobj.shortname = shortname linkobj.url = url linkobj.save() return JsonSuccess('Updated.') except Exception as e: print repr(e) return JsonError('Unknown error.') else: if not link_obj_list.count(): return redirecterror(request, 'Shortlink not found.') if link_obj_list.count() > 1: return redirecterror(request, 'Multiple ShortLink instances found.') linkobj = link_obj_list[0] params = {} params['form'] = ShortLinkForm(instance=linkobj) params['shortlink'] = linkobj params.update(csrf(request)) return xrender(request, 'edit_shortlink.html', params)
def manage_monitor_course_page(request): if not request.user.profile.is_contact_set: return redirecterror(request, "You need to set up your cell phone or email first.") params = {} params.update(csrf(request)) return xrender(request, "manage_monitor_course_page.html", params)