예제 #1
0
파일: views.py 프로젝트: kmnrstzaiou/sample
def ajax_delete(request):
    session = request.session.session_key
    username = request.user.username
    change_set = None
    search = re.search(ur'(.*)_(\d+)', request.POST[u'id'])
    if search:
        model = getattr(models, search.group(1)).objects.get(id=int(search.group(2)))
        change_set = register_edit(models.INSTANCE_DELETED, model, session, username, request.META[u'REMOTE_ADDR'])
        model.is_invisible = True
        model.save()
    log_message(u'Deleted: ' + request.POST[u'id'] + u' by ' + request.user.username + u'.')
    if change_set == None:
        return HttpResponse(u'')
    else:
        response = u'<!--# ' + str(change_set) + u' #-->'
        return HttpResponse(response)
예제 #2
0
파일: views.py 프로젝트: kmnrstzaiou/sample
def saveimage(request, string_id):
    id = int(string_id)
    entity = models.Entity.objects.filter(id=id)[0]
    original_mimetype = entity.image_mimetype
    file = request.FILES.values()[0]
    extension = file.name.lower().split(".")[-1]
    if extension == u'jpg':
        entity.image_mimetype = u'image/jpeg'
    elif extension == u'swf':
        entity.image_mimetype = u'application/x-shockwave-flash'
    else:
        entity.image_mimetype = u'image/' + extension
    entity.save()
    try:
        os.rename(settings.DIRNAME + u'/static/images/profile/' + string_id, settings.DIRNAME + u'/static/images/profile/' + string_id + '.old')
    except OSError:
        pass
    save_file = open(settings.DIRNAME + u'/static/images/profile/' + string_id, u'wb')
    for chunk in file.chunks():
        save_file.write(chunk)
    log_message(u'Image for entity ' + string_id + u' changed by ' + request.user.username + u'".')
    change_set = register_edit(models.IMAGE_CHANGED, entity, request.session.session_key, request.user.username, request.META[u'REMOTE_ADDR'], text_before=original_mimetype, text_after=entity.image_mimetype)
    result = u'<img class="profile" src="/static/images/profile/' + unicode(id) + u'"><!--# ' + unicode(change_set) + u' #-->'
    return HttpResponse(result)
예제 #3
0
파일: views.py 프로젝트: kmnrstzaiou/sample
     dictionary = request.GET
 if html_id.startswith(u'Entity_department_'):
     value = dictionary[u'department']
 elif html_id.startswith(u'Entity_location_'):
     value = dictionary[u'location']
 elif html_id.startswith(u'Entity_reports_to_'):
     value = dictionary[u'reports_to']
 else:
     value = dictionary[u'value']
 if not re.match(ur'^\w+$', html_id):
     raise Exception(u'Invalid HTML id.')
 match = re.match(ur'Status_new_(\d+)', html_id)
 if match:
     status = models.Status(entity=models.Entity.objects.get(id=int(match.group(1))), text=value)
     status.save()
     log_message(u'Status for Entity ' + str(match.group(1)) + u' added by: ' + username + u', value: ' + value + u'\n')
     change_set = register_edit(models.INSTANCE_CREATED, status, session, username, request.META[u'REMOTE_ADDR'])
     register_edit(models.TEXT_CHANGED, status, session, username, request.META[u'REMOTE_ADDR'], field_name=u'text', change_set=change_set, text_after=value)
     return HttpResponse(u'<!--# ' + unicode(change_set) + u' #-->')
 match = re.match(ur'Email_new_(\d+)', html_id)
 if match:
     model = int(match.group(1))
     email = models.Email(email=value, entity=models.Entity.objects.get(id=model))
     email.save()
     log_message(u'Email for Entity ' + str(model) + u' added by: ' + username + u', value: ' + value + u'\n')
     change_set = register_edit(models.INSTANCE_CREATED, email, session, username, request.META[u'REMOTE_ADDR'])
     register_edit(models.TEXT_CHANGED, email, session, username, request.META[u'REMOTE_ADDR'], field_name=u'email', text_after=value)
     return HttpResponse(u'<!--# ' + unicode(change_set) + u' #-->')
 match = re.match(ur'Entity_tag_new_(\d+)', html_id) 
 if match:
     model = int(match.group(1))