def addlogmsg(userid, instanceid, message): """ :param request: :return: """ add_log_msg = Logs(user_id=userid, instance_id=instanceid, message=message) add_log_msg.save()
def addlogmsg(user, instance, message): """ :param request: :return: """ add_log_msg = Logs(user=user, instance=instance, message=message) add_log_msg.save()
def create(self, data): """ this serializers handles redit room """ try: status = data.get("status") date_now = datetime.now().strftime('%Y-%m-%d') if data.get("date_publish") != "": if date_now != data.get("date_publish"): status = TypeRoom.INACTIVE update_room = TypeRoom.objects.get(pk=data.get("id")) update_room.name = data.get("name") update_room.hotel_id = data.get("hotel_id") update_room.price = data.get("price") update_room.enable = data.get("enable") update_room.count_person = data.get("count_person") update_room.date_publish = data.get( "date_publish") if data.get("date_publish") != "" else None update_room.date_inactive = data.get( "date_inactive") if data.get("date_inactive") != "" else None update_room.status = status update_room.save() return update_room.id log_register = Logs(user=data.get("user"), action=Actions.action_update, name_model='Room', id_handle=update_room.id) log_register.save() except Exception as e: print(e) return 0
def addLog(user_id=None, log_module=None, scene=None, content=None): addtime = datetime.now() log = Logs(username=user_id, log_module=log_module, scene=scene, content=content, addtime=addtime) log.save()
def addlogmsg(user, host, instance, message): """ :param user: :param host: :param instance: :param message: :return: """ add_log_msg = Logs(user=user, host=host, instance=instance, message=message) add_log_msg.save()
def create(self, data): """ this serializers handles activity hotel """ try: newActivity = None if ActivityHotel.LIKE == int(data.get("type_activity")): query_activity = ActivityHotel.objects.filter( profile=data.get("profile"), hotel_id=data.get("hotel_id"), type_activity=data.get("type_activity")) if len(query_activity) == 0: newActivity = ActivityHotel( hotel_id=data.get("hotel_id"), by_like=data.get("by_like"), profile=data.get("profile"), type_activity=data.get("type_activity")) else: update_activity = ActivityHotel.objects.get( pk=query_activity[0].id) update_activity.by_like = data.get("by_like") update_activity.save() log_register = Logs(user=data.get("user"), action=Actions.action_update, name_model='ActivityHotel', id_handle=update_activity.id) log_register.save() return update_activity.id elif ActivityHotel.COMMENT == int(data.get("type_activity")): query_activity = ActivityHotel.objects.filter( profile=data.get("profile"), hotel_id=data.get("hotel_id"), type_activity=data.get("type_activity")) if len(query_activity) == 0: newActivity = ActivityHotel( hotel_id=data.get("hotel_id"), comment=data.get("comment"), profile=data.get("profile"), type_activity=data.get("type_activity")) else: return -1 if newActivity is not None: newActivity.save() log_register = Logs(user=data.get("user"), action=Actions.action_create, name_model='ActivityHotel', id_handle=newActivity.id) log_register.save() return newActivity.id return 1 except Exception as e: print(e) return 0
def create(self, data): """ this serializers handles edit a Hotel """ try: status = data.get("status") date_now = datetime.now().strftime('%Y-%m-%d') if data.get("date_publish") != "": if date_now != data.get("date_publish"): status = Hotel.INACTIVE update_hotel = Hotel.objects.get(pk=data.get("id")) update_hotel.name = data.get("name") update_hotel.city_id = data.get("city_id") update_hotel.type_document_id = data.get("type_document_id") update_hotel.number_document = data.get("number_document") update_hotel.date_publish = data.get( "date_publish") if data.get("date_publish") != "" else None update_hotel.date_inactive = data.get( "date_inactive") if data.get("date_inactive") != "" else None update_hotel.status = status update_hotel.category.clear() update_hotel.tags.clear() update_hotel.save() if data.get("category") != "": category = data.get("category").split(",") print(category) update_hotel.category.add(*category) update_hotel.save() if data.get("tags") != "": tags = data.get("tags").split(",") print(tags) update_hotel.tags.add(*tags) update_hotel.save() log_register = Logs(user=data.get("user"), action=Actions.action_update, name_model='Hotel', id_handle=update_hotel.id) log_register.save() return update_hotel.id except Exception as e: print(e) return 0
def eventChallengesDel(request,event_id,challenge_id): if request.user.is_staff: challenge = Challenges.objects.get(id=challenge_id) event = Events.objects.get(id=event_id) EventsChallenges.objects.get(event=event,challenge=challenge).delete() print Logs(user_logged=request.user,function='events',message='del %s challenge on %s Event' % (challenge.name,event.name)).save() return redirect('eventChallenges',event_id)
def challengeEdit(request, challenge_id): categorys = Challenges._meta.get_field('category').choices challenge = Challenges.objects.get(id=challenge_id) if request.user.id == challenge.created_by.id or request.user.is_staff: if request.method == "POST": data = request.POST user = User.objects.get(id=request.user.id) chall_file = request.FILES[ 'chall_file'] if 'chall_file' in request.FILES else challenge.chall_file challenge.name = data['name'] challenge.points = data['points'] challenge.flag = data['flag'] challenge.description = data['description'] challenge.writeup = data['writeup'] challenge.category = data['category'] challenge.chall_file = chall_file challenge.save(update_fields=[ "name", "points", "description", "writeup", "category", "chall_file", "flag" ]) Logs(user_logged=request.user, function='challenges', message='Edit %s challenge' % data['name']).save() return redirect('challenges') return render(request, 'challenge_register.html', { 'categorys': categorys, 'challenge': challenge }) return redirect('challenges')
def challengeDelete(request, challenge_id): challenge = Challenges.objects.get(id=challenge_id) if request.user.id == challenge.created_by.id or request.user.is_staff: print Logs(user_logged=request.user, function='challenges', message='Delete %s challenge' % challenge.name).save() challenge.delete() return redirect('challenges')
def userDelete(request, sysuser_id): if request.user.id != int(sysuser_id): user = User.objects.get(id=sysuser_id) Logs(user_logged=request.user, function='users', message='Delete %s user' % user.username).save() user.delete() return redirect('usersView')
def create(self, data): """ this serializers handles registration new Hotel """ try: status = data.get("status") date_now = datetime.now().strftime('%Y-%m-%d') if data.get("date_publish") != "": if date_now != data.get("date_publish"): status = Hotel.INACTIVE newHotel = Hotel(name=data.get("name"), type_document_id=data.get("type_document_id"), number_document=data.get("number_document"), city_id=data.get("city_id"), owner=data.get("owner"), date_publish=data.get("date_publish") if data.get("date_publish") != "" else None, date_inactive=data.get("date_inactive") if data.get("date_inactive") != "" else None, status=status) newHotel.save() if data.get("category") != "": category = data.get("category").split(",") newHotel.category.add(*category) newHotel.save() if data.get("tags") != "": tags = data.get("tags").split(",") newHotel.tags.add(*tags) newHotel.save() log_register = Logs(user=data.get("user"), action=Actions.action_create, name_model='Hotel', id_handle=newHotel.id) log_register.save() return newHotel.id except Exception as e: print(e) return 0
def delete(self, request): try: TypeRoom.objects.get(pk=request.data["room_id"]).delete() log_register = Logs(user=request.user, action=Actions.action_delete, name_model='Room', id_handle=request.data["room_id"]) log_register.save() return Response({ 'error': False, 'message': "OK" }, status=status.HTTP_200_OK) except Exception as e: return Response({ 'error': True, 'message': "ERROR_SERVER" }, status=status.HTTP_400_BAD_REQUEST)
def money_check(check_user): """ Нужно чтоб были импортированы: UserProfile, User, Post, Logs requests, lxml.html """ pr_user = UserProfile.objects.get(user_id=check_user.id) try: r = requests.post( 'http://www.wimagic.com.ua/1.php', # 'http://www.wimagicss.com.ua/1.php', data = { 'login':check_user.username, 'pass':pr_user.pwd } ) html = lxml.html.fromstring(r.text) money_r = html.xpath("/html/body/table/tr[1]/td[4]/text()")[0] new = Post(money=money_r, user=check_user) new.save() log = Logs(log_user = check_user, log_type = 6, log_status = LOGSTATUSYES,) log.save() except: log = Logs(log_user = check_user, log_type = 6, log_status = LOGSTATUSNO,) log.save()
def userPassword(request): sysuser = User.objects.get(id=request.user.id) if request.method == 'POST': data = request.POST if sysuser.check_password( data['actual_password'] ) and data['new_password'] == data['conf_password']: sysuser.set_password(data['new_password']) sysuser.save() Logs(user_logged=request.user, function='users', message='Change password').save() return redirect('dashboard') return render(request, 'userPassword.html')
def user_login(request): if request.user is not None: logout(request) if request.method == 'POST': form = LoginUserForm(request.POST) if form.is_valid(): user = authenticate(username=form.cleaned_data['user_name'], password=form.cleaned_data['user_pass'] ) if user is not None: login(request, user) log = Logs(log_user = user, log_type = 3, log_status = LOGSTATUSYES,) log.save() return HttpResponseRedirect('/user/'+request.user.username+'/') else: data = { 'user_name': form.cleaned_data['user_name'], 'user_pass': form.cleaned_data['user_pass'], } form = LoginUserForm(initial=data) else: form = LoginUserForm() return render(request, 'userprofile/user_login.html', {'form': form,})
def create(self, data): """ this serializers handles registration creates a Room """ try: status = data.get("status") date_now = datetime.now().strftime('%Y-%m-%d') if data.get("date_publish") != "": if date_now != data.get("date_publish"): status = TypeRoom.INACTIVE newRoom = TypeRoom(name=data.get("name"), hotel_id=data.get("hotel_id"), enable=data.get("enable"), price=data.get("price"), count_person=data.get("count_person"), description=data.get("description"), owner=data.get("owner"), date_publish=data.get("date_publish") if data.get("date_publish") != "" else None, date_inactive=data.get("date_inactive") if data.get("date_inactive") != "" else None, status=status) newRoom.save() log_register = Logs(user=data.get("user"), action=Actions.action_create, name_model='Room', id_handle=newRoom.id) log_register.save() return newRoom.id except Exception as e: print(e) return 0
def readd_all_commits(request): if request.user.is_superuser: try: all_commits = go_news_commit() News.objects.filter(news_type=2).delete() for news_date, news_text in go_news_commit().items(): news_item = News( title = news_text, created_date = datetime.strptime(news_date, '%Y-%m-%d %H:%M:%S'), news_type = 2, parsed_date = timezone.now(), ) news_item.save() data = { 'news_commit': go_news_commit(), } log = Logs( log_user = request.user, log_type = 7, log_status = LOGSTATUSYES, ) log.save() state = { 'state_type':'success', 'state_message':'<strong>Отлично!</strong> Все прошло как надо! Добавлено коммитов: %s' % (len(all_commits)), } data = { 'news_commit': all_commits, 'state':state, } return render(request, 'admin/readd_all_commits.html', data,) except Exception as inst: import sys log = Logs( log_user = request.user, log_type = 7, log_status = LOGSTATUSNO, ) log.save() state = { 'state_type':'danger', 'state_message':inst, } data = { 'state':state, } return render(request, 'admin/readd_all_news_wed.html', data,) else: return HttpResponseRedirect('/')
def userRegister(request): if request.method == 'POST': data = request.POST staff = True if 'staff' in data else False user = User.objects.create_user(username=data['username'], email=data['email'], password=data['password'], first_name=data['first_name'], last_name=data['last_name'], is_staff=staff) Logs(user_logged=request.user, function='users', message='Create %s user' % data['username']).save() return redirect('usersView') return render(request, 'userRegister.html')
def userEdit(request, sysuser_id): sysuser = User.objects.get(id=sysuser_id) if request.method == 'POST': data = request.POST staff = True if 'staff' in data else False sysuser.email = data['email'] sysuser.first_name = data['first_name'] sysuser.last_name = data['last_name'] sysuser.is_staff = staff sysuser.save( update_fields=["email", "first_name", "last_name", "is_staff"]) Logs(user_logged=request.user, function='users', message='Edit %s user' % sysuser.username).save() return redirect('usersView') return render(request, 'userRegister.html', {'sysuser': sysuser})
def create(self, data): """ this serializers handles registration creates a User, Profile """ try: newUser = User.objects.create_user( username=data.get("email"), first_name=data.get("first_name"), last_name=data.get("last_name"), email=data.get("email")) user_model = User.objects.get(pk=newUser.id) user_model.set_password(data.get('password')) user_model.save() log_register = Logs(user=newUser, action=Actions.action_create, name_model='User', id_handle=newUser.id) log_register.save() newProfile = Profile(user_id=newUser.id, phone=data.get("phone"), date_birth=data.get("date_birth"), gender=data.get("gender"), type_document_id=data.get("type_document_id"), number_document=data.get("number_document")) newProfile.save() log_register = Logs(user=newUser, action=Actions.action_create, name_model='Profile', id_handle=newProfile.id) log_register.save() return newProfile.id except Exception as e: print(e) return 0
def eventEdit(request,event_id): event = Events.objects.get(id=event_id) if request.user.is_staff: if request.method == "POST": event_logo = request.FILES['event_logo'] if 'event_logo' in request.FILES else event.event_logo event_wallpaper = request.FILES['event_wallpaper'] if 'event_wallpaper' in request.FILES else event.event_wallpaper data = request.POST event.name=data['name'] event.description=data['description'] event.prize=data['prize'] event.start_date=parse_datetime(data['start_date']) event.end_date=parse_datetime(data['end_date']) event.event_wallpaper = event_wallpaper event.event_logo=event_logo event.save(update_fields=["name","description","prize","start_date","end_date","event_logo","event_wallpaper"]) Logs(user_logged=request.user,function='events',message='Edit %s event' % data['name']).save() return redirect('events') return render(request,'eventRegister.html',{'event':event}) return redirect('events')
def eventRegister(request): if request.user.is_staff: if request.method == "POST": event_logo = request.FILES['event_logo'] if 'event_logo' in request.FILES else None event_wallpaper = request.FILES['event_wallpaper'] if 'event_wallpaper' in request.FILES else None data = request.POST user = User.objects.get(id=request.user.id) Events(name=data['name'], description=data['description'], prize=data['prize'], start_date=parse_datetime(data['start_date']), event_wallpaper=event_wallpaper, event_logo=event_logo, end_date=parse_datetime(data['end_date']), created_by=user).save() print Logs(user_logged=request.user,function='events',message='Create %s Event' % data['name']).save() return redirect('events') else: return redirect('events') return render(request,'eventRegister.html')
def challengeRegister(request): categorys = Challenges._meta.get_field('category').choices if request.method == "POST": data = request.POST chall_file = request.FILES[ 'chall_file'] if 'chall_file' in request.FILES else None user = User.objects.get(id=request.user.id) Challenges(name=data['name'], points=data['points'], description=data['description'], writeup=data['writeup'], category=data['category'], chall_file=chall_file, flag=data['flag'], created_by=user).save() print Logs(user_logged=request.user, function='challenges', message='Create %s challenge' % data['name']).save() return redirect('challenges') return render(request, 'challenge_register.html', {'categorys': categorys})
def create(self, data): """ this serializers handles new reservation """ try: sw = 0 room = TypeRoom.objects.get(pk=data.get("type_room_id")) if data.get("date_initial") != "" and data.get( "date_initial") != "": query_reservation = Reservation.objects.filter( type_room_id=data.get("type_room_id"), date_initial__range=[ data.get("date_initial"), data.get("date_end") ], date_end__range=[ data.get("date_initial"), data.get("date_end") ]) review = int(room.enable) - len(query_reservation) if review <= 0: sw = 1 if sw == 1: return -1 newGuest = Guest(full_name=data.get("full_name"), date_birth=data.get("date_birth"), gender=data.get("gender"), type_document_id=data.get("type_document_id"), number_document=data.get("number_document"), email=data.get("email"), phone=data.get("phone")) newGuest.save() log_register = Logs(user=data.get("user"), action=Actions.action_create, name_model='Guest', id_handle=newGuest.id) log_register.save() newReservation = Reservation(guest=newGuest, type_room_id=data.get("type_room_id"), date_initial=data.get("date_initial"), date_end=data.get("date_end"), description=data.get("description")) newReservation.save() log_register = Logs(user=data.get("user"), action=Actions.action_create, name_model='Reservation', id_handle=newReservation.id) log_register.save() return newReservation.id except Exception as e: print(e) return 0
def eventDelete(request,event_id): event = Events.objects.get(id=event_id) if request.user.is_staff: print Logs(user_logged=request.user,function='events',message='Delete %s event' % event.name).save() event.delete() return redirect('events')
def user_logout(request): if request.user is not None: log = Logs(log_user = request.user, log_type = 5, log_status = LOGSTATUSYES,) log.save() logout(request) return HttpResponseRedirect('/')