Esempio n. 1
0
 def register(self, request):
     if request.method == 'POST':
         register_form = RegisterForm(request.POST)
         if register_form.is_valid():
             region_id = register_form.cleaned_data['region_id']
             username = register_form.cleaned_data['username']
             password = register_form.cleaned_data['password']
             first_name = register_form.cleaned_data['first_name']
             last_name = register_form.cleaned_data['last_name']
             profile = ProfileRepo(user=request.user).register(
                 username=username,
                 password=password,
                 first_name=first_name,
                 last_name=last_name,
                 region_id=region_id)
             if profile is not None:
                 user = profile.user
                 if user is not None:
                     request1 = ProfileRepo(user=request.user).login(
                         request=request,
                         username=user.username,
                         password=password)
                     if request1 is not None and request1.user.is_authenticated:
                         CreateProfiles(profile=profile)
                         return redirect(reverse('app:home'))
         context = getContext(request)
         context['login_form'] = LoginForm()
         context['register_form'] = RegisterForm()
         context['reset_password_form'] = ResetPasswordForm()
         context['regions'] = RegionRepo(user=request.user).list()
         return render(request,
                       TEMPLATE_ROOT + 'login.html',
                       context=context)
     else:
         return redirect(reverse('authentication:login'))
Esempio n. 2
0
    def edit_profile(self, request):
        if not request.method == 'POST':
            return redirect('app:home')
        edit_profile_form = EditProfileForm(request.POST)
        if edit_profile_form.is_valid():

            profile_id = edit_profile_form.cleaned_data['profile_id']
            first_name = edit_profile_form.cleaned_data['first_name']
            last_name = edit_profile_form.cleaned_data['last_name']
            region_id = edit_profile_form.cleaned_data['region_id']
            mobile = edit_profile_form.cleaned_data['mobile']
            bio = edit_profile_form.cleaned_data['bio']
            address = edit_profile_form.cleaned_data['address']
            postal_code = edit_profile_form.cleaned_data['postal_code']
            # print(new_profile['bio'])
            profile = ProfileRepo(user=request.user).edit_profile(
                profile_id=profile_id,
                first_name=first_name,
                last_name=last_name,
                mobile=mobile,
                region_id=region_id,
                address=address,
                postal_code=postal_code,
                bio=bio)
        return redirect(
            reverse('app:profile', kwargs={'profile_id': profile.pk}))
Esempio n. 3
0
    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
                }
Esempio n. 4
0
    def reset_password(self, request):
        user = request.user
        if request.method == 'POST':
            reset_password_form = ResetPasswordForm(request.POST)
            if reset_password_form.is_valid():
                username = reset_password_form.cleaned_data['username']
                old_password = reset_password_form.cleaned_data['old_password']
                new_password = reset_password_form.cleaned_data['new_password']
                request1 = ProfileRepo(user=request.user).reset_password(
                    request=request,
                    username=username,
                    old_password=old_password,
                    new_password=new_password)
                if request1 is not None:
                    return redirect(reverse('projectmanager:home'))

            context = getContext(request)
            context['message'] = 'نام کاربری و کلمه عبور صحیح نمی باشد'

            context['login_form'] = LoginForm()
            context['register_form'] = RegisterForm()
            context['reset_password_form'] = ResetPasswordForm()
            context['regions'] = RegionRepo(user=request.user).list()

            return render(request,
                          TEMPLATE_ROOT + 'login.html',
                          context=context)
        else:
            return redirect(reverse('authentication:login'))
Esempio n. 5
0
    def auth(self, request, *args, **kwargs):

        if request.method == 'POST':
            login_form = LoginForm(request.POST)
            if login_form.is_valid():
                username = login_form.cleaned_data['username']
                password = login_form.cleaned_data['password']
                back_url = login_form.cleaned_data['back_url']
                if back_url is None or not back_url:
                    back_url = reverse('app:my_profile')
                request1 = ProfileRepo().login(request=request,
                                               username=username,
                                               password=password)
                if request1 is not None and request1.user is not None and request1.user.is_authenticated:
                    return redirect(back_url)
                else:
                    context = getContext(request=request)
                    context['message'] = 'نام کاربری و کلمه عبور صحیح نمی باشد'
                    context['login_form'] = LoginForm()
                    context['register_form'] = RegisterForm()
                    context['back_url'] = back_url
                    context['reset_password_form'] = ResetPasswordForm()
                    return render(request, TEMPLATE_ROOT + 'login.html',
                                  context)
        else:
            return redirect(reverse('authentication:login'))
