예제 #1
0
def edit_url(request, id):

    if 'user_email' in request.session:
        current_user = auth(request.session['user_email'])
        if not current_user:
            raise Http404
    else:
        return HttpResponseRedirect("/")

    if request.method == "POST":
        form = AddUrlForm(current_user.id, request.POST)
        if form.is_valid():
            savedurl = get_object_or_404(SavedUrl, id=id, user_id=current_user.id)
            (savedurl.url, created) = Url.objects.get_or_create(url = form.cleaned_data['url'])
            savedurl.category = get_object_or_404(Category, id=form.cleaned_data['category'])
            savedurl.url_title = form.cleaned_data['url_title']
            savedurl.notes = form.cleaned_data['notes']
            try:
                savedurl.save()
            except IntegrityError as e:
                return render(request, 'add_url.html', 
                        {'form': form, 'reason': 'There were some problems with the data. Maybe you want to add an existing url?'})
            return render(request, 'add_url_success.html')
        return render(request, 'add_url.html', { 'form': form, 'error': form.errors })
    else:
        savedurl = get_object_or_404(SavedUrl, id=id)
        url = get_object_or_404(Url, id=savedurl.url_id)
        category = get_object_or_404(Category, id=savedurl.category_id)
        labels = Label.objects.filter(saved_url=url.id)
        form = AddUrlForm(current_user.id, 
                {'url': url.url, 'category': category.id, 
                    'url_title': savedurl.url_title, 'notes': savedurl.notes})
        return render(request, 'add_url.html', {'form': form, 'labels': labels})
예제 #2
0
def add_label(request, id):

    if 'user_email' in request.session:
        current_user = auth(request.session['user_email'])
        if not current_user:
            raise Http404
    else:
        return HttpResponseRedirect("/")

    if request.method == 'POST':
        form = AddLabelForm(request.POST)
        if form.is_valid():
            url = get_object_or_404(SavedUrl, id=id)
            label_name = form.cleaned_data['label_name']
            try:
                (label, created) = Label.objects.get_or_create(name=label_name)
                label.saved_url.add(url)
                label.save()
            except IntegrityError as e:
                return render(request, 'add_label.html', {'form': form, 'reason': e})
            return render(request, 'add_label_success.html', {'form': form})

        return render(request, 'add_label.html', {'form': form, 'error': form.errors})
    else:
        return render(request, 'add_label.html', {'form': AddLabelForm})
예제 #3
0
def index(request):
    saved_urls = []
    categories = []
    default_categories = []
    current_user = None
    cursor = connection.cursor()

    if 'user_email' in request.session:
        current_user = auth(request.session['user_email'])
        #try:
        #    current_user = User.objects.get(email = request.session['user_email'])
        #except User.DoesNotExist:
        #    current_user = None

        cursor.execute('''
        SELECT main_category.id AS id, main_category.name AS name, count(main_savedurl.url_id) AS count 
        FROM main_savedurl RIGHT JOIN main_category 
        ON main_savedurl.category_id=main_category.id AND main_savedurl.user_id=''' + str(current_user.id) + '''
        WHERE main_category.is_default=TRUE 
        GROUP BY main_category.id
        ORDER BY count DESC''')
        default_categories = cursor.fetchall()

        cursor.execute('''SELECT main_category.id AS id, main_category.name AS name, count(main_savedurl.url_id) AS count 
                FROM main_savedurl RIGHT JOIN main_category ON main_savedurl.category_id=main_category.id 
                WHERE main_category.is_default=FALSE AND main_savedurl.user_id=''' + str(current_user.id) + ''' 
                GROUP BY main_category.id''')
        categories = cursor.fetchall()
        cursor.close()


    context = {'categories' : categories, 'default_categories': default_categories, 'user': current_user }

    return render(request, 'index.html', context)
예제 #4
0
def add_url(request):

    if 'user_email' in request.session:
        current_user = auth(request.session['user_email'])
        if not current_user:
            raise Http404
    else:
        return HttpResponseRedirect("/login/")

    if request.method == 'POST':
        form = AddUrlForm(current_user.id, request.POST)
        if form.is_valid():
            
            (new_url, created) = Url.objects.get_or_create(url=form.cleaned_data['url'])
            (new_cat, created) = Category.objects.get_or_create(id=form.cleaned_data['category'])

            new_title = form.cleaned_data['url_title']
            new_notes = form.cleaned_data['notes']

            try:
                savedurl = SavedUrl(user=current_user, url=new_url, 
                        category=new_cat, url_title=new_title, notes=new_notes)
                savedurl.save()
            except IntegrityError as e:
                return render(request, 'add_url.html', {'form': form, 'reason': 'There is already an entry with that url.'})
            return render(request, 'add_url_success.html')
        return render(request, 'add_url.html', { 'error': form.errors })
    else:
        return render(request, 'add_url.html', {'form': AddUrlForm(current_user.id)})
