Ejemplo n.º 1
0
def manageExhibitions(request, username):
    if userBackOfficePermission(request, username):
        user = User.objects.get(username=username)
        exhibitions = Exhibition.objects.filter(user_id=user.id)
        return render(request, 'buildengine/manageexhibition.html', {'firstname' : user.first_name, 'name' : user.last_name,
                                                                     'exhibitions' : exhibitions})
    return HttpResponseRedirect("/")
Ejemplo n.º 2
0
def editWork(request, username, idWork):
    if userBackOfficePermission(request, username):
        work = Work.objects.get(id=idWork)
        workTypeTuple = WorkType.objects.filter(idWork_id=idWork)
        dateCreated = str(work.date_created)[0:10]
        if work.date_created is None:
            dateCreated = ""   
        editMetaWorkForm = EditMetaWork(initial={'name': work.name, 'text': work.text, 'keywords' : work.keywords,
                                                 'dateCreated' : dateCreated, 'width' : work.width, 'height' : work.height,
                                                 'material' : work.material, 'current_local' : work.current_local,
                                                 'type' : workTypeTuple, 'depth': work.depth, 'in_focus':work.in_focus})
        editImageWorkForm = EditImageWork()
        workType = WorkType.objects.all()
        #If the form has been sent
        if request.method == 'POST':
            form = EditMetaWork(request.POST)
            if form.is_valid():
                requestName = request.POST['name']
                requestText = request.POST['text']
                requestKeywords = request.POST['keywords']
                requestWidth = request.POST['width']
                requestHeight = request.POST['height']
                requestDepth = request.POST['depth']
                requestCreated = request.POST['dateCreated']
                requestMaterial = request.POST['material']
                requestLocal = request.POST['current_local']
                requestFocus = request.POST['in_focus']
                requestType = request.POST.getlist('type')
                if request.POST['dateCreated'] == "":
                    requestCreated = None
                if request.POST['width'] == "":
                    requestWidth = None
                if request.POST['height'] == "":
                    requestHeight = None
                if request.POST['depth'] == "":
                    requestDepth = None
                if request.POST['in_focus'] == "False":
                    work.in_focus = False
                else:
                    work.in_focus = True
                work.name = requestName
                work.text = requestText
                work.keywords = requestKeywords
                work.width = requestWidth
                work.height = requestHeight
                work.depth = requestDepth
                work.date_created = requestCreated
                work.material = requestMaterial
                work.current_local = requestLocal
                work.save()
                WorkType.objects.filter(idWork_id=idWork).delete()
                for value in requestType:
                    workType = WorkType(idType=value, idWork=work)
                    workType.save()
                return HttpResponseRedirect("/"+username+"/build/editwork/"+idWork)
            return render(request, 'form/editwork.html', {'editMetaWorkForm' : form, 'editImageWorkForm' : editImageWorkForm,
                                                      'work': work, 'workType' : workType})
        return render(request, 'form/editwork.html', {'editMetaWorkForm' : editMetaWorkForm, 'editImageWorkForm' : editImageWorkForm,
                                                      'work': work, 'workType' : workType})
    return HttpResponseRedirect("/")
Ejemplo n.º 3
0
def display(request, username):
    if userBackOfficePermission(request, username):
        user = User.objects.get(username=username)
        userFollowers = []
        userFollowing = []
        userLastWorks = []
        userLastExhibitions = []
        following = FriendSocial.objects.filter(user1_id = user.id)
        followers = FriendSocial.objects.filter(user2_id = user.id)
        for f in followers:
            query = User.objects.get(id = f.user1_id)
            userFollowers.append(query)
        for f in following:
            query = User.objects.get(id = f.user2_id)
            userFollowing.append(query)
        for f in userFollowing:
            query = Work.objects.filter(user_id = f.id)[:10]
            for w in query:
                userLastWorks.append(w)
        for f in userFollowing:
            query = Exhibition.objects.filter(user_id = f.id)[:10]
            for e in query:
                userLastExhibitions.append(e)
        firstname = user.first_name
        name = user.last_name
        userLastWorks = sorted(userLastWorks, key=lambda obj: obj.date_pub, reverse=True)
        userLastExhibitions = sorted(userLastExhibitions, key=lambda obj: obj.date_pub, reverse=True)
        return render(request, 'buildengine/statistics.html', {'user': user, 'firstname' : firstname, 'name' : name,
                                                               'userFollowers': userFollowers, 'userFollowing': userFollowing,
                                                               'userLastWorks' : userLastWorks, 'userLastExhibitions' : userLastExhibitions})
    return HttpResponseRedirect("/")