Esempio n. 6
0
 def __init__(self, user):
     self.user = user
     self.objects = FinancialProfile.objects
     self.profile = ProfileRepo(user=user).me
     try:
         self.me = self.objects.get(profile=self.profile)
     except:
         self.me = None
Esempio n. 7
0
    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
Esempio n. 8
0
 def change_profile(self, request):
     if not request.method == 'POST':
         return redirect('app:home')
     change_profile_form = ChangeProfileForm(request.POST)
     if change_profile_form.is_valid():
         actived = change_profile_form.cleaned_data['actived']
         profile = ProfileRepo(user=request.user).change_profile(
             user=request.user, actived=actived)
     return redirect(reverse('app:home'))
Esempio n. 9
0
    def __init__(self, user=None):
        self.user = user
        self.objects = Customer.objects

        self.profile = ProfileRepo(user=user).me
        try:
            self.me = self.objects.get(profile=self.profile)
        except:
            self.me = None
Esempio n. 10
0
 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
Esempio n. 11
0
 def change_profile_image(self, request):
     upload_profile_image_form = UploadProfileImageForm(
         request.POST, request.FILES)
     if upload_profile_image_form.is_valid():
         image = request.FILES['image']
         profile_id = upload_profile_image_form.cleaned_data['profile_id']
         ProfileRepo(user=request.user).change_profile_image(
             profile_id=profile_id, image=image)
         return redirect(
             reverse('app:profile', kwargs={'profile_id': profile_id}))
Esempio n. 12
0
 def delete_model(self, request, obj):
     user = request.user
     profile = ProfileRepo(user=user).me
     log = PageLog(page=obj,
                   manager_page_id=obj.pk,
                   name=obj.title,
                   profile=profile,
                   action=LogActionEnum.DELETE)
     log.save()
     super().delete_model(request, obj)
Esempio n. 13
0
 def __init__(self, user=None):
     self.objects = Contractor.objects
     self.user = user
     self.profile = ProfileRepo(user=user).me
     self.me = None
     try:
         if self.profile is not None:
             self.me = self.objects.get(profile=self.profile)
     except:
         pass
Esempio n. 14
0
 def save_model(self, request, obj, form, change):
     super().save_model(request, obj, form, change)
     user = request.user
     profile = ProfileRepo(user=user).me
     log = PageLog(page=obj,
                   manager_page_id=obj.pk,
                   name=obj.title,
                   profile=profile,
                   action=LogActionEnum.SAVE)
     log.save()
Esempio n. 15
0
 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
Esempio n. 16
0
 def transactions(self, request, profile_id, *args, **kwargs):
     user = request.user
     profile = ProfileRepo(user=user).get(profile_id=profile_id)
     context = getContext(request=request)
     transaction_repo = ProfileTransactionRepo(user=user)
     transactions = transaction_repo.list(profile_id=profile_id)
     context['transactions'] = transactions
     context['transaction_title'] = profile.name
     context['rest_all'] = transaction_repo.rest(profile_id=profile_id)
     return render(request, TEMPLATE_ROOT_DASHBOARD + 'transactions.html',
                   context)
Esempio n. 17
0
 def add_link(self, title, manager_page_id):
     manager_page = self.page(page_id=manager_page_id)
     if manager_page is not None and self.user and self.user.has_perm(
             APP_NAME + '.add_link'):
         profile = ProfileRepo(user=self.user).me
         if profile is not None:
             link = Link(title=title, icon_material='link', profile=profile)
             link.save()
             manager_page.links.add(link)
         return True
     return False
Esempio n. 18
0
 def __init__(self, user=None):
     self.user = user
     self.objects = Employee.objects
     self.profile = ProfileRepo(user=user).me
     try:
         self.me = Employee.objects.filter(profile=self.profile).first()
     except:
         self.me = None
     try:
         self.me = self.objects.get(profile=self.profile)
     except:
         self.me = None
