mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
Now, we allow the direct relationships and their foreign keys to be set in all of our models. Previously, we constrained this to direct relationships, and this forced users to perform a query in most situations to satisfy that requirement. Now, IDs can be passed directly. Additionally, this change removes the need for extraneous imports when users which to use relationships. We now import and use models directly instead of passing string-references to them. Signed-off-by: Kevin Morris <kevr@0cost.org>
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
from sqlalchemy import Column, Integer
|
|
from sqlalchemy.exc import IntegrityError
|
|
|
|
from aurweb.models.declarative import Base
|
|
|
|
# TODO: Fix this! Official packages aren't from aur.archlinux.org...
|
|
OFFICIAL_BASE = "https://aur.archlinux.org"
|
|
|
|
|
|
class OfficialProvider(Base):
|
|
__tablename__ = "OfficialProviders"
|
|
|
|
ID = Column(Integer, primary_key=True)
|
|
|
|
__mapper_args__ = {"primary_key": [ID]}
|
|
|
|
def __init__(self, **kwargs):
|
|
super().__init__(**kwargs)
|
|
|
|
if not self.Name:
|
|
raise IntegrityError(
|
|
statement="Column Name cannot be null.",
|
|
orig="OfficialProviders.Name",
|
|
params=("NULL"))
|
|
|
|
if not self.Repo:
|
|
raise IntegrityError(
|
|
statement="Column Repo cannot be null.",
|
|
orig="OfficialProviders.Repo",
|
|
params=("NULL"))
|
|
|
|
if not self.Provides:
|
|
raise IntegrityError(
|
|
statement="Column Provides cannot be null.",
|
|
orig="OfficialProviders.Provides",
|
|
params=("NULL"))
|