Ejemplo n.º 4
0
def editTopic(request, idTopic, username):
    if userBackOfficePermission(request, username):
        topic = WorkTopic.objects.get(id=idTopic)
        workTopicTypeTuple = WorkTopicType.objects.filter(idWork_id=idTopic)
        form = WorkTopicForm(initial={'name' : topic.name, 'text': topic.text, 'type' : workTopicTypeTuple})
        workTopic = WorkTopic.objects.get(id=idTopic)
        works = Work.objects.filter(work_topic_id=idTopic)
        workTopicType = WorkTopicType.objects.filter(idWork_id=idTopic)
        if request.method == 'POST':
            form = WorkTopicForm(request.POST)
            if form.is_valid():
                requestName = request.POST['name']
                requestText = request.POST['text']
                requestType = request.POST.getlist('type')
                workTopic.name = requestName
                workTopic.text = requestText
                workTopic.save()
                WorkTopicType.objects.filter(idWork_id=idTopic).delete()
                for value in requestType:
                    workTopicType = WorkTopicType(idType=value, idWork=workTopic)
                    workTopicType.save()
                return HttpResponseRedirect("/"+username+"/build/edittopic/"+idTopic)
        return render(request, 'buildengine/managetopic.html', {'idTopic' : idTopic, 'workTopic' : workTopic, 'works' : works,
                                                                'workType' : workTopicType, 'form' : form})
    return HttpResponseRedirect("/")
Ejemplo n.º 5
0
def manageWork(request, username):
    if userBackOfficePermission(request, username):
        workType = WorkType.objects.all()
        workTopic = WorkTopic.objects.filter(user_id=request.user.id)
        works = Work.objects.filter(user_id=request.user.id)
        return render(request, 'buildengine/managework.html', {'username' : username, 'blockTopic' : workTopic, 'workType' : workType,
                                                               'works' : works})
    return HttpResponseRedirect("/")
Ejemplo n.º 6
0
def addExhibition(request, username):
    if userBackOfficePermission(request, username):
        user = User.objects.get(username=username)
        form = ExhibitionForm()
        exhibitions = Exhibition.objects.filter(user_id=user.id)
        if request.method == 'POST':
            form = ExhibitionForm(request.POST)
            if form.is_valid():
                form.save(request)
                return render(request, 'buildengine/manageexhibition.html', {'firstname' : user.first_name, 'name' : user.last_name,
                                                                             'exhibitions' : exhibitions})
        return render(request, 'form/addexhibition.html', {'firstname' : user.first_name, 'name' : user.last_name, 'form' : form})
    return HttpResponseRedirect("/")