Esempio n. 19
0
 def save_model(self, request, obj, form, change):
     if obj.location:
         obj.location = obj.location.replace('width="600"', 'width="100%"')
         obj.location = obj.location.replace('height="450"', 'height="400"')
     super().save_model(request, obj, form, change)
     user = request.user
     profile = ProfileRepo(user=user).me
     log = PageLog(page=obj,
                   manager_page_id=obj.pk,
                   name=obj.title,
                   profile=profile,
                   action=LogActionEnum.SAVE)
     log.save()
Esempio n. 20
0
 def add_document(self, title, manager_page_id):
     manager_page = self.page(page_id=manager_page_id)
     if manager_page is not None and self.user and self.user.has_perm(
             APP_NAME + '.add_link'):
         profile = ProfileRepo(user=self.user).me
         if profile is not None:
             document = Document(title=title,
                                 icon_material='get_app',
                                 profile=profile)
             document.save()
             manager_page.documents.add(document)
         return True
     return False
Esempio n. 21
0
 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
Esempio n. 22
0
 def __init__(self, user):
     self.objects = Employee.objects
     self.user = user
     self.profile = ProfileRepo(user=user).me
     self.me = None
     #must be deleted
     # print('self.profile')
     # print(self.profile)
     if self.profile is None:
         self.me = None
     else:
         try:
             self.me = self.objects.get(profile=self.profile)
         except:
             self.me = None
Esempio n. 23
0
    def profile(self, request, profile_id=0):
        user = request.user
        context = getContext(request=request)
        if not user.is_authenticated:
            return redirect(reverse("authentication:login"))
        active_profile = ProfileRepo(user=user).me
        # input(active_profile)
        if profile_id == 0:
            selected_profile = ProfileRepo(user=user).me
        else:
            selected_profile = ProfileRepo(user=user).get(
                profile_id=profile_id)
            # input(selected_profile)
        if selected_profile is None:
            raise Http404
        context['my_permissions'] = ProfileRepo(
            user=request.user).my_permissions()

        context['selected_profile'] = selected_profile
        if (selected_profile is not None
                and selected_profile.user == request.user
            ) or request.user.has_perm(f'{APP_NAME}.change_profile'):
            context['regions'] = RegionRepo(user=user).list().exclude(
                pk=selected_profile.region_id)
            context['edit_profile_form'] = EditProfileForm()
            context['upload_profile_image_form'] = UploadProfileImageForm()

        if selected_profile.user == request.user or request.user.has_perm(
                f'{APP_NAME}.view_profiletransaction'):
            transaction_repo = ProfileTransactionRepo(user=user)
            transactions = transaction_repo.list(profile_id=profile_id)[:20]
            context['transactions'] = transactions
            context['rest'] = transaction_repo.rest(profile_id=profile_id)

        return render(request, TEMPLATE_ROOT_DASHBOARD + 'profile.html',
                      context)
Esempio n. 24
0
 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
Esempio n. 25
0
    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
Esempio n. 26
0
 def manager(self, request):
     user = request.user
     if user is None or not user.is_authenticated:
         return BasicView().home(request)
     context = getContext(request=request)
     priority_range = range(6)
     context['priority_range'] = priority_range
     site_profiles = ProfileRepo(user=user).list_all()
     icons = list(IconsEnum)
     context['icons_s'] = json.dumps(icons)
     context['site_profiles'] = site_profiles
     if user.has_perm('app.add_notification'):
         add_notification_form = AddNotificationForm()
         context['add_notification_form'] = add_notification_form
         return render(request, TEMPLATE_ROOT_DASHBOARD + 'manager.html',
                       context)
     return BasicView().home(request)
Esempio n. 27
0
 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
Esempio n. 28
0
    def search(self, request, *args, **kwargs):
        user = request.user
        if request.method == 'POST':
            search_form = SearchForm(request.POST)
            if search_form.is_valid():
                search_for = search_form.cleaned_data['search_for']
                context = getContext(request)
                context['pages'] = ManagerPageRepo(user=user).search(
                    search_for=search_for)
                context['search_for'] = search_for
                cont_repo = ContractorRepo(user=user)
                context['contractors'] = cont_repo.search(
                    search_for=search_for)
                context['profiles'] = ProfileRepo(user=user).search(
                    search_for=search_for)
                context['materialobjects'] = MaterialObjectRepo(
                    user=user).search(search_for=search_for)

                return render(request, TEMPLATE_ROOT + 'search.html', context)
Esempio n. 29
0
 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
Esempio n. 30
0
    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
        }