def profile(self, request, profile_id=0, *args, **kwargs): if profile_id == 0: selected_profile = ProfileRepo(user=request.user).me else: selected_profile = ProfileRepo(user=request.user).get( profile_id=profile_id) context = getContext(request) context['body_class'] = 'profile-page' context['selected_profile'] = selected_profile return render(request, TEMPLATE_ROOT + 'profile.html', context)
def add_resume_category(self, request, *args, **kwargs): level = 1 user = request.user profile = ProfileRepo(user=user).me if request.method == 'POST' and profile is not None: level = 2 add_resume_category_form = AddResumeCategoryForm(request.POST) if add_resume_category_form.is_valid(): level = 3 title = add_resume_category_form.cleaned_data['title'] profile_id = add_resume_category_form.cleaned_data[ 'profile_id'] resume_category = ResumeCategoryRepo(user=user).add( profile_id=profile_id, title=title) if resume_category is not None: resume_category_s = ResumeCategorySerializer( resume_category).data return JsonResponse({ 'resume_category': resume_category_s, 'result': SUCCEED }) return JsonResponse({'result': FAILED, 'level': level})
def add_resume(self, request, *args, **kwargs): level = 1 user = request.user profile = ProfileRepo(user=user).me if request.method == 'POST' and profile is not None: level = 2 add_resume_form = AddResumeForm(request.POST) if add_resume_form.is_valid(): level = 3 title = add_resume_form.cleaned_data['title'] category_id = add_resume_form.cleaned_data['category_id'] app_name = add_resume_form.cleaned_data['app_name'] resume = ResumeRepo(user=user).add(app_name=app_name, category_id=category_id, title=title) if resume is not None: resume_s = ResumeSerializer(resume).data return JsonResponse({ 'resume': resume_s, 'result': SUCCEED }) return JsonResponse({'result': FAILED, 'level': level})
def add_document(self, request, *args, **kwargs): level = 1 user = request.user profile = ProfileRepo(user=user).me if request.method == 'POST' and profile is not None: level = 2 add_document_form = AddDocumentForm(request.POST, request.FILES) if add_document_form.is_valid(): level = 3 title = add_document_form.cleaned_data['title'] page_id = add_document_form.cleaned_data['page_id'] file1 = request.FILES['file1'] page = PageRepo(user=user).add_document(page_id=page_id, file1=file1, title=title) if page is not None: level = 4 documents = page.documents.all() documents_s = DocumentSerializer(documents, many=True).data return JsonResponse({ 'documents': documents_s, 'result': SUCCEED }) return JsonResponse({'result': FAILED, 'level': level})
def get_user_cart_for_api(self): user=self.user if user.is_authenticated: profile = ProfileRepo(user=self.user).me if profile is not None: orders=[] cart_total=0 cart_lines_total=0 cart_lines = CartLine.objects.filter(profile=profile) shops = Shop.objects.filter( id__in=cart_lines.values('shop_id')) for supplier in Supplier.objects.filter(id__in=shops.values('supplier_id')): order = Order() order.supplier = supplier order.ship_fee = supplier.ship_fee lines_total = 0 for line in cart_lines: if line.shop.supplier == supplier: lines_total = lines_total+(line.quantity*line.shop.price) order.lines_total = lines_total total = lines_total+supplier.ship_fee order.total = total cart_total=cart_total+total cart_lines_total=cart_lines_total+lines_total orders.append(order) return {'lines':cart_lines,'orders':orders,'total':cart_total,'lines_total':cart_lines_total}
def add_image(self, request, *args, **kwargs): level = 1 user = request.user profile = ProfileRepo(user=user).me if request.method == 'POST' and profile is not None: level = 2 add_image_form = AddImageForm(request.POST, request.FILES) if add_image_form.is_valid(): level = 3 image_title = add_image_form.cleaned_data['title'] page_id = add_image_form.cleaned_data['page_id'] image_description = add_image_form.cleaned_data['description'] location = add_image_form.cleaned_data['location'] image = request.FILES['image'] thumbnail = request.FILES['thumbnail'] page = PageRepo(user=user).add_image( page_id=page_id, image=image, thumbnail=thumbnail, location=location, image_title=image_title, image_description=image_description) if page is not None: level = 4 images = page.images.all() images_s = GalleryPhotoSerializer(images, many=True).data return JsonResponse({ 'images': images_s, 'result': SUCCEED }) return JsonResponse({'result': FAILED, 'level': level})
def __init__(self, user): self.objects = Employee.objects self.user = user self.profile = ProfileRepo(user=user).me try: self.me = self.objects.get(profile=self.profile) except: self.me = None
def __init__(self, user=None): self.objects = Contractor.objects self.user = user self.profile = ProfileRepo(user=user).me try: self.me = self.objects.get(profile=self.profile) except: self.me = None
def get_profiles(self, channel_event_id): list1 = self.objects.filter(channel_event_id=channel_event_id) profiles = [] for item in list1: profiles.append( ProfileRepo(user=self.user).get(profile_id=item.profile_id)) return profiles
def add_comment(self,product_id,comment): profile=ProfileRepo(user=self.user).me if profile is not None: product_comment=ProductComment() product_comment.profile=profile product_comment.product=self.objects.get(pk=product_id) product_comment.comment=comment; product_comment.save() return product_comment
def profile(self,request,profile_id=0,*args,**kwargs): context=getContext(request) if profile_id==0: selected_profile=ProfileRepo(user=request.user).me else: selected_profile=ProfileRepo(user=request.user).get(profile_id=profile_id) if selected_profile is None: raise Http404 context['body_class']='profile-page' context['selected_profile']=selected_profile if selected_profile is not None: context['add_resume_category_form']=AddResumeCategoryForm() context['add_resume_form']=AddResumeForm() resumecategories=selected_profile.resumecategory_set.all() resumecategories_s=json.dumps(ResumeCategorySerializer(resumecategories,many=True).data) context['resumecategories_s']=resumecategories_s return render(request,TEMPLATE_ROOT+'profile.html',context)
def add_message(self, text, channelevent_id): channelevent = self.get(channel_event_id=channelevent_id) profile = ProfileRepo(user=self.user).me if profile is None or channelevent is None: return None message = Message(profile=profile, text=text, channelevent=channelevent) message.save() return message
def profile_customization(self, request, *args, **kwargs): if request.method == 'POST': profile_customization_form = ProfileCustomizationForm(request.POST) if profile_customization_form.is_valid(): line_key = profile_customization_form.cleaned_data['line_key'] line_value = profile_customization_form.cleaned_data[ 'line_value'] user = request.user profile = ProfileRepo(user=user).me if profile is not None: profile_customization = profile.profile_customization() if profile_customization is None: profile_customization = ProfileCustomization( profile=profile) profile_customization.save() profile_customization.set_value(line_key=line_key, line_value=line_value) profile_customization.save() return JsonResponse({'result': SUCCEED}) return JsonResponse({'result': FAILED})
def __init__(self,user=None): self.user=user self.objects=Shipper.objects self.profile=ProfileRepo(user=self.user).me if self.profile is not None: try: self.me=self.objects.get(profile_id=self.profile.id) except: self.me=None else: self.me=None
def related(self,product_id): product=self.get(product_id=product_id) user=self.user region=None if user is not None: profile=ProfileRepo(user=self.user).me if profile is not None: region=profile.region products=product.related.all() for product in products: product.price=Shop.objects.filter(product_id=product.id).filter(supplier__in=Supplier.objects.filter(region=region)).aggregate(Min('price'))['price__min'] return products
def list(self,category_id=0): user=self.user region=None if user is not None: profile=ProfileRepo(user=self.user).me if profile is not None: region=profile.region if category_id == 0: return [] products=self.objects.filter(category_id=category_id).order_by('priority') for product in products: product.price=Shop.objects.filter(product_id=product.id).filter(supplier__in=Supplier.objects.filter(region=region)).aggregate(Min('price'))['price__min'] return products
def get(self,product_id): user=self.user region=None if user is not None: profile=ProfileRepo(user=self.user).me if profile is not None: region=profile.region try: product = self.objects.get(pk=product_id) product.category=CategoryRepo(user=user).get(category_id=product.category_id) product.price=Shop.objects.filter(product_id=product.id).filter(supplier__in=Supplier.objects.filter(region=region)).aggregate(Min('price'))['price__min'] except ObjectDoesNotExist: product = None return product
def search(self,search_for): user=self.user region=None if user is not None: profile=ProfileRepo(user=self.user).me if profile is not None: region=profile.region products=self.objects.filter(Q(name__contains=search_for) | Q(model_name__contains=search_for) ) for product in products: product.price=Shop.objects.filter(product_id=product.id).filter(supplier__in=Supplier.objects.filter(region=region)).aggregate(Min('price'))['price__min'] categories=Category.objects.filter(name__contains=search_for) suppliers=Supplier.objects.filter(title__contains=search_for) return {'products':products,'categories':categories,'suppliers':suppliers}
def confirm_order(self, order_id, description): profile = ProfileRepo(user=self.user).me if profile is None: return None order = Order.objects.get(pk=order_id) if order.profile == profile and order.status == OrderStatusEnum.CANCELED: order.status = OrderStatusEnum.CONFIRMED if order.description is None: order.description = '' if description is not None: order.description = order.description+' @ ' + \ order.profile.full_name()+' # تایید مجدد '+PersianCalendar().from_gregorian(datetime.datetime.now())+' : '+str(description) order.save() if order is not None: return order
def add(self, name,category_id,unit_name=None): user=self.user product = Product(name=name, category_id=category_id) default_unit=ProductUnitRepo(user=self.user).get_by_name(name=unit_name) if ProductUnitRepo(user=self.user).get_by_name(name=unit_name) is not None else ProductUnitRepo(user=self.user).get_default() if user.has_perm(f'{APP_NAME}.add_product'): if category_id == 0: return None else: product.category = CategoryRepo(user=user).get(category_id=category_id) product.adder = ProfileRepo(user=self.user).me product.save() product.unit_names.add(default_unit) product.save() return product return None
def do_signature(self, status, description, materialrequest_id): profile = ProfileRepo(user=self.user).me if profile is not None: materialrequest = self.materialrequest( materialrequest_id=materialrequest_id) if materialrequest is not None: signature = MaterialRequestSignature( profile=profile, status=status, description=description, materialrequest=materialrequest) signature.save() materialrequest.status = status materialrequest.save() return signature
def delete_comment(self, request, *args, **kwargs): level = 1 user = request.user profile = ProfileRepo(user=user).me if request.method == 'POST' and profile is not None: level = 2 delete_comment_form = DeleteCommentForm(request.POST) if delete_comment_form.is_valid(): level = 3 comment_id = delete_comment_form.cleaned_data['comment_id'] comments = CommentRepo(user=user).delete(comment_id=comment_id) if comments is not None: comments_s = CommentSerializer(comments, many=True).data return JsonResponse({ 'comments': comments_s, 'result': SUCCEED }) return JsonResponse({'result': FAILED, 'level': level})
def add_comment(self, request, *args, **kwargs): level = 1 user = request.user profile = ProfileRepo(user=user).me if request.method == 'POST' and profile is not None: level = 2 add_comment_form = AddCommentForm(request.POST) if add_comment_form.is_valid(): level = 3 text = add_comment_form.cleaned_data['text'] page_id = add_comment_form.cleaned_data['page_id'] comments = CommentRepo(user=user).add(page_id=page_id, text=text) if comments is not None: comments_s = CommentSerializer(comments, many=True).data return JsonResponse({ 'comments': comments_s, 'result': SUCCEED }) return JsonResponse({'result': FAILED, 'level': level})
def add_link(self, request, *args, **kwargs): level = 1 user = request.user profile = ProfileRepo(user=user).me if request.method == 'POST' and profile is not None: level = 2 add_link_form = AddLinkForm(request.POST) if add_link_form.is_valid(): level = 3 title = add_link_form.cleaned_data['title'] url = add_link_form.cleaned_data['url'] page_id = add_link_form.cleaned_data['page_id'] page = PageRepo(user=user).add_link(page_id=page_id, url=url, title=title) if page is not None: level = 4 links = page.links.all() link_s = LinkSerializer(links, many=True).data return JsonResponse({'links': link_s, 'result': SUCCEED}) return JsonResponse({'result': FAILED, 'level': level})
def __init__(self,user=None): self.user=user self.profile=ProfileRepo(user=self.user).me
def __init__(self, user): self.objects = PusherChannelEvent.objects self.user = user self.profile = ProfileRepo(user=user).me
def __init__(self, user=None): self.objects = Event.objects self.user = user self.profile = ProfileRepo(user=user).me
def __init__(self, user=None): self.objects = ArchiveDocument.objects self.user = user self.profile = ProfileRepo(user=user).me
def __init__(self, user): self.objects = Assignment.objects self.user = user self.profile = ProfileRepo(user=user).me
def __init__(self, user=None): self.objects = Project.objects self.user = user self.profile = ProfileRepo(user=self.user).me self.me_employee = EmployeeRepo(user=self.user).me self.me_contractor = ContractorRepo(user=self.user).me