示例#1
0
def new_Entity(request):
    entity = directory.models.Entity()
    entity.save()
    json_serializer = serializers.get_serializer(u"json")()
    response = HttpResponse(mimetype=u"application/json")
    register_edit(
        INSTANCE_CREATED, entity, request.session.session_key, request.user.username, request.META[u"REMOTE_ADDR"]
    )
    json_serializer.serialize([entity], ensure_ascii=False, stream=response)
    return response
示例#2
0
def saveimage(request, string_id):
    id = int(string_id)
    entity = directory.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(
            directory.settings.DIRNAME + u"/static/images/profile/" + string_id,
            directory.settings.DIRNAME + u"/static/images/profile/" + string_id + ".old",
        )
    except OSError:
        pass
    save_file = open(directory.settings.DIRNAME + u"/static/images/profile/" + string_id, u"wb")
    for chunk in file.chunks():
        save_file.write(chunk)
    directory.functions.log_message(u"Image for entity " + string_id + u" changed by " + request.user.username + u'".')
    change_set = register_edit(
        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="/profile/images/%d">""" % id + u"<!--# " + unicode(change_set) + u" #-->"
    return HttpResponse(result)
示例#3
0
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(directory.models, search.group(1)).objects.get(id=int(search.group(2)))
        change_set = register_edit(INSTANCE_DELETED, model, session, username, request.META[u"REMOTE_ADDR"])
        model.is_invisible = True
        model.save()
    directory.functions.log_message(u"Deleted: " + request.POST[u"id"] + u" by " + request.user.username + u".")
    if change_set == None:
        return HttpResponse(u"")
    else:
        response = u"<!--# " + unicode(change_set) + u" #-->"
        return HttpResponse(response)
示例#4
0
     status = directory.models.Status(
         entity=directory.models.Entity.objects.get(id=int(match.group(1))),
         text=value,
         username=request.user.username,
     )
     status.save()
     directory.functions.log_message(
         u"Status for Entity "
         + unicode(match.group(1))
         + u" added by: "
         + request.user.username
         + u", value: "
         + value
         + u"\n"
     )
     change_set = register_edit(INSTANCE_CREATED, status, session, username, request.META[u"REMOTE_ADDR"])
     register_edit(
         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 = directory.models.Email(email=value, entity=directory.models.Entity.objects.get(id=model))