Ejemplo n.º 7
0
def addWork(request, idTopic, username):
    if userBackOfficePermission(request, username):
        workForm = WorkForm()
        #If the form has been sent
        if request.method == 'POST':
            form = WorkForm(request.POST, request.FILES)
            if form.is_valid():
                requestName = request.POST['name']
                requestImage = request.FILES['image']  
                requestText = request.POST['text']
                requestKeywords = request.POST['keywords']
                requestWidth = request.POST['width']
                requestHeight = request.POST['height']
                requestDepth = request.POST['depth']
                requestCreated = request.POST['dateCreated']
                requestMaterial = request.POST['material']
                requestLocal = request.POST['current_local']
                if request.POST['in_focus'] == "False":
                    requestFocus = False
                else:
                    requestFocus = True
                requestType = request.POST.getlist('type')
                if request.POST['dateCreated'] == "":
                    requestCreated = None
                if request.POST['width'] == "":
                    requestWidth = None
                if request.POST['height'] == "":
                    requestHeight = None
                if request.POST['depth'] == "":
                    requestDepth = None
                #Create new image in the database
                user = User.objects.get(username=username)
                workTopic = WorkTopic.objects.get(id=idTopic)
                #Create Work in the database
                contentType = ContentType.objects.get(model="work")
                work = Work(name=requestName, text=requestText, user_id=user.id, image=requestImage, content_type_id=contentType.id,
                            work_topic_id=workTopic.id, keywords=requestKeywords, date_created=requestCreated ,width=requestWidth, height=requestHeight,
                            material=requestMaterial, current_local=requestLocal, depth=requestDepth, in_focus=requestFocus)
                work.save()
                #Create WorkType in the database
                for value in requestType:
                    workType = WorkType(idType=value, idWork=work)
                    workType.save()
                #Resize
                image = Image.open(work.image)
                image.thumbnail((820, 820), Image.ANTIALIAS)
                image.save(work.image.path)
                return HttpResponseRedirect("/"+username+"/build/managework")
            return render(request, 'form/addwork.html', {'form' : form, 'idTopic': idTopic})
        return render(request, 'form/addwork.html', {'form' : workForm, 'idTopic': idTopic})
    return HttpResponseRedirect("/")
Ejemplo n.º 8
0
def editAnonymity(request, username):
    if userBackOfficePermission(request, username):
        editAccountForm = EditAccountForm();
        editAnonymityForm = EditAnonymityForm();
        if request.method == 'POST':
            form = EditAnonymityForm(request.POST)
            if form.is_valid():
                    requestAnonymity = request.POST['anonymity']
                    user = User.objects.get(username=username)
                    prefWebsite = PrefWebsite.objects.get(user_id=user.id)
                    prefWebsite.anonymity = requestAnonymity
                    prefWebsite.save()
                    return HttpResponseRedirect("/"+username+"/build")
            return render(request, 'form/editaccount.html', {'form' : form, 'formState' : formState})
        return render(request, 'form/editaccount.html', {'form' : editAccountForm})
    return HttpResponseRedirect("/") 
Ejemplo n.º 9
0
def editImageWork(request, username, idWork):
    if userBackOfficePermission(request, username):
        if request.method == 'POST':
            form = EditImageWork(request.POST, request.FILES)
            if form.is_valid():
                work = Work.objects.get(id=idWork)
                requestImage = request.FILES['image']
                work.image = requestImage
                work.save()
                #Resize
                image = Image.open(work.image)
                image.thumbnail((820, 820), Image.ANTIALIAS)
                image.save(work.image.path)
                return HttpResponseRedirect("/"+username+"/build/editwork/"+idWork)
        return HttpResponseRedirect("/"+username+"/build/editwork/"+idWork)
    return HttpResponseRedirect("/")
Ejemplo n.º 10
0
def editAccount(request, username):
    if userBackOfficePermission(request, username):
        user = User.objects.get(username=username)
        prefWebsite = PrefWebsite.objects.get(user_id=user.id)
        editAccountForm = EditAccountForm();
        editAnonymityForm = EditAnonymityForm(initial={'anonymity' : prefWebsite.anonymity});
        if request.method == 'POST':
            form = EditAccountForm(request.POST)
            if form.is_valid():
                requestPassword = request.POST['password']
                requestConfirmPassword = request.POST['confirmPassword']
                requestEmail = request.POST['email']
                formState = "Error password"
                if requestPassword == requestConfirmPassword: 
                    user.set_password(form.cleaned_data['password'])
                    user.email = requestEmail
                    user.save()
                    return HttpResponseRedirect("/"+username+"/build")
            return render(request, 'form/editaccount.html', {'form' : form, 'form_anonymity' : editAnonymityForm, 'formState' : formState})
        return render(request, 'form/editaccount.html', {'form' : editAccountForm, 'form_anonymity' : editAnonymityForm})
    return HttpResponseRedirect("/")