예제 #5
0
def search_label(request, id):

    if 'user_email' in request.session:
        current_user = auth(request.session['user_email'])
        if not current_user:
            raise Http404
    else:
        return HttpResponseRedirect("/")

    label = Label.objects.get(id=id)
    d = {}
    for url in label.saved_url.all():
        try:
            url = SavedUrl.objects.get(id=url.id, user=current_user)
        except:
            continue

        labels = Label.objects.filter(saved_url=url.id)

        if url.id not in d:
            d.update({url.id : (url, labels)})
        else:
            d[url.id][1] += [label]

    saved_urls = list(d.values())

    context = {'saved_urls' : saved_urls , 'label': label}

    return render(request, 'savedurls.html', context)
예제 #6
0
def search(request):

    if 'user_email' in request.session:
        current_user = auth(request.session['user_email'])
        if not current_user:
            raise Http404
    else:
        return HttpResponseRedirect("/")

    if request.method == "POST":
        raise Http404

    query = request.GET['q'].split()
    if len(query) == 0:
        return render(request, 'savedurls.html', {'saved_urls': []})

    q = Q(url__url__icontains=query[0]) | Q(category__name__icontains=query[0]) | Q(url_title__icontains=query[0])
    for elem in query:
        q.add(Q(url__url__icontains=elem) | Q(category__name__icontains=elem) | Q(url_title__icontains=elem), q.connector)

    urls = SavedUrl.objects.filter(q, user=current_user).exclude(url__isnull=True)
    saved_urls = [(url, Label.objects.filter(saved_url=url.id)) for url in urls]

    context = {'saved_urls' : saved_urls }

    return render(request, 'savedurls.html', context)
예제 #7
0
파일: views.py 프로젝트: Myxir/wet
def vet_details(request, vet_id):
    try:
        vet = Vet.objects.get(pk=vet_id)
    except Vet.DoesNotExist:
        raise Http404
    
    txt = auth(request)
    
    clientlist = vet.client_set.all()
    if not (request.user.is_authenticated and \
    (request.user.username == vet.user.username or request.user.is_staff)):
        clientlist = 'false'
    context = Context({'clientlist': clientlist, 'vet':vet, 'len':len(clientlist),'STATIC_URL':settings.STATIC_URL, 'date':getDate(), 'logged':txt})
    return render_to_response('main/weterynarze_details.html',context)
예제 #8
0
def delete_url(request, id):

    if 'user_email' in request.session:
        current_user = auth(request.session['user_email'])
        if not current_user:
            raise Http404
    else:
        return HttpResponseRedirect("/")

    if request.method == "POST":
        savedurl = get_object_or_404(SavedUrl, id=id, user_id=current_user.id)
        savedurl.delete()
        return render(request, 'delete_url_success.html')
    else:
        return render(request, 'delete_url.html')
예제 #9
0
def view_all_categories(request):

    if 'user_email' in request.session:
        current_user = auth(request.session['user_email'])
        if not current_user:
            raise Http404
    else:
        return HttpResponseRedirect("/")

    urls = SavedUrl.objects.filter(user=current_user).exclude(url__isnull=True)
    saved_urls = [(url, Label.objects.filter(saved_url=url.id)) for url in urls]

    context = {'saved_urls' : saved_urls }

    return render(request, 'savedurls.html', context)
예제 #10
0
파일: views.py 프로젝트: Myxir/wet
def client_details(request, client_id):
    try:
        client = Client.objects.get(pk=client_id)
    except Client.DoesNotExist:
        raise Http404
    txt = auth(request)
    if not (request.user.is_authenticated and \
    (request.user.username == client.user.username \
     or request.user.username == client.vet.user.username or request.user.is_staff)):
        vet = 'false'
        animallist = []
    else:
        vet = client.vet
        animallist = client.animal_set.all()
    context = Context({'animallist': animallist, 'client':client, 'vet':vet,'STATIC_URL':settings.STATIC_URL, 'date':getDate(), 'logged':txt})
    return render_to_response('main/klient_details.html', context)
