Commit 11a3efa2 authored by CepbluKot's avatar CepbluKot
Browse files

upd

parent fd4b206b
......@@ -56,6 +56,7 @@ def all_advertisments():
api_all_adv = AdvertisementSchema(many=True)
return api_all_adv.dump(data_query)
def filter_advertisments(id_adv=None):
data_query = _base_query()
......@@ -67,6 +68,16 @@ def filter_advertisments(id_adv=None):
return api_all_adv.dump(data_query)
# def filter_by_community_advertisments(id_adv=None):
# data_query = _base_query()
# if id_adv is not None:
# data_query = data_query.filter(Advertisement.id == id_adv)
# api_all_adv = AdvertisementSchema(many=True)
# return api_all_adv.dump(data_query)
def indexes_advertisments(indexes: list = None):
data_query = _base_query()
......@@ -77,6 +88,3 @@ def indexes_advertisments(indexes: list = None):
api_all_adv = AdvertisementSchema(many=True)
return api_all_adv.dump(data_query)
from web_setting import flask_app, ma, db
from models.all_models import Community
#from api.api_tags import TagsSchema
from api.api_employer import EmployerSchema
from api.api_categories import CategoriesSchema
from api.api_customers import CustomersSchema
from api.api_tags import TagsGlobalSchema
class CommunitySchema(ma.SQLAlchemyAutoSchema):
class Meta:
model = Community
load_instance = True
include_relationships = True
exclude = ['community_cus', 'tags_community_community']
# connect_customer = ma.Nested(CustomersSchema(exclude=('connect_com', 'customer_approve', 'id', )))
def _base_query():
return db.session.query(Community)
def all_communities():
data_query = _base_query()
api_all_community = CommunitySchema(many=True)
return api_all_community.dump(data_query)
def filter_communities(community_id=None):
data_query = _base_query()
if community_id is not None:
data_query = data_query.filter(Community.id == community_id)
api_all_adv = CommunitySchema(many=True)
return api_all_adv.dump(data_query)
from buisness_logic.coordinates_to_adress import location_from_address, location_from_coordinates
from models.all_models import Advertisement, CommunityAdv, СoordinatesEvent
from web_setting import flask_app, db
from models.all_models import Users, Employer, Customers, TagsUsers, ClickHistory
from werkzeug.security import generate_password_hash, check_password_hash
......@@ -43,6 +45,83 @@ def add_new_click(NewClick: TagsIndex):
def create_advertisement(adv_name, time_event, type_event, employer_id, coordinates_id, categories_id, wait_size_users):
new_advertisement = Advertisement(
new_adv_name=adv_name,
new_time_event=time_event,
new_type_event=type_event,
new_employer_id=employer_id,
new_coordinates_id=coordinates_id,
new_categories_id=categories_id,
new_wait_size_users=wait_size_users
)
db.session.add(new_advertisement)
db.session.commit()
return 'advert add success'
# def add_new_advertisement_to_community(adv_info, community_info):
# new_advertisement = Advertisement(
# new_adv_name=adv_info.adv_name,
# new_time_event=adv_info.time_event,
# new_type_event=adv_info.type_event,
# new_employer_id=adv_info.employer_id,
# new_coordinates_id=adv_info.coordinates_id,
# new_categories_id=adv_info.categories_id,
# new_wait_size_users=adv_info.wait_size_users
# )
# new_community_advertisement = CommunityAdv(
# new_community_id=,
# new_adv_id=,
# new_is_repost=False,
# new_reposted_by=
# )
# db.session.add(new_advertisement)
# db.session.commit()
# return 'advert for community add success'
def add_new_repost(adv_id, repost_to_community_id, reposter_user_id):
new_repost = CommunityAdv(
new_community_id=adv_id,
new_adv_id=repost_to_community_id,
new_is_repost=True,
new_reposted_by=reposter_user_id
)
# add new unique tags
db.session.add(new_repost)
db.session.commit()
return 'repost add success'
def add_new_address_from_coordinates(coordinates):
address = location_from_coordinates(coordinates)
new_data = СoordinatesEvent(
address=address,
coordinates=coordinates
)
db.session.add(new_data)
db.session.commit()
def add_new_coordinates_from_address(address):
coordinates = location_from_address(address)
new_data = СoordinatesEvent(
address=address,
coordinates=coordinates
)
db.session.add(new_data)
db.session.commit()
""" 1) Подписка на комьюнити и инскрт новых коммьюнити
2) Создание новых объявлений
3) обработка друзей и лоби"""
from web_setting import flask_app
from routers import entry_routers, \
admin_routers, users_routers, advertisement_routers
admin_routers, users_routers, advertisement_routers, community_routers
if __name__ == '__main__':
flask_app.run(host='0.0.0.0', debug=True)
\ No newline at end of file
......@@ -161,14 +161,14 @@ class Advertisement(db.Model):
categories_id = db.Column(db.Integer, db.ForeignKey('categories.id'))
connect_categories = db.relationship('Categories', backref='categories_advertisement', uselist=False)
def __init__(self, new_adv_name, new_employer_id, new_coordinates, new_categories_id, new_tags_id,
new_confirmed=default_confirmed_status):
def __init__(self, new_adv_name, new_employer_id, new_type_event, new_coordinates_id, new_categories_id, new_wait_size_users, new_time_event):
self.adv_name = new_adv_name
self.time_event = new_time_event
self.type_event = new_type_event
self.employer_id = new_employer_id
self.confirmed = new_confirmed
self.coordinates = new_coordinates
self.coordinates_id = new_coordinates_id
self.categories_id = new_categories_id
self.tags_id = new_tags_id
self.wait_size_users = new_wait_size_users
def __repr__(self):
return f"Advertisement name:'{self.adv_name}"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment