Example #1
0
def add_resource(request):
    if request.method == 'POST':
        form = ResourceForm(request.POST)
        if form.is_valid():
            r = CalendarResources(
                 resource_common_name=request.POST['resource_common_name'],
                 resource_description=request.POST['resource_description'],
                 resource_type=request.POST['resource_type'])
            r.save()
            r = CalendarResources.objects.latest('updated')
            r.resource_id = 'r%s' % r.id
            r.save()
            client = GetClient()
            try:
                client.CreateResource(
                     resource_id=r.resource_id,
                     resource_common_name=request.POST['resource_common_name'],
                     resource_description=request.POST['resource_description'],
                     resource_type=request.POST['resource_type'])
            except:
                client.UpdateResource(
                     resource_id=r.resource_id,
                     resource_common_name=request.POST['resource_common_name'],
                     resource_description=request.POST['resource_description'],
                     resource_type=request.POST['resource_type'])
            return HttpResponseRedirect('/resource/%s' % r.resource_id)
    else:
        form = ResourceForm()

    return render(request, 'resources/edit_form.html', {
        'title': 'Tambah Sumber Daya',
        'form': form,
    })
Example #2
0
def sync(request, resource_id):
    try:
        client = GetClient()
        resource = client.GetResource(resource_id=resource_id)
    except:
        return HttpResponseRedirect('/resources/out_of_sync')
    try:
        r = CalendarResources.objects.get(resource_id=resource.resource_id)
        r.resource_id=resource.resource_id
        r.resource_common_name=resource.resource_common_name
        r.resource_description=resource.resource_description
        r.resource_email=resource.resource_email
        r.resource_type=resource.resource_type
    except:
        r = CalendarResources(
             resource_id=resource.resource_id,
             resource_common_name=resource.resource_common_name,
             resource_description=resource.resource_description,
             resource_email=resource.resource_email,
             resource_type=resource.resource_type)
    r.save()
    return HttpResponseRedirect('/resources/out_of_sync')