예제 #11
0
def view_category(request, id):

    if 'user_email' in request.session:
        current_user = auth(request.session['user_email'])
        if not current_user:
            raise Http404
    else:
        return HttpResponseRedirect("/")

    category = get_object_or_404(Category, id=id)

    urls = SavedUrl.objects.filter(user=current_user, category=id).exclude(url__isnull=True)
    saved_urls = [(url, Label.objects.filter(saved_url=url.id)) for url in urls]

    context = {'category': category, 'saved_urls' : saved_urls, 'user': current_user }

    return render(request, 'savedurls.html', context)
예제 #12
0
파일: views.py 프로젝트: Myxir/wet
def animal_details(request, animal_id):
    try:
        animal = Animal.objects.get(pk=animal_id)
    except Animal.DoesNotExist:
        raise Http404
    txt = auth(request)
    if not (request.user.is_authenticated and \
    (request.user.username == animal.client.user.username \
     or request.user.username == animal.client.vet.user.username or request.user.is_staff)):
        client = 'false'
        vet = 'false'
        age = 'false'
    else:
        client = animal.client
        vet = client.vet
        age = animal.age()
    context = Context({'wiek':age, 'animal':animal, 'client':client, 'vet':vet,'STATIC_URL':settings.STATIC_URL, 'date':getDate(), 'logged':txt})
    return render_to_response('main/zwierzak_details.html', context);
예제 #13
0
def delete_label(request, url_id, label_id):

    if 'user_email' in request.session:
        current_user = auth(request.session['user_email'])
        if not current_user:
            raise Http404
    else:
        return HttpResponseRedirect("/")

    if request.method == 'POST':
        saved_url = get_object_or_404(SavedUrl, id=url_id)
        label = get_object_or_404(Label, id=label_id)
        try:
            label.saved_url.remove(saved_url)
            label.save()
        except IntegrityError as e:
            return render(request, 'delete_label.html', {'reason': e})
        return render(request, 'delete_label_success.html')
    else:
        return render(request, 'delete_label.html')
예제 #14
0
파일: views.py 프로젝트: Myxir/wet
def vets(request):
    vetlist = Vet.objects.all().order_by('-pk')
    
    txt = auth(request)    
    paginator = Paginator(vetlist, 10) # Show 25 contacts per page
    
    page = request.GET.get('page')
    try:
        vetpag = paginator.page(page)
    except TypeError:
        vetpag = paginator.page(1)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        vetpag = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        vetpag = paginator.page(paginator.num_pages)

        
    context = Context({'vetlist' : vetlist, "log":txt, 'STATIC_URL':settings.STATIC_URL, 'date':getDate(), 'logged':txt, 'vetpag':vetpag})
    return render_to_response('main/weterynarze.html',context)
예제 #15
0
def delete_category(request, id):

    if 'user_email' in request.session:
        current_user = auth(request.session['user_email'])
        if not current_user:
            raise Http404
    else:
        return HttpResponseRedirect("/")

    if request.method == 'POST':
        category = get_object_or_404(Category, id=id)
        undefined_category = Category.objects.filter(name='Undefined')[0]
        saved_urls = SavedUrl.objects.filter(category_id=category.id)
        try:
            for s_u in saved_urls:
                s_u.category_id = undefined_category.id
                s_u.save()
            category.delete()
        except IntegrityError as e:
            return render(request, 'delete_category.html', {'reason': e})
        return render(request, 'delete_category_success.html')
    else:
        return render(request, 'delete_category.html')
예제 #16
0
def add_category(request):

    if 'user_email' in request.session:
        current_user = auth(request.session['user_email'])
        if not current_user:
            raise Http404
    else:
        return HttpResponseRedirect("/")

    if request.method == 'POST':
        form = AddCategoryForm(request.POST)
        if form.is_valid():
            category_name = form.cleaned_data['category_name']
            (new_category, created) = Category.objects.get_or_create(name=category_name)
            try:
                new_saved_url = SavedUrl(user=current_user, category=new_category)
                new_saved_url.save()
            except IntegrityError as e:
                return render(request, 'add_category.html', {'form': form, 'reason': e})
            return render(request, 'add_category_success.html', {'form': form})

        return render(request, 'add_category.html', {'form': form, 'error': form.errors})
    else:
        return render(request, 'add_category.html', {'form': AddCategoryForm})
예제 #17
0
파일: views.py 프로젝트: Myxir/wet
def index(request):
    txt = auth(request)
    context = Context({'STATIC_URL':settings.STATIC_URL, 'date':getDate(), 'logged':txt})
    return render_to_response('main/index.html',context)
예제 #18
0
파일: views.py 프로젝트: Myxir/wet
def new_animal(request):
    txt = auth(request)
    context = ({'STATIC_URL':settings.STATIC_URL, 'date':getDate(), 'logged':txt})
    return render_to_response('main/new_animal.html',context);