Ejemplo n.º 11
0
def addTopic(request, username):
    if userBackOfficePermission(request, username):
        workForm = WorkTopicForm()
        if request.method == 'POST':
                form = WorkTopicForm(request.POST)
                if form.is_valid():
                    requestName = request.POST['name']
                    requestText = request.POST['text']
                    requestType = request.POST.getlist('type')
                    user = User.objects.get(username=username)
                    contentType = ContentType.objects.get(model="worktopic")
                    workTopic = WorkTopic(name=requestName, text=requestText, user_id=user.id, content_type_id=contentType.id)
                    workTopic.save()
                    #Create WorkType in the database
                    for value in requestType:
                        workType = WorkTopicType(idType=value, idWork=workTopic)
                        workType.save()
                    return HttpResponseRedirect("/"+username+"/build/managework")
                return render(request, 'form/addtopicwork.html', {'form' : form})
        return render(request, 'form/addtopicwork.html', {'form' : workForm})
    return HttpResponseRedirect("/")
Ejemplo n.º 12
0
def editExhibition(request, username, idExhibition):
    if userBackOfficePermission(request, username):
        user = User.objects.get(username=username)
        exhibition = Exhibition.objects.get(id=idExhibition)
        exhibitions = Exhibition.objects.filter(user_id=user.id)
        form = ExhibitionForm(initial={'nameGallery':exhibition.nameGallery, 'mapLongitude':exhibition.mapLongitude, 'mapLatitude':exhibition.mapLatitude,
                                       'adress':exhibition.adress, 'city':exhibition.city, 'zipcode':exhibition.zipcode, 'country':exhibition.country, 'text':exhibition.text,
                                       'date_begin':str(exhibition.date_begin)[0:10], 'date_end':str(exhibition.date_end)[0:10]})
        if request.method == 'POST':
            form = ExhibitionForm(request.POST)
            if form.is_valid():
                exhibition.mapLongitude = request.POST["mapLongitude"]
                exhibition.mapLatitude = request.POST["mapLatitude"]
                exhibition.adress = request.POST["adress"].encode('utf-8')
                exhibition.city = request.POST["city"].encode('utf-8')
                exhibition.zipcode = request.POST["zipcode"]
                exhibition.country = request.POST["country"].encode('utf-8')
                if request.POST["mapLongitude"] == "" or request.POST["mapLongitude"] == "0.0":
                    exhibition.mapLongitude = 0
                if request.POST["mapLatitude"] == "" or request.POST["mapLatitude"] == "0.0":
                    exhibition.mapLatitude = 0
                URLAddress = str(exhibition.adress).replace(" ", "_")+"_"+str(exhibition.city).replace(" ", "_")+"_"+str(exhibition.country).replace(" ", "_")
                URL = 'http://maps.googleapis.com/maps/api/geocode/json?address='+URLAddress+'&sensor=false'
                response = urllib2.urlopen(URL)
                data = json.load(response)
                print URL
                print data
                exhibition.mapLatitude = data["results"][0]["geometry"]["location"]["lat"]
                exhibition.mapLongitude = data["results"][0]["geometry"]["location"]["lng"]
                exhibition.nameGallery = request.POST["nameGallery"]
                exhibition.text = request.POST["text"].encode('utf-8')
                exhibition.date_begin = request.POST["date_begin"]
                exhibition.date_end = request.POST["date_end"]
                exhibition.save()
                #return render(request, 'buildengine/manageexhibition.html', {'firstname' : user.first_name, 'name' : user.last_name,
                #'exhibitions' : exhibitions})
                return HttpResponseRedirect("/"+user.username+"/build/manageexhibitions/")
        return render(request, 'form/editexhibition.html', {'firstname' : user.first_name, 'name' : user.last_name, 'form' : form, 'exhibition': exhibition})
    return HttpResponseRedirect("/")
Ejemplo n.º 13
0
def deleteWork(request, username, idWork):
    if userBackOfficePermission(request, username):
        work = Work.objects.filter(id=idWork)
        work.delete()
        return HttpResponseRedirect("/"+username+"/build")
    return HttpResponseRedirect("/")
Ejemplo n.º 14
0
def deleteTopic(request, idTopic, username):
    if userBackOfficePermission(request, username):
        workTopic = WorkTopic.objects.get(id=idTopic).delete()
    return HttpResponseRedirect("/"+username+"/build/managework/")